Browse Source

add a comment for MConnection#CanSend

also add a note to TestMConnectionSend
pull/456/head
Anton Kaliaev 8 years ago
parent
commit
2ac69176e1
No known key found for this signature in database GPG Key ID: 7B6881D965918214
2 changed files with 4 additions and 2 deletions
  1. +2
    -0
      connection.go
  2. +2
    -2
      connection_test.go

+ 2
- 0
connection.go View File

@ -258,6 +258,8 @@ func (c *MConnection) TrySend(chID byte, msg interface{}) bool {
return ok return ok
} }
// CanSend returns true if you can send more data onto the chID, false
// otherwise. Use only as a heuristic.
func (c *MConnection) CanSend(chID byte) bool { func (c *MConnection) CanSend(chID byte) bool {
if !c.IsRunning() { if !c.IsRunning() {
return false return false


+ 2
- 2
connection_test.go View File

@ -37,9 +37,9 @@ func TestMConnectionSend(t *testing.T) {
msg := "Ant-Man" msg := "Ant-Man"
assert.True(mconn.Send(0x01, msg)) assert.True(mconn.Send(0x01, msg))
// Note: subsequent Send/TrySend calls could pass because we are reading from
// the send queue in a separate goroutine.
assert.False(mconn.CanSend(0x01), "CanSend should return false because queue is full") assert.False(mconn.CanSend(0x01), "CanSend should return false because queue is full")
// assert.False(mconn.Send(0x01, msg), "Send should return false because queue is full")
// assert.False(mconn.TrySend(0x01, msg), "TrySend should return false because queue is full")
server.Read(make([]byte, len(msg))) server.Read(make([]byte, len(msg)))
assert.True(mconn.CanSend(0x01)) assert.True(mconn.CanSend(0x01))


Loading…
Cancel
Save