-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathconn.go
76 lines (64 loc) · 1.52 KB
/
conn.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package sonic
import (
"net"
"time"
"github.com/talostrading/sonic/sonicopts"
"github.com/talostrading/sonic/internal"
)
var _ Conn = &conn{}
type conn struct {
*file
localAddr net.Addr
remoteAddr net.Addr
}
// Dial establishes a stream based connection to the specified address. It is similar to `net.Dial`.
//
// Data can be sent or received only from the specified address for all networks: tcp, udp and unix domain sockets.
func Dial(
ioc *IO,
network, addr string,
opts ...sonicopts.Option,
) (Conn, error) {
return DialTimeout(ioc, network, addr, 10*time.Second, opts...)
}
// `DialTimeout` is like `Dial` but with a timeout.
func DialTimeout(
ioc *IO, network, addr string,
timeout time.Duration,
opts ...sonicopts.Option,
) (Conn, error) {
fd, localAddr, remoteAddr, err := internal.ConnectTimeout(network, addr, timeout, opts...)
if err != nil {
return nil, err
}
return newConn(ioc, fd, localAddr, remoteAddr), nil
}
func newConn(
ioc *IO,
fd int,
localAddr, remoteAddr net.Addr,
) *conn {
return &conn{
file: newFile(ioc, fd),
localAddr: localAddr,
remoteAddr: remoteAddr,
}
}
func (c *conn) LocalAddr() net.Addr {
return c.localAddr
}
func (c *conn) RemoteAddr() net.Addr {
return c.remoteAddr
}
func (c *conn) SetDeadline(t time.Time) error {
panic("not implemented")
}
func (c *conn) SetReadDeadline(t time.Time) error {
panic("not implemented")
}
func (c *conn) SetWriteDeadline(t time.Time) error {
panic("not implemented")
}
func (c *conn) RawFd() int {
return c.file.slot.Fd
}