diff --git a/gbn/config.go b/gbn/config.go index 4d14f7f..20dbd8c 100644 --- a/gbn/config.go +++ b/gbn/config.go @@ -45,6 +45,8 @@ type config struct { pingTime time.Duration pongTime time.Duration + + onFIN func() } // newConfig constructs a new config struct. diff --git a/gbn/gbn_conn.go b/gbn/gbn_conn.go index 92c97d2..1709f9f 100644 --- a/gbn/gbn_conn.go +++ b/gbn/gbn_conn.go @@ -646,6 +646,10 @@ func (g *GoBackNConn) receivePacketsForever() error { // nolint:gocyclo close(g.remoteClosed) + if g.cfg.onFIN != nil { + g.cfg.onFIN() + } + return errTransportClosing default: diff --git a/gbn/options.go b/gbn/options.go index 2c1e8df..9aedd27 100644 --- a/gbn/options.go +++ b/gbn/options.go @@ -4,6 +4,12 @@ import "time" type Option func(conn *config) +func WithOnFIN(fn func()) Option { + return func(conn *config) { + conn.onFIN = fn + } +} + // WithMaxSendSize is used to set the maximum payload size in bytes per packet. // If set and a large payload comes through then it will be split up into // multiple packets with payloads no larger than the given maximum size. diff --git a/mailbox/client_conn.go b/mailbox/client_conn.go index 6355a94..784d60c 100644 --- a/mailbox/client_conn.go +++ b/mailbox/client_conn.go @@ -157,20 +157,25 @@ func NewClientConn(ctx context.Context, sid [64]byte, serverHost string, } c := &ClientConn{ - transport: transport, - gbnOptions: []gbn.Option{ - gbn.WithTimeout(gbnTimeout), - gbn.WithHandshakeTimeout(gbnHandshakeTimeout), - gbn.WithKeepalivePing( - gbnClientPingTimeout, gbnPongTimeout, - ), - }, + transport: transport, status: ClientStatusNotConnected, onNewStatus: onNewStatus, quit: make(chan struct{}), cancel: cancel, log: logger, } + + c.gbnOptions = []gbn.Option{ + gbn.WithTimeout(gbnTimeout), + gbn.WithHandshakeTimeout(gbnHandshakeTimeout), + gbn.WithKeepalivePing( + gbnClientPingTimeout, gbnPongTimeout, + ), + gbn.WithOnFIN(func() { + c.setStatus(ClientStatusSessionNotFound) + }), + } + c.connKit = &connKit{ ctx: ctxc, impl: c,