-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
52 lines (43 loc) · 1.07 KB
/
server.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
package gtcp
import (
"net"
)
// Return new listener
func NewTCPListener(addr string) (*TCPListener, error) {
tcpAddr, err := net.ResolveTCPAddr("tcp4", addr)
if err != nil {
return nil, err
}
listener, err := net.ListenTCP("tcp", tcpAddr)
if err != nil {
return nil, err
}
return &TCPListener{listener}, nil
}
// TCP listener struct
type TCPListener struct {
*net.TCPListener
}
// accept a dialing and return a TCPConn
func (t *TCPListener) AcceptTCP() (*TCPConn, error) {
conn, err := t.TCPListener.AcceptTCP()
tcpConn := GetTCPConn(conn)
return tcpConn, err
}
// accept a dialing and return a TCPConnInterface
func (t *TCPListener) Accept() (TCPConnInterface, error) {
conn, err := t.TCPListener.AcceptTCP()
tcpConn := GetTCPConn(conn)
return tcpConn, err
}
// accept a dialing and return a TCPCtrl
func (t *TCPListener) AcceptTCPCtrl(actor Actor) (*TCPCtrl, error) {
conn, err := t.TCPListener.AcceptTCP()
if err != nil {
return nil, err
}
tcpConn := GetTCPConn(conn)
TCPCtrl := GetTCPCtrl(actor)
TCPCtrl.InstallTCPConn(tcpConn)
return TCPCtrl, err
}