Add tcp.Listener (#15)

* begin reviewing TCP listener

* begin adding listener tests

* adding TestExchange implementation

* split out legacy and Step tests

* move listener to tcp package

* fix up tcp tests taking very long

* add xnet.TCPPool and work on TCPPool semantics

* xnet: TCPPool only accepts established connections

* xnet: getting to bottom of panic in xnet.Listener

* xnet: improve listener tests

* fix several data races in testing fixtures

* fix more synchronization things in listener test

* finalize tcplistener test
This commit is contained in:
Pat Whittingslow
2026-01-03 12:41:57 -03:00
committed by GitHub
parent 5731a378dd
commit 018f9258ac
19 changed files with 2288 additions and 849 deletions
+7 -6
View File
@@ -83,13 +83,12 @@ func (h *Handler) RemotePort() uint16 {
// OpenActive opens an "active" TCP connection to a known remote port. The caller holds knowledge of the IP address.
// OpenActive is used by TCP Clients to initiate a connection.
func (h *Handler) OpenActive(localPort, remotePort uint16, iss Value) error {
if h.bufRx.Size() < minBufferSize || h.bufTx.Size() < minBufferSize {
if remotePort == 0 {
return lneto.ErrZeroDestination
} else if h.bufRx.Size() < minBufferSize || h.bufTx.Size() < minBufferSize {
return errBufferTooSmall
}
if h.scb.State() != StateClosed && h.scb.State() != StateTimeWait {
} else if h.scb.State() != StateClosed && h.scb.State() != StateTimeWait {
return errNeedClosedTCBToOpen
} else if remotePort == 0 {
return errors.New("zero port on open call")
}
// reset/Abort prepares a SCB for active connection by resetting state to closed.
h.scb.reset()
@@ -101,7 +100,9 @@ func (h *Handler) OpenActive(localPort, remotePort uint16, iss Value) error {
// OpenListen prepares a passive TCP connection where the Handler acts as a server.
// OpenListen is used by TCP Servers to begin listening for remote connections.
func (h *Handler) OpenListen(localPort uint16, iss Value) error {
if h.bufRx.Size() < minBufferSize || h.bufTx.Size() < minBufferSize {
if localPort == 0 {
return lneto.ErrZeroSource
} else if h.bufRx.Size() < minBufferSize || h.bufTx.Size() < minBufferSize {
return errBufferTooSmall
}
// Open will fail unless SCB in closed state.