3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-10 22:19:31 +01:00

socket: Fixup sending code so we can support more connections

This commit is contained in:
Daniel Oaks 2017-03-23 12:07:23 +10:00
parent f29a5f0e70
commit c3be2d0d46

View File

@ -50,7 +50,12 @@ func NewSocket(conn net.Conn, maxSendQBytes uint64) Socket {
// Close stops a Socket from being able to send/receive any more data. // Close stops a Socket from being able to send/receive any more data.
func (socket *Socket) Close() { func (socket *Socket) Close() {
socket.Closed = true socket.Closed = true
// socket will close once all data has been sent
// 'send data' to force close loop to happen
socket.linesToSendMutex.Lock()
socket.linesToSend = append(socket.linesToSend, "")
socket.linesToSendMutex.Unlock()
go socket.fillLineToSendExists()
} }
// CertFP returns the fingerprint of the certificate provided by the client. // CertFP returns the fingerprint of the certificate provided by the client.
@ -155,12 +160,21 @@ func (socket *Socket) RunSocketWriter() {
} }
// write data // write data
if 0 < len(data) {
_, err := socket.conn.Write([]byte(data)) _, err := socket.conn.Write([]byte(data))
if err != nil { if err != nil {
errOut = true errOut = true
fmt.Println(err.Error()) fmt.Println(err.Error())
break break
} }
}
// check if we're closed
if socket.Closed {
socket.linesToSendMutex.Unlock()
break
}
socket.linesToSendMutex.Unlock() socket.linesToSendMutex.Unlock()
} }
if errOut { if errOut {