Skip to content

Commit 9dea4b7

Browse files
committed
add
1 parent 7e1a7b2 commit 9dea4b7

12 files changed

Lines changed: 60063 additions & 45764 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
tests/**
22
!tests/**/*.nim
3+
nimble.develop
4+
nimble.paths
5+

config.nims

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ when not defined(windows):
99
usages
1010
--styleCheck:
1111
error
12+
# begin Nimble config (version 2)
13+
when withDir(thisDir(), system.fileExists("nimble.paths")):
14+
include "nimble.paths"
15+
# end Nimble config

lsquic.nimble

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ requires "nim >= 2.0.0"
1010
requires "zlib"
1111
requires "nim >= 2.0.0"
1212
requires "stew >= 0.4.0"
13+
requires "https://github.com/status-im/nim-chronos#03d928216facac908489757426a8b022ba4ceac7"
1314
requires "chronos >= 4.0.4"
1415
requires "nimcrypto >= 0.6.0"
1516
requires "unittest2"

lsquic/api.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ proc listen*(
4343
proc new*(
4444
t: typedesc[QuicClient], tlsConfig: TLSConfig
4545
): QuicClient {.raises: [QuicError, TransportOsError].} =
46-
let outgoing = newAsyncQueue[Datagram]()
46+
let outgoing = ManyQueue[Datagram]()
4747

4848
let clientCtx = ClientContext.new(tlsConfig, outgoing).valueOr:
4949
raise newException(QuicError, error)

lsquic/connectionmanager.nim

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import chronicles
1+
import chronicles, sequtils
22
import chronos
33
import chronos/osdefs
44
import results
@@ -10,7 +10,7 @@ type ConnectionManager* = ref object of RootObj
1010
tlsConfig*: TLSConfig
1111
udp*: DatagramTransport
1212
quicContext*: QuicContext
13-
outgoing*: AsyncQueue[Datagram]
13+
outgoing*: ManyQueue[Datagram]
1414
connections: seq[Connection]
1515
loop*: Future[void]
1616
closed*: Future[void]
@@ -20,7 +20,7 @@ proc init*(
2020
tlsConfig: TLSConfig,
2121
udp: DatagramTransport,
2222
quicContext: QuicContext,
23-
outgoing: AsyncQueue[Datagram],
23+
outgoing: ManyQueue[Datagram],
2424
) =
2525
c.tlsConfig = tlsConfig
2626
c.quicContext = quicContext
@@ -34,7 +34,7 @@ proc new*(
3434
tlsConfig: TLSConfig,
3535
udp: DatagramTransport,
3636
quicContext: QuicContext,
37-
outgoing: AsyncQueue[Datagram],
37+
outgoing: ManyQueue[Datagram],
3838
): T =
3939
let ret = ConnectionManager()
4040
ret.init(tlsConfig, udp, quicContext, outgoing)
@@ -50,12 +50,12 @@ proc startSending*(connman: ConnectionManager) =
5050

5151
proc send() {.async: (raises: [CancelledError]).} =
5252
try:
53-
let datagram = await connman.outgoing.get()
54-
if datagram.len == 0:
55-
# In windows, empty datagrams will make the peer stop receiving data
56-
return
57-
await connman.udp.sendTo(datagram.taddr, datagram.data)
58-
except TransportError as e:
53+
let datagrams = await connman.outgoing.get()
54+
let req = datagrams.mapIt((it.taddr, it.data))
55+
# echo "111111111 ", req.len
56+
await connman.udp.sendTo(req)
57+
# echo "2222222"
58+
except CatchableError as e:
5959
debug "Failed to send datagram", errorMsg = e.msg
6060

6161
connman.loop = asyncLoop(send)

lsquic/context/client.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import chronos
44
import chronos/osdefs
55
import ./[context, io, stream]
66
import ../[lsquic_ffi, tlsconfig, datagram, timeout, stream]
7-
import ../helpers/sequninit
7+
import ../helpers/[sequninit]
88

99
proc onNewConn(
1010
stream_if_ctx: pointer, conn: ptr lsquic_conn_t
@@ -105,7 +105,7 @@ method dial*(
105105
const BBRv1 = 2
106106

107107
proc new*(
108-
T: typedesc[ClientContext], tlsConfig: TLSConfig, outgoing: AsyncQueue[Datagram]
108+
T: typedesc[ClientContext], tlsConfig: TLSConfig, outgoing: ManyQueue[Datagram]
109109
): Result[T, string] =
110110
var ctx = ClientContext()
111111
ctx.tlsConfig = tlsConfig

lsquic/context/context.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type QuicContext* = ref object of RootObj
1818
engine*: ptr struct_lsquic_engine
1919
stream_if*: struct_lsquic_stream_if
2020
tlsConfig*: TLSConfig
21-
outgoing*: AsyncQueue[Datagram]
21+
outgoing*: ManyQueue[Datagram]
2222
tickTimeout*: Timeout
2323
sslCtx*: ptr SSL_CTX
2424

lsquic/context/io.nim

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,10 @@ proc sendPacketsOut*(
5555
continue
5656
copyMem(addr data[currLen], currIov.iov_base, currIov.iov_len)
5757
currLen += currIov.iov_len.int
58-
58+
5959
let taddr = toTransportAddress(curr.dest_sa)
6060
let datagram = Datagram(data: data, ecn: curr.ecn, taddr: taddr)
61-
try:
62-
quicCtx.outgoing.putNoWait(datagram)
63-
sent.inc
64-
except AsyncQueueFullError:
65-
discard # nothing to do
61+
quicCtx.outgoing.put(datagram)
62+
sent.inc
6663

6764
sent.cint

lsquic/context/server.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const BBRv1 = 2
4141
proc new*(
4242
T: typedesc[ServerContext],
4343
tlsConfig: TLSConfig,
44-
outgoing: AsyncQueue[Datagram],
44+
outgoing: ManyQueue[Datagram],
4545
incoming: AsyncQueue[QuicConnection],
4646
): Result[T, string] =
4747
var ctx = ServerContext()

lsquic/listener.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type Listener* = ref object of ConnectionManager
1313
proc newListener*(
1414
tlsConfig: TLSConfig, address: TransportAddress
1515
): Result[Listener, string] =
16-
let outgoing = newAsyncQueue[Datagram]()
16+
let outgoing = ManyQueue[Datagram]()
1717
let incoming = newAsyncQueue[QuicConnection]()
1818
let quicContext = ?ServerContext.new(tlsConfig, outgoing, incoming)
1919
let listener = Listener(incoming: incoming)

0 commit comments

Comments
 (0)