File tree Expand file tree Collapse file tree 2 files changed +9
-1
lines changed
Expand file tree Collapse file tree 2 files changed +9
-1
lines changed Original file line number Diff line number Diff line change 66 "log"
77 "net"
88 "net/http"
9+ "time"
910)
1011
1112type TRPClient struct {
@@ -26,6 +27,8 @@ func (c *TRPClient) Start() error {
2627 if err != nil {
2728 return err
2829 }
30+ conn .(* net.TCPConn ).SetKeepAlive (true )
31+ conn .(* net.TCPConn ).SetKeepAlivePeriod (time .Duration (2 * time .Second ))
2932 c .conn = conn
3033 return c .process ()
3134}
Original file line number Diff line number Diff line change @@ -37,6 +37,10 @@ func (s *TRPServer) Start() error {
3737}
3838
3939func (s * TRPServer ) Close () error {
40+ if s .conn != nil {
41+ s .conn .Close ()
42+ s .conn = nil
43+ }
4044 if s .listener != nil {
4145 err := s .listener .Close ()
4246 s .listener = nil
@@ -109,7 +113,8 @@ func (s *TRPServer) cliProcess(conn *net.TCPConn) error {
109113 s .conn = nil
110114 }
111115 log .Println ("连接新的客户端:" , conn .RemoteAddr ())
112-
116+ conn .SetKeepAlive (true )
117+ conn .SetKeepAlivePeriod (time .Duration (2 * time .Second ))
113118 s .conn = conn
114119 return nil
115120}
You can’t perform that action at this time.
0 commit comments