diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-03-07 23:04:26 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-03-07 23:05:29 +0900 |
commit | bbde43608fc23b6739f84a7df8275c23b99e44be (patch) | |
tree | f90f5b229da68da3c1a1ed7402499a7603ae6f5e /server | |
parent | 51a677cbe60f57ec327bc8d95928f36bb0acf432 (diff) |
server: recvMessageWithError avoid blocked due to msgCh
Preparation for make recvMessageWithError() avoid being blocked.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server')
-rw-r--r-- | server/fsm.go | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/server/fsm.go b/server/fsm.go index b6b0990b..0e5e7e90 100644 --- a/server/fsm.go +++ b/server/fsm.go @@ -549,7 +549,7 @@ func readAll(conn net.Conn, length int) ([]byte, error) { return buf, nil } -func (h *FSMHandler) recvMessageWithError() error { +func (h *FSMHandler) recvMessageWithError() (*FsmMsg, error) { sendToErrorCh := func(reason FsmStateReason) { // probably doesn't happen but be cautious select { @@ -561,7 +561,7 @@ func (h *FSMHandler) recvMessageWithError() error { headerBuf, err := readAll(h.conn, bgp.BGP_HEADER_LENGTH) if err != nil { sendToErrorCh(FSM_READ_FAILED) - return err + return nil, err } hd := &bgp.BGPHeader{} @@ -574,18 +574,18 @@ func (h *FSMHandler) recvMessageWithError() error { "State": h.fsm.state, "error": err, }).Warn("malformed BGP Header") - h.msgCh <- &FsmMsg{ + fmsg := &FsmMsg{ MsgType: FSM_MSG_BGP_MESSAGE, MsgSrc: h.fsm.pConf.Config.NeighborAddress, MsgData: err, } - return err + return fmsg, err } bodyBuf, err := readAll(h.conn, int(hd.Len)-bgp.BGP_HEADER_LENGTH) if err != nil { sendToErrorCh(FSM_READ_FAILED) - return err + return nil, err } now := time.Now() @@ -649,7 +649,7 @@ func (h *FSMHandler) recvMessageWithError() error { h.holdTimerResetCh <- true } if m.Header.Type == bgp.BGP_MSG_KEEPALIVE { - return nil + return nil, nil } case bgp.BGP_MSG_NOTIFICATION: body := m.Body.(*bgp.BGPNotification) @@ -662,16 +662,18 @@ func (h *FSMHandler) recvMessageWithError() error { }).Warn("received notification") sendToErrorCh(FSM_NOTIFICATION_RECV) - return nil + return nil, nil } } } - h.msgCh <- fmsg - return err + return fmsg, err } func (h *FSMHandler) recvMessage() error { - h.recvMessageWithError() + fmsg, _ := h.recvMessageWithError() + if fmsg != nil { + h.msgCh <- fmsg + } return nil } @@ -1062,7 +1064,10 @@ func (h *FSMHandler) sendMessageloop() error { func (h *FSMHandler) recvMessageloop() error { for { - err := h.recvMessageWithError() + fmsg, err := h.recvMessageWithError() + if fmsg != nil { + h.msgCh <- fmsg + } if err != nil { return nil } |