-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
58 lines (46 loc) · 998 Bytes
/
client.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
package mdp
import (
"errors"
"net"
"time"
)
var _ net.Conn = &Client{}
func NewClient(config Config) (*Client, error) {
c := &Client{
sess: newSession(config).addForwardEndpoints(),
}
return c, nil
}
type Client struct {
sess *session
}
func (c *Client) Read(b []byte) (n int, err error) {
select {
case <-c.sess.closeOnce.Wait():
return 0, errors.New("mdp: client is closed")
case packet := <-c.sess.dstInputCh:
n = copy(b, packet.Data)
return
}
}
func (c *Client) Write(b []byte) (n int, err error) {
return len(b), c.sess.output(b,true)
}
func (c *Client) Close() error {
return c.sess.Close()
}
func (c *Client) LocalAddr() net.Addr {
return c.sess.srcAddr
}
func (c *Client) RemoteAddr() net.Addr {
return c.sess.dstAddr
}
func (c *Client) SetDeadline(t time.Time) error {
panic("implement me")
}
func (c *Client) SetReadDeadline(t time.Time) error {
panic("implement me")
}
func (c *Client) SetWriteDeadline(t time.Time) error {
panic("implement me")
}