-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf21a4b
commit dae294b
Showing
3 changed files
with
48 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,43 @@ | ||
package dilithium | ||
|
||
// Closer manages the state machine for the shutdown of a TxPortal and RxPortal pair (one side of a communication). | ||
import ( | ||
"github.com/openziti/dilithium/util" | ||
"github.com/sirupsen/logrus" | ||
"time" | ||
) | ||
|
||
// closer manages the state machine for the shutdown of a TxPortal and RxPortal pair (one side of a communication). | ||
// | ||
type Closer struct { | ||
type closer struct { | ||
seq *util.Sequence | ||
rxCloseSeq int32 | ||
rxCloseSeqIn chan int32 | ||
txCloseSeq int32 | ||
txCloseSeqIn chan int32 | ||
txp *TxPortal | ||
rxp *RxPortal | ||
lastEvent time.Time | ||
closeHook func() | ||
} | ||
|
||
func newCloser(seq *util.Sequence, closeHook func()) *closer { | ||
return &closer{ | ||
seq: seq, | ||
rxCloseSeq: notClosed, | ||
rxCloseSeqIn: make(chan int32, 1), | ||
txCloseSeq: notClosed, | ||
txCloseSeqIn: make(chan int32, 1), | ||
closeHook: closeHook, | ||
} | ||
} | ||
|
||
func (c *closer) emergencyStop() { | ||
logrus.Info("broken glass") | ||
c.txp.close() | ||
c.rxp.Close() | ||
if c.closeHook != nil { | ||
c.closeHook() | ||
} | ||
} | ||
|
||
const notClosed = int32(-99) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters