mirror of
https://github.com/soypat/lneto.git
synced 2026-08-15 12:23:44 +00:00
changes to TCP stack to enable xnet functionality
This commit is contained in:
+9
-1
@@ -44,7 +44,7 @@ type ConnConfig struct {
|
||||
Logger *slog.Logger
|
||||
}
|
||||
|
||||
func (conn *Conn) Configure(config *ConnConfig) (err error) {
|
||||
func (conn *Conn) Configure(config ConnConfig) (err error) {
|
||||
err = conn.h.SetBuffers(config.TxBuf, config.RxBuf, config.TxPacketQueueSize)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -109,9 +109,17 @@ func (conn *Conn) Abort() {
|
||||
h: conn.h,
|
||||
remoteAddr: conn.remoteAddr[:0],
|
||||
logger: conn.logger,
|
||||
ipID: conn.ipID,
|
||||
}
|
||||
}
|
||||
|
||||
// InternalHandler returns the internal [Handler] instance. The Handler contains lower level implementation logic for a TCP connection.
|
||||
// Typical users should not be using this method unless implementing a stack which manages several TCP connections and thus need
|
||||
// access to low level internals for careful memory management.
|
||||
func (conn *Conn) InternalHandler() *Handler {
|
||||
return &conn.h
|
||||
}
|
||||
|
||||
// Write writes argument data to the TCPConns's output buffer which is queued to be sent.
|
||||
func (conn *Conn) Write(b []byte) (int, error) {
|
||||
err := conn.checkPipeOpen()
|
||||
|
||||
+11
-5
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user