Skip to content

Commit

Permalink
fix issue linxGnu#151, bind not restarting when user uses closeBond
Browse files Browse the repository at this point in the history
  • Loading branch information
laduchesneau committed Sep 4, 2024
1 parent 3cf20dc commit 0dcdeb9
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion transceivable.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ func (t *transceivable) SystemID() string {
// Close transceiver and stop underlying daemons.
func (t *transceivable) Close() (err error) {
if atomic.CompareAndSwapInt32(&t.aliveState, Alive, Closed) {
t.cancel()

// closing input and output
_ = t.out.close(StoppingProcessOnly)
_ = t.in.close(StoppingProcessOnly)
Expand All @@ -127,6 +129,8 @@ func (t *transceivable) Close() (err error) {
if t.settings.OnClosed != nil {
t.settings.OnClosed(ExplicitClosing)
}

t.wg.Wait()
}
return
}
Expand Down Expand Up @@ -161,7 +165,7 @@ func (t *transceivable) windowCleanup() {
if t.settings.OnExpiredPduRequest != nil {
bindClose := t.settings.OnExpiredPduRequest(request.PDU)
if bindClose {
_ = t.Close()
t.closing(ConnectionIssue)
}
}
}
Expand All @@ -170,3 +174,19 @@ func (t *transceivable) windowCleanup() {
}
}
}

func (t *transceivable) closing(state State) {
if atomic.CompareAndSwapInt32(&t.aliveState, Alive, Closed) {
t.in.closing(StoppingProcessOnly)
t.out.closing(StoppingProcessOnly)

// close underlying conn
_ = t.conn.Close()

// notify transceiver closed
if t.settings.OnClosed != nil {
t.settings.OnClosed(state)
}
}
return
}

0 comments on commit 0dcdeb9

Please sign in to comment.