mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 12:47:36 +03:00
introduce a session.closeRemote, simplify error handling
This commit is contained in:
parent
6f48a1ebb4
commit
c80bd6ff2c
1 changed files with 8 additions and 6 deletions
14
session.go
14
session.go
|
@ -441,7 +441,7 @@ func (s *session) handleFrames(fs []frames.Frame) error {
|
|||
case *frames.AckFrame:
|
||||
err = s.handleAckFrame(frame)
|
||||
case *frames.ConnectionCloseFrame:
|
||||
s.close(qerr.Error(frame.ErrorCode, frame.ReasonPhrase), true)
|
||||
s.closeRemote(qerr.Error(frame.ErrorCode, frame.ReasonPhrase))
|
||||
case *frames.GoawayFrame:
|
||||
err = errors.New("unimplemented: handling GOAWAY frames")
|
||||
case *frames.StopWaitingFrame:
|
||||
|
@ -527,20 +527,22 @@ func (s *session) handleAckFrame(frame *frames.AckFrame) error {
|
|||
return s.sentPacketHandler.ReceivedAck(frame, s.lastRcvdPacketNumber, s.lastNetworkActivityTime)
|
||||
}
|
||||
|
||||
func (s *session) close(e error, remoteClose bool) {
|
||||
func (s *session) closeLocal(e error) {
|
||||
s.closeOnce.Do(func() {
|
||||
s.closeChan <- closeError{err: e, remote: remoteClose}
|
||||
s.closeChan <- closeError{err: e, remote: false}
|
||||
})
|
||||
}
|
||||
|
||||
func (s *session) closeLocal(e error) {
|
||||
s.close(e, false)
|
||||
func (s *session) closeRemote(e error) {
|
||||
s.closeOnce.Do(func() {
|
||||
s.closeChan <- closeError{err: e, remote: true}
|
||||
})
|
||||
}
|
||||
|
||||
// Close the connection. If err is nil it will be set to qerr.PeerGoingAway.
|
||||
// It waits until the run loop has stopped before returning
|
||||
func (s *session) Close(e error) error {
|
||||
s.close(e, false)
|
||||
s.closeLocal(e)
|
||||
<-s.runClosed
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue