mirror of
https://github.com/ergochat/ergo.git
synced 2025-01-09 19:52:57 +01:00
socket: Make closing work a little better
This commit is contained in:
parent
e0035dfa04
commit
121269661b
@ -51,10 +51,7 @@ func NewSocket(conn net.Conn, maxSendQBytes uint64) Socket {
|
|||||||
func (socket *Socket) Close() {
|
func (socket *Socket) Close() {
|
||||||
socket.Closed = true
|
socket.Closed = true
|
||||||
|
|
||||||
// 'send data' to force close loop to happen
|
// force close loop to happen
|
||||||
socket.linesToSendMutex.Lock()
|
|
||||||
socket.linesToSend = append(socket.linesToSend, "")
|
|
||||||
socket.linesToSendMutex.Unlock()
|
|
||||||
go socket.fillLineToSendExists()
|
go socket.fillLineToSendExists()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,6 +135,11 @@ func (socket *Socket) RunSocketWriter() {
|
|||||||
case <-socket.lineToSendExists:
|
case <-socket.lineToSendExists:
|
||||||
socket.linesToSendMutex.Lock()
|
socket.linesToSendMutex.Lock()
|
||||||
|
|
||||||
|
// check if we're closed
|
||||||
|
if socket.Closed {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
// check sendq
|
// check sendq
|
||||||
var sendQBytes uint64
|
var sendQBytes uint64
|
||||||
for _, line := range socket.linesToSend {
|
for _, line := range socket.linesToSend {
|
||||||
|
Loading…
Reference in New Issue
Block a user