-
Notifications
You must be signed in to change notification settings - Fork 1
/
dialer.go
33 lines (29 loc) · 1.05 KB
/
dialer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package goconnpool
import (
"context"
"net"
)
// Dialer interface used to dial specific server independently from the specific protocol.
type Dialer interface {
// Dial dials the address passed (this address is one of the registered servers addresses).
//
// Function should return net.Conn-compatible connection.
//
// Function should be implemented in the thread-safe way.
// Connect timeout is setuped before this function invocation: be sure your function not stuck in the case of
// timeout.
//
// address variable is the same address used into RegisterServer call.
//
// You could get original connection returned by the Dial() call using Conn.OriginalConn().
Dial(ctx context.Context, address string) (net.Conn, error)
}
// TCPDialer is the default implementation of Dialer interface.
// Use it for raw TCP connections.
type TCPDialer struct {
d net.Dialer
}
// Dial dials some TCP server using net.Dialer structure.
func (d *TCPDialer) Dial(ctx context.Context, address string) (net.Conn, error) {
return d.d.DialContext(ctx, "tcp", address)
}