refactor MConnection#sendBytes

This commit is contained in:
Anton Kaliaev
2017-04-14 14:21:58 +04:00
parent 06d219db8e
commit ebe23f1379
3 changed files with 30 additions and 6 deletions

View File

@ -557,14 +557,12 @@ func newChannel(conn *MConnection, desc *ChannelDescriptor) *Channel {
// Goroutine-safe
// Times out (and returns false) after defaultSendTimeout
func (ch *Channel) sendBytes(bytes []byte) bool {
timeout := time.NewTimer(defaultSendTimeout)
select {
case <-timeout.C:
// timeout
return false
case ch.sendQueue <- bytes:
atomic.AddInt32(&ch.sendQueueSize, 1)
return true
case <-time.After(defaultSendTimeout):
return false
}
}