Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lsquic.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ installFiles = @["lsquic.nim"]
requires "nim >= 2.0.0"
requires "zlib"
requires "stew >= 0.4.0"
requires "chronos >= 4.0.4"
requires "https://github.com/status-im/nim-chronos#012cd2c92e9e62b11976ad15b5fd1404e279cf9a"
requires "unittest2"
requires "chronicles >= 0.11.0"
requires "https://github.com/vacp2p/nim-boringssl >= 0.0.11"
Expand Down
50 changes: 50 additions & 0 deletions lsquic/context/context.nim
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,56 @@ type
running*: bool
ownedCids: HashSet[CidKey]

when defined(windows):
wsaSendMsg: osdefs.LPFN_WSASENDMSG
wsaRecvMsg: osdefs.LPFN_WSARECVMSG

when defined(windows):
proc resolveExtension(
fd: SocketHandle, guid: var GUID, extension: var pointer
): bool {.raises: [].} =
var bytesReturned: DWORD
wsaIoctl(
fd,
osdefs.SIO_GET_EXTENSION_FUNCTION_POINTER,
addr guid,
DWORD(sizeof(guid)),
addr extension,
DWORD(sizeof(extension)),
addr bytesReturned,
nil,
nil,
) == 0

proc initPacketIo*(ctx: QuicContext, fd: SocketHandle): bool {.raises: [].} =
var
sendExtension, recvExtension: pointer
sendGuid = osdefs.WSAID_WSASENDMSG
recvGuid = osdefs.WSAID_WSARECVMSG
if not resolveExtension(fd, sendGuid, sendExtension) or
not resolveExtension(fd, recvGuid, recvExtension):
return false
ctx.wsaSendMsg = cast[osdefs.LPFN_WSASENDMSG](sendExtension)
ctx.wsaRecvMsg = cast[osdefs.LPFN_WSARECVMSG](recvExtension)
true

proc sendMsg*(
ctx: QuicContext, fd: SocketHandle, msg: ptr osdefs.WSAMSG, bytesSent: ptr DWORD
): cint {.inline, raises: [].} =
if ctx.wsaSendMsg.isNil:
return -1
ctx.wsaSendMsg(fd, msg, DWORD(0), bytesSent, nil, nil)

proc recvMsg*(
ctx: QuicContext,
fd: SocketHandle,
msg: ptr osdefs.WSAMSG,
bytesReceived: ptr DWORD,
): cint {.inline, raises: [].} =
if ctx.wsaRecvMsg.isNil:
return -1
ctx.wsaRecvMsg(fd, msg, bytesReceived, nil, nil)

func hash*(cid: CidKey): Hash =
var h = hash(cid.len)
for i in 0 ..< cid.len.int:
Expand Down
Loading
Loading