OSDN Git Service

edit for code review
authorpaladz <453256728@qq.com>
Wed, 30 May 2018 09:04:18 +0000 (17:04 +0800)
committerpaladz <453256728@qq.com>
Wed, 30 May 2018 09:04:18 +0000 (17:04 +0800)
p2p/connection/connection.go

index 09b2810..983fe22 100644 (file)
@@ -118,7 +118,7 @@ func NewMConnectionWithConfig(conn net.Conn, chDescs []*ChannelDescriptor, onRec
                sendMonitor: flow.New(0, 0),
                recvMonitor: flow.New(0, 0),
                send:        make(chan struct{}, 1),
-               pong:        make(chan struct{}),
+               pong:        make(chan struct{}, 1),
                channelsIdx: map[byte]*channel{},
                channels:    []*channel{},
                onReceive:   onReceive,
@@ -268,7 +268,10 @@ func (c *MConnection) recvRoutine() {
                switch pktType {
                case packetTypePing:
                        log.Debug("receive Ping")
-                       c.pong <- struct{}{}
+                       select {
+                       case c.pong <- struct{}{}:
+                       default:
+                       }
 
                case packetTypePong:
                        log.Debug("receive Pong")