add TCPConn Read+Write and ancilliary methods; looks like IP mux is broken

This commit is contained in:
soypat
2025-05-25 18:30:55 -03:00
parent 682e533017
commit a967f083cb
5 changed files with 232 additions and 2 deletions
+18 -1
View File
@@ -30,7 +30,7 @@ type Handler struct {
// connid is a conenction counter that is incremented each time a new
// connection is established via Open calls. This disambiguate's whether
// Read and Write calls belong to the current connection.
connid uint8
connid uint16
closing bool
}
@@ -39,6 +39,11 @@ func (h *Handler) SetLoggers(handler, scb *slog.Logger) {
h.scb.logger.log = scb
}
// ConnectionID returns the connection identifier which is incremented every time the connection is closed or open.
func (h *Handler) ConnectionID() int {
return int(h.connid)
}
// State returns the state of the TCP state machine as per RFC9293. See [State].
func (h *Handler) State() State { return h.scb.State() }
@@ -99,6 +104,13 @@ func (h *Handler) OpenListen(localPort uint16, iss Value) error {
return nil
}
// Abort forcibly terminates all state associated to current connection.
// After a call to abort no more data can be sent nor received over the connection.
func (h *Handler) Abort() {
h.scb.Abort()
h.reset(0, 0, 0)
}
func (h *Handler) reset(localPort, remotePort uint16, iss Value) {
*h = Handler{
scb: h.scb,
@@ -177,6 +189,11 @@ func (h *Handler) Recv(incomingPacket []byte) error {
return nil
}
func (h *Handler) Close() error {
h.trace("tcp.Handler.Close")
return h.scb.Close()
}
// Send writes TCP frame to be sent over the network to the remote peer to `b`.
// It does no IP interfacing or CRC calculation of packet, which is left to the caller to perform.
// The returned integer is the length written to the argument buffer.