tcp.Conn:add Flush method and more lock protection

This commit is contained in:
Patricio Whittingslow
2026-01-01 10:32:13 -03:00
parent f8166aea05
commit c6e88b1c3b
5 changed files with 85 additions and 29 deletions
+10 -1
View File
@@ -228,7 +228,7 @@ func (h *Handler) Send(b []byte) (int, error) {
if err != nil {
return 0, err
}
buffered := h.bufTx.Buffered()
buffered := h.bufTx.BufferedUnsent()
if buffered == 0 && h.closing {
// If Close called and no more data to be sent, terminate connection!
h.closing = false
@@ -328,6 +328,15 @@ func (h *Handler) BufferedInput() int {
return h.bufRx.Buffered()
}
// BufferedUnsent returns the number of bytes in the socket's transmit(output) buffer
// that has yet to be sent.
func (h *Handler) BufferedUnsent() int {
if h.State().IsClosed() {
return 0
}
return h.bufTx.BufferedUnsent()
}
// AvailableOutput returns amount of bytes available to write to output
// before [Handler.Write] returns an error.
func (h *Handler) AvailableOutput() int {