mirror of
https://github.com/vacp2p/nim-quic.git
synced 2026-01-08 21:38:05 -05:00
fix: sending datagram (#104)
This commit is contained in:
@@ -155,23 +155,12 @@ proc send(
|
||||
let written = addr result
|
||||
var datagram = trySend(connection, streamId, messagePtr, messageLen, written, isFin)
|
||||
|
||||
# Special handling for empty data - avoid infinite waiting
|
||||
if messageLen == 0:
|
||||
if isFin:
|
||||
# For FIN-only packets, handle them properly without waiting
|
||||
if datagram.data.len > 0:
|
||||
connection.onSend(datagram)
|
||||
else:
|
||||
# Force a general send to flush any pending packets
|
||||
connection.send()
|
||||
connection.updateExpiryTimer()
|
||||
return
|
||||
else:
|
||||
# For empty writes without FIN, treat as no-op
|
||||
# Return 0 bytes written since there was nothing to write
|
||||
result = 0
|
||||
connection.updateExpiryTimer()
|
||||
return
|
||||
# For empty writes without FIN, treat as no-op
|
||||
# Return 0 bytes written since there was nothing to write
|
||||
if messageLen == 0 and not isFin:
|
||||
result = 0
|
||||
connection.updateExpiryTimer()
|
||||
return
|
||||
|
||||
# Normal flow control for data packets
|
||||
while datagram.data.len == 0:
|
||||
@@ -189,10 +178,10 @@ proc send*(
|
||||
var done = false
|
||||
while not done:
|
||||
let written = await connection.send(streamId, messagePtr, messageLen, isFin)
|
||||
if written != -1:
|
||||
if written >= 0:
|
||||
messagePtr = messagePtr + written
|
||||
messageLen = messageLen - written.uint
|
||||
done = messageLen == 0
|
||||
done = messageLen == 0
|
||||
|
||||
proc tryReceive(connection: Ngtcp2Connection, datagram: openArray[byte], ecn: ECN) =
|
||||
let conn = connection.conn.valueOr:
|
||||
|
||||
Reference in New Issue
Block a user