-
Notifications
You must be signed in to change notification settings - Fork 0
/
conn.go
66 lines (54 loc) · 1.31 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
package tlsdialer
import (
"errors"
"io"
"net"
"github.com/tarantool/go-tarantool/v2"
)
type ttConn struct {
net net.Conn
reader io.Reader
writer writeFlusher
}
// writeFlusher is the interface that groups the basic Write and Flush methods.
type writeFlusher interface {
io.Writer
Flush() error
}
// Addr makes ttConn satisfy the Conn interface.
func (c *ttConn) Addr() net.Addr {
return c.net.RemoteAddr()
}
// Read makes ttConn satisfy the Conn interface.
func (c *ttConn) Read(p []byte) (int, error) {
return c.reader.Read(p)
}
// Write makes ttConn satisfy the Conn interface.
func (c *ttConn) Write(p []byte) (int, error) {
var (
l int
err error
)
if l, err = c.writer.Write(p); err != nil {
return l, err
} else if l != len(p) {
return l, errors.New("wrong length written")
}
return l, nil
}
// Flush makes ttConn satisfy the Conn interface.
func (c *ttConn) Flush() error {
return c.writer.Flush()
}
// Close makes ttConn satisfy the Conn interface.
func (c *ttConn) Close() error {
return c.net.Close()
}
// Greeting makes ttConn satisfy the Conn interface.
func (c *ttConn) Greeting() tarantool.Greeting {
return tarantool.Greeting{}
}
// ProtocolInfo makes ttConn satisfy the Conn interface.
func (c *ttConn) ProtocolInfo() tarantool.ProtocolInfo {
return tarantool.ProtocolInfo{}
}