aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-03-19 22:16:06 +0800
committerFelix Lange <fjl@twurst.com>2015-03-19 22:16:06 +0800
commitb9e0b11e7da387bbb426d25c36d495c4f099722f (patch)
tree93ecc3ea85d7def8e7e1aa6df55938e3e9a7f42f
parenta7bced779a599fb3f87a69a5f8bb8017b62dc0a3 (diff)
downloaddexon-b9e0b11e7da387bbb426d25c36d495c4f099722f.tar
dexon-b9e0b11e7da387bbb426d25c36d495c4f099722f.tar.gz
dexon-b9e0b11e7da387bbb426d25c36d495c4f099722f.tar.bz2
dexon-b9e0b11e7da387bbb426d25c36d495c4f099722f.tar.lz
dexon-b9e0b11e7da387bbb426d25c36d495c4f099722f.tar.xz
dexon-b9e0b11e7da387bbb426d25c36d495c4f099722f.tar.zst
dexon-b9e0b11e7da387bbb426d25c36d495c4f099722f.zip
p2p: interrupt MsgPipe payload read/write
This is better because protocols might not actually read the payload for some errors (msg too big, etc.) which can be a pain to test with the old behaviour.
-rw-r--r--p2p/message.go9
1 files changed, 6 insertions, 3 deletions
diff --git a/p2p/message.go b/p2p/message.go
index 5dc7d5460..ef3630a90 100644
--- a/p2p/message.go
+++ b/p2p/message.go
@@ -185,7 +185,10 @@ func (p *MsgPipeRW) WriteMsg(msg Msg) error {
case p.w <- msg:
if msg.Size > 0 {
// wait for payload read or discard
- <-consumed
+ select {
+ case <-consumed:
+ case <-p.closing:
+ }
}
return nil
case <-p.closing:
@@ -207,8 +210,8 @@ func (p *MsgPipeRW) ReadMsg() (Msg, error) {
}
// Close unblocks any pending ReadMsg and WriteMsg calls on both ends
-// of the pipe. They will return ErrPipeClosed. Note that Close does
-// not interrupt any reads from a message payload.
+// of the pipe. They will return ErrPipeClosed. Close also
+// interrupts any reads from a message payload.
func (p *MsgPipeRW) Close() error {
if atomic.AddInt32(p.closed, 1) != 1 {
// someone else is already closing