Browse Source

Connection time for

2024/07/23 13:44:49 Error reading from socket: read tcp 192.168.178.41:8008->192.168.178.8:59614: read: connection reset by peer
2024/07/23 13:44:49 Error handling TCP client 192.168.178.8: read tcp 192.168.178.41:8008->192.168.178.8:59614: read: connection reset by peer
2024/07/23 13:44:49 Connection time for 192.168.178.8: 1m27.808454138s
master
yuriy0803 1 year ago
parent
commit
eb9777a6f8
  1. 20
      proxy/stratum.go

20
proxy/stratum.go

@ -76,16 +76,26 @@ func (s *ProxyServer) ListenTCP() {
accept <- n accept <- n
go func(cs *Session) { go func(cs *Session) {
err = s.handleTCPClient(cs) s.logConnectionTime(cs)
if err != nil {
s.removeSession(cs)
conn.Close()
}
<-accept <-accept
}(cs) }(cs)
} }
} }
func (s *ProxyServer) logConnectionTime(cs *Session) {
start := time.Now()
defer func() {
duration := time.Since(start)
log.Printf("Connection time for %s: %s", cs.ip, duration)
}()
err := s.handleTCPClient(cs)
if err != nil {
log.Printf("Error handling TCP client %s: %v", cs.ip, err)
s.removeSession(cs)
cs.conn.Close()
}
}
func (s *ProxyServer) handleTCPClient(cs *Session) error { func (s *ProxyServer) handleTCPClient(cs *Session) error {
cs.enc = json.NewEncoder(cs.conn) cs.enc = json.NewEncoder(cs.conn)
connbuff := bufio.NewReaderSize(cs.conn, MaxReqSize) connbuff := bufio.NewReaderSize(cs.conn, MaxReqSize)

Loading…
Cancel
Save