Skip to content

Commit 53d8bbf

Browse files
authored
add more mutex locks (#149)
1 parent 7e2798a commit 53d8bbf

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

internal/gameServer/tcp.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func (g *GameServer) tcpSendFile(tcpData *TCPData, conn *net.TCPConn, withSize b
5353
return
5454
}
5555
} else {
56+
g.tcpMutex.Lock()
5657
if withSize {
5758
size := make([]byte, 4)
5859
binary.BigEndian.PutUint32(size, uint32(len(g.tcpFiles[tcpData.filename])))
@@ -67,6 +68,7 @@ func (g *GameServer) tcpSendFile(tcpData *TCPData, conn *net.TCPConn, withSize b
6768
g.Logger.Error(err, "could not write file", "address", conn.RemoteAddr().String())
6869
}
6970
}
71+
g.tcpMutex.Unlock()
7072

7173
// g.Logger.Info("sent save file", "filename", tcpData.filename, "filesize", tcpData.filesize, "address", conn.RemoteAddr().String())
7274
tcpData.filename = ""
@@ -105,7 +107,9 @@ func (g *GameServer) tcpSendCustom(conn *net.TCPConn, customID byte) {
105107
return
106108
}
107109
} else {
110+
g.tcpMutex.Lock()
108111
_, err := conn.Write(g.customData[customID])
112+
g.tcpMutex.Unlock()
109113
if err != nil {
110114
g.Logger.Error(err, "could not write data", "address", conn.RemoteAddr().String())
111115
}

0 commit comments

Comments
 (0)