Move all remote address storage to heap.
This commit is contained in:
parent
b231e7ebf8
commit
82f7b9f77f
|
@ -43,15 +43,15 @@ type
|
||||||
udata*: pointer # User-driven pointer
|
udata*: pointer # User-driven pointer
|
||||||
function: DatagramCallback # Receive data callback
|
function: DatagramCallback # Receive data callback
|
||||||
future: Future[void] # Transport's life future
|
future: Future[void] # Transport's life future
|
||||||
|
raddr: Sockaddr_storage # Reader address storage
|
||||||
|
ralen: SockLen # Reader address length
|
||||||
|
waddr: Sockaddr_storage # Writer address storage
|
||||||
|
walen: SockLen # Writer address length
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
rovl: CustomOverlapped # Reader OVERLAPPED structure
|
rovl: CustomOverlapped # Reader OVERLAPPED structure
|
||||||
wovl: CustomOverlapped # Writer OVERLAPPED structure
|
wovl: CustomOverlapped # Writer OVERLAPPED structure
|
||||||
raddr: Sockaddr_storage # Reader address storage
|
|
||||||
ralen: SockLen # Reader address length
|
|
||||||
rflag: int32 # Reader flags storage
|
rflag: int32 # Reader flags storage
|
||||||
rwsabuf: TWSABuf # Reader WSABUF structure
|
rwsabuf: TWSABuf # Reader WSABUF structure
|
||||||
waddr: Sockaddr_storage # Writer address storage
|
|
||||||
wlen: SockLen # Writer address length
|
|
||||||
wwsabuf: TWSABuf # Writer WSABUF structure
|
wwsabuf: TWSABuf # Writer WSABUF structure
|
||||||
|
|
||||||
template setReadError(t, e: untyped) =
|
template setReadError(t, e: untyped) =
|
||||||
|
@ -95,10 +95,10 @@ when defined(windows):
|
||||||
var ret: cint
|
var ret: cint
|
||||||
if vector.kind == WithAddress:
|
if vector.kind == WithAddress:
|
||||||
toSockAddr(vector.address.address, vector.address.port,
|
toSockAddr(vector.address.address, vector.address.port,
|
||||||
transp.waddr, transp.wlen)
|
transp.waddr, transp.walen)
|
||||||
ret = WSASendTo(fd, addr transp.wwsabuf, DWORD(1), addr bytesCount,
|
ret = WSASendTo(fd, addr transp.wwsabuf, DWORD(1), addr bytesCount,
|
||||||
DWORD(0), cast[ptr SockAddr](addr transp.waddr),
|
DWORD(0), cast[ptr SockAddr](addr transp.waddr),
|
||||||
cint(transp.wlen),
|
cint(transp.walen),
|
||||||
cast[POVERLAPPED](addr transp.wovl), nil)
|
cast[POVERLAPPED](addr transp.wovl), nil)
|
||||||
else:
|
else:
|
||||||
ret = WSASend(fd, addr transp.wwsabuf, DWORD(1), addr bytesCount,
|
ret = WSASend(fd, addr transp.wwsabuf, DWORD(1), addr bytesCount,
|
||||||
|
@ -313,11 +313,7 @@ else:
|
||||||
# Linux/BSD/MacOS part
|
# Linux/BSD/MacOS part
|
||||||
|
|
||||||
proc readDatagramLoop(udata: pointer) =
|
proc readDatagramLoop(udata: pointer) =
|
||||||
var
|
var raddr: TransportAddress
|
||||||
saddr: Sockaddr_storage
|
|
||||||
slen: SockLen
|
|
||||||
raddr: TransportAddress
|
|
||||||
|
|
||||||
var cdata = cast[ptr CompletionData](udata)
|
var cdata = cast[ptr CompletionData](udata)
|
||||||
if not isNil(cdata) and (int(cdata.fd) == 0 or isNil(cdata.udata)):
|
if not isNil(cdata) and (int(cdata.fd) == 0 or isNil(cdata.udata)):
|
||||||
# Transport was closed earlier, exiting
|
# Transport was closed earlier, exiting
|
||||||
|
@ -326,13 +322,13 @@ else:
|
||||||
let fd = SocketHandle(cdata.fd)
|
let fd = SocketHandle(cdata.fd)
|
||||||
if not isNil(transp):
|
if not isNil(transp):
|
||||||
while true:
|
while true:
|
||||||
slen = SockLen(sizeof(Sockaddr_storage))
|
transp.ralen = SockLen(sizeof(Sockaddr_storage))
|
||||||
var res = posix.recvfrom(fd, addr transp.buffer[0],
|
var res = posix.recvfrom(fd, addr transp.buffer[0],
|
||||||
cint(len(transp.buffer)), cint(0),
|
cint(len(transp.buffer)), cint(0),
|
||||||
cast[ptr SockAddr](addr saddr),
|
cast[ptr SockAddr](addr transp.raddr),
|
||||||
addr slen)
|
addr transp.ralen)
|
||||||
if res >= 0:
|
if res >= 0:
|
||||||
fromSockAddr(saddr, slen, raddr.address, raddr.port)
|
fromSockAddr(transp.raddr, transp.ralen, raddr.address, raddr.port)
|
||||||
transp.buflen = res
|
transp.buflen = res
|
||||||
discard transp.function(transp, raddr)
|
discard transp.function(transp, raddr)
|
||||||
else:
|
else:
|
||||||
|
@ -346,11 +342,7 @@ else:
|
||||||
break
|
break
|
||||||
|
|
||||||
proc writeDatagramLoop(udata: pointer) =
|
proc writeDatagramLoop(udata: pointer) =
|
||||||
var
|
var res: int
|
||||||
res: int
|
|
||||||
saddr: Sockaddr_storage
|
|
||||||
slen: SockLen
|
|
||||||
|
|
||||||
var cdata = cast[ptr CompletionData](udata)
|
var cdata = cast[ptr CompletionData](udata)
|
||||||
if not isNil(cdata) and (int(cdata.fd) == 0 or isNil(cdata.udata)):
|
if not isNil(cdata) and (int(cdata.fd) == 0 or isNil(cdata.udata)):
|
||||||
# Transport was closed earlier, exiting
|
# Transport was closed earlier, exiting
|
||||||
|
@ -362,10 +354,11 @@ else:
|
||||||
var vector = transp.queue.popFirst()
|
var vector = transp.queue.popFirst()
|
||||||
while true:
|
while true:
|
||||||
if vector.kind == WithAddress:
|
if vector.kind == WithAddress:
|
||||||
toSockAddr(vector.address.address, vector.address.port, saddr, slen)
|
toSockAddr(vector.address.address, vector.address.port,
|
||||||
|
transp.waddr, transp.walen)
|
||||||
res = posix.sendto(fd, vector.buf, vector.buflen, MSG_NOSIGNAL,
|
res = posix.sendto(fd, vector.buf, vector.buflen, MSG_NOSIGNAL,
|
||||||
cast[ptr SockAddr](addr saddr),
|
cast[ptr SockAddr](addr transp.waddr),
|
||||||
slen)
|
transp.walen)
|
||||||
elif vector.kind == WithoutAddress:
|
elif vector.kind == WithoutAddress:
|
||||||
res = posix.send(fd, vector.buf, vector.buflen, MSG_NOSIGNAL)
|
res = posix.send(fd, vector.buf, vector.buflen, MSG_NOSIGNAL)
|
||||||
if res >= 0:
|
if res >= 0:
|
||||||
|
|
Loading…
Reference in New Issue