Add read loop for sctp connexion

This commit is contained in:
Ludovic Chenut 2023-10-13 15:06:06 +02:00
parent 95c4805ab6
commit 64d374d837
No known key found for this signature in database
GPG Key ID: D9A59B1907F1D50C
1 changed files with 12 additions and 1 deletions

View File

@ -45,6 +45,7 @@ type
state: SctpState state: SctpState
connectEvent: AsyncEvent connectEvent: AsyncEvent
acceptEvent: AsyncEvent acceptEvent: AsyncEvent
readLoop: Future[void]
sctp: Sctp sctp: Sctp
udp: DatagramTransport udp: DatagramTransport
address: TransportAddress address: TransportAddress
@ -340,6 +341,16 @@ proc stop*(self: Sctp) {.async.} =
discard self.usrsctpAwait usrsctp_finish() discard self.usrsctpAwait usrsctp_finish()
self.udp.close() self.udp.close()
proc readLoopProc(res: SctpConn) {.async.} =
while true:
let
msg = await res.conn.read()
data = usrsctp_dumppacket(unsafeAddr msg[0], uint(msg.len), SCTP_DUMP_INBOUND)
if data != nil:
trace "Receive connection", remoteAddress = result.conn.raddr, data = data.packetPretty()
usrsctp_freedumpbuffer(data)
usrsctp_conninput(cast[pointer](res), unsafeAddr msg[0], uint(msg.len), 0)
proc accept*(self: Sctp): Future[SctpConn] {.async.} = proc accept*(self: Sctp): Future[SctpConn] {.async.} =
if not self.isServer: if not self.isServer:
raise newSctpError("Not a server") raise newSctpError("Not a server")
@ -354,7 +365,7 @@ proc accept*(self: Sctp): Future[SctpConn] {.async.} =
usrsctp_freedumpbuffer(data) usrsctp_freedumpbuffer(data)
# sctp.sentAddress = raddr # sctp.sentAddress = raddr
usrsctp_register_address(cast[pointer](res)) usrsctp_register_address(cast[pointer](res))
usrsctp_conninput(cast[pointer](res), unsafeAddr msg[0], uint(msg.len), 0) res.readLoop = res.readLoopProc()
res.acceptEvent.clear() res.acceptEvent.clear()
await res.acceptEvent.wait() await res.acceptEvent.wait()
return res return res