changes to TCP stack to enable xnet functionality

This commit is contained in:
soypat
2025-08-16 15:17:46 -03:00
parent c2995383da
commit 9cf4e35d2e
10 changed files with 124 additions and 19 deletions
+11 -5
View File
@@ -53,16 +53,17 @@ func (h *Handler) ConnectionID() *uint64 {
func (h *Handler) State() State { return h.scb.State() }
// SetBuffers sets the internal buffers used to receive and transmit bytes asynchronously via [Handler.Write] and [Handler.Read] calls.
// If the argument buffer is nil then the respective currently set buffer will be reused.
func (h *Handler) SetBuffers(txbuf, rxbuf []byte, packets int) error {
if h.bufRx.Buf == nil && (len(rxbuf) < minBufferSize || len(txbuf) < minBufferSize) {
return errors.New("tcp: short buffer")
}
if !h.scb.State().IsClosed() {
return errors.New("tcp.Handler must be closed before setting buffers")
}
if rxbuf != nil {
h.bufRx.Buf = rxbuf
}
if len(h.bufRx.Buf) < minBufferSize {
return errors.New("short rx buffer")
}
h.scb.SetRecvWindow(Size(h.bufRx.Size()))
h.bufRx.Reset()
return h.bufTx.ResetOrReuse(txbuf, packets, 0)
@@ -270,11 +271,16 @@ func (h *Handler) Send(b []byte) (int, error) {
return int(offset)*4 + int(segment.DATALEN), nil
}
// Free returns the amount of space free in the transmit buffer. A call to [Handler.Write] with a larger buffer will fail.
func (h *Handler) Free() int {
// FreeTx returns the amount of space free in the transmit buffer. A call to [Handler.Write] with a larger buffer will fail.
func (h *Handler) FreeTx() int {
return h.bufTx.Free()
}
// SizeRx returns the size of the TCP receive ring buffer.
func (h *Handler) SizeRx() int {
return h.bufRx.Size()
}
// Write implements [io.Writer] by copying b to a internal buffer to be sent over the network on the next
// [Handler.Send] call that can send data to remote peer. Use [Handler.Free] to know the maximum length the argument slice can be before erroring.
func (h *Handler) Write(b []byte) (int, error) {