-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathconn.go
More file actions
44 lines (36 loc) · 656 Bytes
/
conn.go
File metadata and controls
44 lines (36 loc) · 656 Bytes
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
package main
import (
"net"
"time"
)
type Conn struct {
conn net.Conn
pool *recycler
}
func NewConn(conn net.Conn, pool *recycler) *Conn {
return &Conn{
conn: conn,
pool: pool,
}
}
func (c *Conn) Read(b []byte) (int, error) {
c.conn.SetReadDeadline(time.Now().Add(30 * time.Minute))
n, err := c.conn.Read(b)
return n, err
}
func (c *Conn) Write(b []byte) (int, error) {
return c.conn.Write(b)
}
func (c *Conn) Close() {
c.conn.Close()
}
func (c *Conn) CloseRead() {
if conn, ok := c.conn.(*net.TCPConn); ok {
conn.CloseRead()
}
}
func (c *Conn) CloseWrite() {
if conn, ok := c.conn.(*net.TCPConn); ok {
conn.CloseWrite()
}
}