-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathconn.go
78 lines (66 loc) · 1.53 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
77
78
package sonic
import (
"fmt"
"net"
"time"
"github.com/talostrading/sonic/sonicopts"
"github.com/talostrading/sonic/internal"
)
var _ Conn = &conn{}
type conn struct {
*file
fd int
localAddr net.Addr
remoteAddr net.Addr
}
// Dial establishes a stream based connection to the specified address.
//
// 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...)
}
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: &file{ioc: ioc, fd: fd, pd: internal.PollData{Fd: fd}},
fd: 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 {
return fmt.Errorf("not supported")
}
func (c *conn) SetReadDeadline(t time.Time) error {
return fmt.Errorf("not supported")
}
func (c *conn) SetWriteDeadline(t time.Time) error {
return fmt.Errorf("not supported")
}
func (c *conn) RawFd() int {
return c.fd
}