event loop. overflooded counter cleanup on connection close.

This commit is contained in:
Gennadii Kovalev 2016-07-05 20:18:06 +02:00
parent 426d5cedc6
commit ccde7b309c
1 changed files with 6 additions and 1 deletions

View File

@ -97,6 +97,11 @@ func CloseChannel(c *Channel, m *methods, args ...interface{}) error {
c.out <- protocol.CloseMessage c.out <- protocol.CloseMessage
m.callLoopEvent(c, OnDisconnection) m.callLoopEvent(c, OnDisconnection)
overfloodedLock.Lock()
delete(overflooded, c)
overfloodedLock.Unlock()
return nil return nil
} }
@ -145,7 +150,7 @@ outgoing messages loop, sends messages from channel to socket
func outLoop(c *Channel, m *methods) error { func outLoop(c *Channel, m *methods) error {
for { for {
outBufferLen := len(c.out) outBufferLen := len(c.out)
if outBufferLen == queueBufferSize { if outBufferLen >= queueBufferSize - 1 {
return CloseChannel(c, m, ErrorSocketOverflood) return CloseChannel(c, m, ErrorSocketOverflood)
} else if outBufferLen > int(queueBufferSize/2) { } else if outBufferLen > int(queueBufferSize/2) {
overfloodedLock.Lock() overfloodedLock.Lock()