Skip to content

Commit f7db75a

Browse files
authoredFeb 10, 2025
small optimization (#94)
1 parent b2101a5 commit f7db75a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed
 

‎internal/gameServer/tcp.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,14 @@ func (g *GameServer) processTCP(conn *net.TCPConn) {
152152
tcpData := &TCPData{Request: RequestNone}
153153
incomingBuffer := make([]byte, 1500) //nolint:gomnd,mnd
154154
for {
155-
err := conn.SetReadDeadline(time.Now().Add(time.Millisecond))
155+
var readDeadline time.Time
156+
if tcpData.Buffer.Len() > 0 {
157+
// if there is pending data in the buffer, get to it quickly
158+
readDeadline = time.Now().Add(time.Millisecond)
159+
} else {
160+
readDeadline = time.Now().Add(time.Second)
161+
}
162+
err := conn.SetReadDeadline(readDeadline)
156163
if err != nil {
157164
g.Logger.Error(err, "could not set read deadline", "address", conn.RemoteAddr().String())
158165
}

0 commit comments

Comments
 (0)