split the Session.Close(error) in Close() and CloseWithError(error)

This commit is contained in:
Marten Seemann
2018-07-04 17:04:50 +07:00
parent 2bc5b7f532
commit 8b2992a243
22 changed files with 168 additions and 105 deletions

View File

@@ -336,8 +336,8 @@ func (c *client) establishSecureConnection(ctx context.Context) error {
select {
case <-ctx.Done():
// The session sending a PeerGoingAway error to the server.
c.session.Close(nil)
// The session will send a PeerGoingAway error to the server.
c.session.Close()
return ctx.Err()
case err := <-errorChan:
return err
@@ -366,7 +366,7 @@ func (c *client) handlePacketImpl(p *receivedPacket) error {
// version negotiation packets have no payload
if err := c.handleVersionNegotiationPacket(p.header); err != nil {
c.session.Close(err)
c.session.destroy(err)
}
return nil
}
@@ -474,7 +474,7 @@ func (c *client) handleVersionNegotiationPacket(hdr *wire.Header) error {
}
c.logger.Infof("Switching to QUIC version %s. New connection ID: %s", newVersion, c.destConnID)
c.session.Close(errCloseSessionForNewVersion)
c.session.destroy(errCloseSessionForNewVersion)
return nil
}
@@ -526,13 +526,13 @@ func (c *client) createNewTLSSession(
return err
}
func (c *client) Close(err error) error {
func (c *client) Close() error {
c.mutex.Lock()
defer c.mutex.Unlock()
if c.session == nil {
return nil
}
return c.session.Close(err)
return c.session.Close()
}
func (c *client) GetVersion() protocol.VersionNumber {