Skip to content

Commit

Permalink
add the callback OnClose for Handler
Browse files Browse the repository at this point in the history
  • Loading branch information
xgfone committed Jun 7, 2020
1 parent 249556c commit 810bd59
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions peerprotocol/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ type Handler interface {
//
// If requires, it should write the response to the peer.
OnMessage(conn *PeerConn, msg Message) error

// OnClose is called when the connection is closed, which may be used
// to do some cleaning work by the handler.
OnClose(conn *PeerConn)
}

// Config is used to configure the server.
Expand Down Expand Up @@ -141,6 +145,7 @@ func (s *Server) handlePeerMessage(pc *PeerConn) (err error) {
return fmt.Errorf("handshake error with '%s': %s", pc.RemoteAddr().String(), err)
}

defer s.h.OnClose(pc)
return s.loopRun(pc, s.h)
}

Expand Down

0 comments on commit 810bd59

Please sign in to comment.