rename packetHandlerMap.Close() to Destroy()

This commit is contained in:
Marten Seemann 2020-01-22 17:59:22 +07:00
parent 62d3a4166a
commit db396d8a78
6 changed files with 24 additions and 23 deletions

View file

@ -287,7 +287,7 @@ func (c *client) establishSecureConnection(ctx context.Context) error {
go func() { go func() {
err := c.session.run() // returns as soon as the session is closed err := c.session.run() // returns as soon as the session is closed
if err != errCloseForRecreating && c.createdPacketConn { if err != errCloseForRecreating && c.createdPacketConn {
c.packetHandlers.Close() c.packetHandlers.Destroy()
} }
errorChan <- err errorChan <- err
}() }()

View file

@ -128,7 +128,7 @@ var _ = Describe("Client", func() {
manager := NewMockPacketHandlerManager(mockCtrl) manager := NewMockPacketHandlerManager(mockCtrl)
manager.EXPECT().Add(gomock.Any(), gomock.Any()) manager.EXPECT().Add(gomock.Any(), gomock.Any())
manager.EXPECT().Close() manager.EXPECT().Destroy()
mockMultiplexer.EXPECT().AddConn(gomock.Any(), gomock.Any(), gomock.Any()).Return(manager, nil) mockMultiplexer.EXPECT().AddConn(gomock.Any(), gomock.Any(), gomock.Any()).Return(manager, nil)
remoteAddrChan := make(chan string, 1) remoteAddrChan := make(chan string, 1)
@ -159,7 +159,7 @@ var _ = Describe("Client", func() {
It("uses the tls.Config.ServerName as the hostname, if present", func() { It("uses the tls.Config.ServerName as the hostname, if present", func() {
manager := NewMockPacketHandlerManager(mockCtrl) manager := NewMockPacketHandlerManager(mockCtrl)
manager.EXPECT().Add(gomock.Any(), gomock.Any()) manager.EXPECT().Add(gomock.Any(), gomock.Any())
manager.EXPECT().Close() manager.EXPECT().Destroy()
mockMultiplexer.EXPECT().AddConn(gomock.Any(), gomock.Any(), gomock.Any()).Return(manager, nil) mockMultiplexer.EXPECT().AddConn(gomock.Any(), gomock.Any(), gomock.Any()).Return(manager, nil)
hostnameChan := make(chan string, 1) hostnameChan := make(chan string, 1)
@ -440,7 +440,7 @@ var _ = Describe("Client", func() {
// check that the connection is not closed // check that the connection is not closed
Expect(conn.Write([]byte("foobar"))).To(Succeed()) Expect(conn.Write([]byte("foobar"))).To(Succeed())
manager.EXPECT().Close() manager.EXPECT().Destroy()
close(run) close(run)
time.Sleep(50 * time.Millisecond) time.Sleep(50 * time.Millisecond)

View file

@ -74,20 +74,6 @@ func (mr *MockPacketHandlerManagerMockRecorder) AddResetToken(arg0, arg1 interfa
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddResetToken", reflect.TypeOf((*MockPacketHandlerManager)(nil).AddResetToken), arg0, arg1) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddResetToken", reflect.TypeOf((*MockPacketHandlerManager)(nil).AddResetToken), arg0, arg1)
} }
// Close mocks base method
func (m *MockPacketHandlerManager) Close() error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Close")
ret0, _ := ret[0].(error)
return ret0
}
// Close indicates an expected call of Close
func (mr *MockPacketHandlerManagerMockRecorder) Close() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Close", reflect.TypeOf((*MockPacketHandlerManager)(nil).Close))
}
// CloseServer mocks base method // CloseServer mocks base method
func (m *MockPacketHandlerManager) CloseServer() { func (m *MockPacketHandlerManager) CloseServer() {
m.ctrl.T.Helper() m.ctrl.T.Helper()
@ -100,6 +86,20 @@ func (mr *MockPacketHandlerManagerMockRecorder) CloseServer() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CloseServer", reflect.TypeOf((*MockPacketHandlerManager)(nil).CloseServer)) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CloseServer", reflect.TypeOf((*MockPacketHandlerManager)(nil).CloseServer))
} }
// Destroy mocks base method
func (m *MockPacketHandlerManager) Destroy() error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Destroy")
ret0, _ := ret[0].(error)
return ret0
}
// Destroy indicates an expected call of Destroy
func (mr *MockPacketHandlerManagerMockRecorder) Destroy() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Destroy", reflect.TypeOf((*MockPacketHandlerManager)(nil).Destroy))
}
// GetStatelessResetToken mocks base method // GetStatelessResetToken mocks base method
func (m *MockPacketHandlerManager) GetStatelessResetToken(arg0 protocol.ConnectionID) [16]byte { func (m *MockPacketHandlerManager) GetStatelessResetToken(arg0 protocol.ConnectionID) [16]byte {
m.ctrl.T.Helper() m.ctrl.T.Helper()

View file

@ -185,8 +185,9 @@ func (h *packetHandlerMap) CloseServer() {
wg.Wait() wg.Wait()
} }
// Close the underlying connection and wait until listen() has returned. // Destroy the underlying connection and wait until listen() has returned.
func (h *packetHandlerMap) Close() error { // It does not close active sessions.
func (h *packetHandlerMap) Destroy() error {
if err := h.conn.Close(); err != nil { if err := h.conn.Close(); err != nil {
return err return err
} }

View file

@ -62,7 +62,7 @@ var _ = Describe("Packet Handler Map", func() {
} }
handler.server = nil handler.server = nil
handler.mutex.Unlock() handler.mutex.Unlock()
handler.Close() handler.Destroy()
Eventually(handler.listening).Should(BeClosed()) Eventually(handler.listening).Should(BeClosed())
}) })

View file

@ -33,7 +33,7 @@ type unknownPacketHandler interface {
} }
type packetHandlerManager interface { type packetHandlerManager interface {
io.Closer Destroy() error
SetServer(unknownPacketHandler) SetServer(unknownPacketHandler)
CloseServer() CloseServer()
sessionRunner sessionRunner
@ -305,7 +305,7 @@ func (s *baseServer) Close() error {
// If the server was started with ListenAddr, we created the packet conn. // If the server was started with ListenAddr, we created the packet conn.
// We need to close it in order to make the go routine reading from that conn return. // We need to close it in order to make the go routine reading from that conn return.
if s.createdPacketConn { if s.createdPacketConn {
err = s.sessionHandler.Close() err = s.sessionHandler.Destroy()
} }
s.closed = true s.closed = true
close(s.errorChan) close(s.errorChan)