Skip to content

Commit

Permalink
Connection time for
Browse files Browse the repository at this point in the history
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
  • Loading branch information
yuriy0803 committed Jul 23, 2024
1 parent c9d0307 commit eb9777a
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions proxy/stratum.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,26 @@ func (s *ProxyServer) ListenTCP() {

accept <- n
go func(cs *Session) {
err = s.handleTCPClient(cs)
if err != nil {
s.removeSession(cs)
conn.Close()
}
s.logConnectionTime(cs)
<-accept
}(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 {
cs.enc = json.NewEncoder(cs.conn)
connbuff := bufio.NewReaderSize(cs.conn, MaxReqSize)
Expand Down

0 comments on commit eb9777a

Please sign in to comment.