deprecated nativesockets.dealloc, use freeAddrInfo instead; fixed stdlib deprecations
This commit is contained in:
parent
9f6f78ac61
commit
76eb20d2d3
6 changed files with 35 additions and 33 deletions
|
|
@ -438,7 +438,7 @@ when defined(windows) or defined(nimdoc):
|
||||||
success = false
|
success = false
|
||||||
it = it.ai_next
|
it = it.ai_next
|
||||||
|
|
||||||
dealloc(aiList)
|
freeAddrInfo(aiList)
|
||||||
if not success:
|
if not success:
|
||||||
retFuture.fail(newException(OSError, osErrorMsg(lastError)))
|
retFuture.fail(newException(OSError, osErrorMsg(lastError)))
|
||||||
return retFuture
|
return retFuture
|
||||||
|
|
@ -1047,7 +1047,7 @@ else:
|
||||||
p.selector[fd.SocketHandle].data.PData.writeCBs.add(cb)
|
p.selector[fd.SocketHandle].data.PData.writeCBs.add(cb)
|
||||||
update(fd, p.selector[fd.SocketHandle].events + {EvWrite})
|
update(fd, p.selector[fd.SocketHandle].events + {EvWrite})
|
||||||
|
|
||||||
template processCallbacks(callbacks: expr) =
|
template processCallbacks(callbacks: untyped) =
|
||||||
# Callback may add items to ``callbacks`` which causes issues if
|
# Callback may add items to ``callbacks`` which causes issues if
|
||||||
# we are iterating over it at the same time. We therefore
|
# we are iterating over it at the same time. We therefore
|
||||||
# make a copy to iterate over.
|
# make a copy to iterate over.
|
||||||
|
|
@ -1147,7 +1147,7 @@ else:
|
||||||
success = false
|
success = false
|
||||||
it = it.ai_next
|
it = it.ai_next
|
||||||
|
|
||||||
dealloc(aiList)
|
freeAddrInfo(aiList)
|
||||||
if not success:
|
if not success:
|
||||||
retFuture.fail(newException(OSError, osErrorMsg(lastError)))
|
retFuture.fail(newException(OSError, osErrorMsg(lastError)))
|
||||||
return retFuture
|
return retFuture
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ proc generateExceptionCheck(futSym,
|
||||||
result.add elseNode
|
result.add elseNode
|
||||||
|
|
||||||
template useVar(result: var NimNode, futureVarNode: NimNode, valueReceiver,
|
template useVar(result: var NimNode, futureVarNode: NimNode, valueReceiver,
|
||||||
rootReceiver: expr, fromNode: NimNode) =
|
rootReceiver: untyped, fromNode: NimNode) =
|
||||||
## Params:
|
## Params:
|
||||||
## futureVarNode: The NimNode which is a symbol identifying the Future[T]
|
## futureVarNode: The NimNode which is a symbol identifying the Future[T]
|
||||||
## variable to yield.
|
## variable to yield.
|
||||||
|
|
@ -114,7 +114,7 @@ template useVar(result: var NimNode, futureVarNode: NimNode, valueReceiver,
|
||||||
|
|
||||||
template createVar(result: var NimNode, futSymName: string,
|
template createVar(result: var NimNode, futSymName: string,
|
||||||
asyncProc: NimNode,
|
asyncProc: NimNode,
|
||||||
valueReceiver, rootReceiver: expr,
|
valueReceiver, rootReceiver: untyped,
|
||||||
fromNode: NimNode) =
|
fromNode: NimNode) =
|
||||||
result = newNimNode(nnkStmtList, fromNode)
|
result = newNimNode(nnkStmtList, fromNode)
|
||||||
var futSym = genSym(nskVar, "future")
|
var futSym = genSym(nskVar, "future")
|
||||||
|
|
@ -207,7 +207,7 @@ proc processBody(node, retFutureSym: NimNode,
|
||||||
of nnkTryStmt:
|
of nnkTryStmt:
|
||||||
# try: await x; except: ...
|
# try: await x; except: ...
|
||||||
result = newNimNode(nnkStmtList, node)
|
result = newNimNode(nnkStmtList, node)
|
||||||
template wrapInTry(n, tryBody: expr) =
|
template wrapInTry(n, tryBody: untyped) =
|
||||||
var temp = n
|
var temp = n
|
||||||
n[0] = tryBody
|
n[0] = tryBody
|
||||||
tryBody = temp
|
tryBody = temp
|
||||||
|
|
|
||||||
|
|
@ -603,9 +603,9 @@ proc bindAddr*(socket: AsyncSocket, port = Port(0), address = "") {.
|
||||||
|
|
||||||
var aiList = getAddrInfo(realaddr, port, socket.domain)
|
var aiList = getAddrInfo(realaddr, port, socket.domain)
|
||||||
if bindAddr(socket.fd, aiList.ai_addr, aiList.ai_addrlen.Socklen) < 0'i32:
|
if bindAddr(socket.fd, aiList.ai_addr, aiList.ai_addrlen.Socklen) < 0'i32:
|
||||||
dealloc(aiList)
|
freeAddrInfo(aiList)
|
||||||
raiseOSError(osLastError())
|
raiseOSError(osLastError())
|
||||||
dealloc(aiList)
|
freeAddrInfo(aiList)
|
||||||
|
|
||||||
proc close*(socket: AsyncSocket) =
|
proc close*(socket: AsyncSocket) =
|
||||||
## Closes the socket.
|
## Closes the socket.
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,8 @@ else:
|
||||||
|
|
||||||
export SocketHandle, Sockaddr_in, Addrinfo, INADDR_ANY, SockAddr, SockLen,
|
export SocketHandle, Sockaddr_in, Addrinfo, INADDR_ANY, SockAddr, SockLen,
|
||||||
Sockaddr_in6,
|
Sockaddr_in6,
|
||||||
inet_ntoa, recv, `==`, connect, send, accept, recvfrom, sendto
|
inet_ntoa, recv, `==`, connect, send, accept, recvfrom, sendto,
|
||||||
|
freeAddrInfo
|
||||||
|
|
||||||
export
|
export
|
||||||
SO_ERROR,
|
SO_ERROR,
|
||||||
|
|
@ -197,7 +198,7 @@ proc getAddrInfo*(address: string, port: Port, domain: Domain = AF_INET,
|
||||||
protocol: Protocol = IPPROTO_TCP): ptr AddrInfo =
|
protocol: Protocol = IPPROTO_TCP): ptr AddrInfo =
|
||||||
##
|
##
|
||||||
##
|
##
|
||||||
## **Warning**: The resulting ``ptr TAddrInfo`` must be freed using ``dealloc``!
|
## **Warning**: The resulting ``ptr AddrInfo`` must be freed using ``freeAddrInfo``!
|
||||||
var hints: AddrInfo
|
var hints: AddrInfo
|
||||||
result = nil
|
result = nil
|
||||||
hints.ai_family = toInt(domain)
|
hints.ai_family = toInt(domain)
|
||||||
|
|
@ -216,7 +217,8 @@ proc getAddrInfo*(address: string, port: Port, domain: Domain = AF_INET,
|
||||||
else:
|
else:
|
||||||
raiseOSError(osLastError(), $gai_strerror(gaiResult))
|
raiseOSError(osLastError(), $gai_strerror(gaiResult))
|
||||||
|
|
||||||
proc dealloc*(ai: ptr AddrInfo) =
|
proc dealloc*(ai: ptr AddrInfo) {.deprecated.} =
|
||||||
|
## Deprecated since 0.16.2. Use ``freeAddrInfo`` instead.
|
||||||
freeaddrinfo(ai)
|
freeaddrinfo(ai)
|
||||||
|
|
||||||
proc ntohl*(x: uint32): uint32 =
|
proc ntohl*(x: uint32): uint32 =
|
||||||
|
|
@ -229,7 +231,7 @@ proc ntohl*(x: uint32): uint32 =
|
||||||
(x shl 8'u32 and 0xff0000'u32) or
|
(x shl 8'u32 and 0xff0000'u32) or
|
||||||
(x shl 24'u32)
|
(x shl 24'u32)
|
||||||
|
|
||||||
template ntohl*(x: int32): expr {.deprecated.} =
|
template ntohl*(x: int32): untyped {.deprecated.} =
|
||||||
## Converts 32-bit integers from network to host byte order.
|
## Converts 32-bit integers from network to host byte order.
|
||||||
## On machines where the host byte order is the same as network byte order,
|
## On machines where the host byte order is the same as network byte order,
|
||||||
## this is a no-op; otherwise, it performs a 4-byte swap operation.
|
## this is a no-op; otherwise, it performs a 4-byte swap operation.
|
||||||
|
|
@ -245,7 +247,7 @@ proc ntohs*(x: uint16): uint16 =
|
||||||
when cpuEndian == bigEndian: result = x
|
when cpuEndian == bigEndian: result = x
|
||||||
else: result = (x shr 8'u16) or (x shl 8'u16)
|
else: result = (x shr 8'u16) or (x shl 8'u16)
|
||||||
|
|
||||||
template ntohs*(x: int16): expr {.deprecated.} =
|
template ntohs*(x: int16): untyped {.deprecated.} =
|
||||||
## Converts 16-bit integers from network to host byte order. On
|
## Converts 16-bit integers from network to host byte order. On
|
||||||
## machines where the host byte order is the same as network byte order,
|
## machines where the host byte order is the same as network byte order,
|
||||||
## this is a no-op; otherwise, it performs a 2-byte swap operation.
|
## this is a no-op; otherwise, it performs a 2-byte swap operation.
|
||||||
|
|
@ -254,7 +256,7 @@ template ntohs*(x: int16): expr {.deprecated.} =
|
||||||
## this template.
|
## this template.
|
||||||
cast[int16](ntohs(cast[uint16](x)))
|
cast[int16](ntohs(cast[uint16](x)))
|
||||||
|
|
||||||
template htonl*(x: int32): expr {.deprecated.} =
|
template htonl*(x: int32): untyped {.deprecated.} =
|
||||||
## Converts 32-bit integers from host to network byte order. On machines
|
## Converts 32-bit integers from host to network byte order. On machines
|
||||||
## where the host byte order is the same as network byte order, this is
|
## where the host byte order is the same as network byte order, this is
|
||||||
## a no-op; otherwise, it performs a 4-byte swap operation.
|
## a no-op; otherwise, it performs a 4-byte swap operation.
|
||||||
|
|
@ -263,13 +265,13 @@ template htonl*(x: int32): expr {.deprecated.} =
|
||||||
## version of this template.
|
## version of this template.
|
||||||
nativesockets.ntohl(x)
|
nativesockets.ntohl(x)
|
||||||
|
|
||||||
template htonl*(x: uint32): expr =
|
template htonl*(x: uint32): untyped =
|
||||||
## Converts 32-bit unsigned integers from host to network byte order. On
|
## Converts 32-bit unsigned integers from host to network byte order. On
|
||||||
## machines where the host byte order is the same as network byte order,
|
## machines where the host byte order is the same as network byte order,
|
||||||
## this is a no-op; otherwise, it performs a 4-byte swap operation.
|
## this is a no-op; otherwise, it performs a 4-byte swap operation.
|
||||||
nativesockets.ntohl(x)
|
nativesockets.ntohl(x)
|
||||||
|
|
||||||
template htons*(x: int16): expr {.deprecated.} =
|
template htons*(x: int16): untyped {.deprecated.} =
|
||||||
## Converts 16-bit integers from host to network byte order.
|
## Converts 16-bit integers from host to network byte order.
|
||||||
## On machines where the host byte order is the same as network byte
|
## On machines where the host byte order is the same as network byte
|
||||||
## order, this is a no-op; otherwise, it performs a 2-byte swap operation.
|
## order, this is a no-op; otherwise, it performs a 2-byte swap operation.
|
||||||
|
|
@ -278,7 +280,7 @@ template htons*(x: int16): expr {.deprecated.} =
|
||||||
## this template.
|
## this template.
|
||||||
nativesockets.ntohs(x)
|
nativesockets.ntohs(x)
|
||||||
|
|
||||||
template htons*(x: uint16): expr =
|
template htons*(x: uint16): untyped =
|
||||||
## Converts 16-bit unsigned integers from host to network byte order.
|
## Converts 16-bit unsigned integers from host to network byte order.
|
||||||
## On machines where the host byte order is the same as network byte
|
## On machines where the host byte order is the same as network byte
|
||||||
## order, this is a no-op; otherwise, it performs a 2-byte swap operation.
|
## order, this is a no-op; otherwise, it performs a 2-byte swap operation.
|
||||||
|
|
|
||||||
|
|
@ -204,12 +204,12 @@ proc newSocket*(fd: SocketHandle, domain: Domain = AF_INET,
|
||||||
protocol: Protocol = IPPROTO_TCP, buffered = true): Socket =
|
protocol: Protocol = IPPROTO_TCP, buffered = true): Socket =
|
||||||
## Creates a new socket as specified by the params.
|
## Creates a new socket as specified by the params.
|
||||||
assert fd != osInvalidSocket
|
assert fd != osInvalidSocket
|
||||||
new(result)
|
result = Socket(
|
||||||
result.fd = fd
|
fd: fd,
|
||||||
result.isBuffered = buffered
|
isBuffered: buffered,
|
||||||
result.domain = domain
|
domain: domain,
|
||||||
result.sockType = sockType
|
sockType: sockType,
|
||||||
result.protocol = protocol
|
protocol: protocol)
|
||||||
if buffered:
|
if buffered:
|
||||||
result.currPos = 0
|
result.currPos = 0
|
||||||
|
|
||||||
|
|
@ -549,9 +549,9 @@ proc bindAddr*(socket: Socket, port = Port(0), address = "") {.
|
||||||
else:
|
else:
|
||||||
var aiList = getAddrInfo(address, port, socket.domain)
|
var aiList = getAddrInfo(address, port, socket.domain)
|
||||||
if bindAddr(socket.fd, aiList.ai_addr, aiList.ai_addrlen.SockLen) < 0'i32:
|
if bindAddr(socket.fd, aiList.ai_addr, aiList.ai_addrlen.SockLen) < 0'i32:
|
||||||
dealloc(aiList)
|
freeAddrInfo(aiList)
|
||||||
raiseOSError(osLastError())
|
raiseOSError(osLastError())
|
||||||
dealloc(aiList)
|
freeAddrInfo(aiList)
|
||||||
|
|
||||||
proc acceptAddr*(server: Socket, client: var Socket, address: var string,
|
proc acceptAddr*(server: Socket, client: var Socket, address: var string,
|
||||||
flags = {SocketFlag.SafeDisconn}) {.
|
flags = {SocketFlag.SafeDisconn}) {.
|
||||||
|
|
@ -1182,7 +1182,7 @@ proc sendTo*(socket: Socket, address: string, port: Port, data: pointer,
|
||||||
break
|
break
|
||||||
it = it.ai_next
|
it = it.ai_next
|
||||||
|
|
||||||
dealloc(aiList)
|
freeAddrInfo(aiList)
|
||||||
|
|
||||||
proc sendTo*(socket: Socket, address: string, port: Port,
|
proc sendTo*(socket: Socket, address: string, port: Port,
|
||||||
data: string): int {.tags: [WriteIOEffect].} =
|
data: string): int {.tags: [WriteIOEffect].} =
|
||||||
|
|
@ -1503,7 +1503,7 @@ proc connect*(socket: Socket, address: string,
|
||||||
else: lastError = osLastError()
|
else: lastError = osLastError()
|
||||||
it = it.ai_next
|
it = it.ai_next
|
||||||
|
|
||||||
dealloc(aiList)
|
freeAddrInfo(aiList)
|
||||||
if not success: raiseOSError(lastError)
|
if not success: raiseOSError(lastError)
|
||||||
|
|
||||||
when defineSsl:
|
when defineSsl:
|
||||||
|
|
@ -1551,7 +1551,7 @@ proc connectAsync(socket: Socket, name: string, port = Port(0),
|
||||||
|
|
||||||
it = it.ai_next
|
it = it.ai_next
|
||||||
|
|
||||||
dealloc(aiList)
|
freeAddrInfo(aiList)
|
||||||
if not success: raiseOSError(lastError)
|
if not success: raiseOSError(lastError)
|
||||||
|
|
||||||
proc connect*(socket: Socket, address: string, port = Port(0),
|
proc connect*(socket: Socket, address: string, port = Port(0),
|
||||||
|
|
|
||||||
|
|
@ -378,7 +378,7 @@ when defined(windows) or defined(nimdoc):
|
||||||
success = false
|
success = false
|
||||||
it = it.ai_next
|
it = it.ai_next
|
||||||
|
|
||||||
dealloc(aiList)
|
freeAddrInfo(aiList)
|
||||||
if not success:
|
if not success:
|
||||||
retFuture.fail(newException(OSError, osErrorMsg(lastError)))
|
retFuture.fail(newException(OSError, osErrorMsg(lastError)))
|
||||||
return retFuture
|
return retFuture
|
||||||
|
|
@ -1348,7 +1348,7 @@ else:
|
||||||
success = false
|
success = false
|
||||||
it = it.ai_next
|
it = it.ai_next
|
||||||
|
|
||||||
dealloc(aiList)
|
freeAddrInfo(aiList)
|
||||||
if not success:
|
if not success:
|
||||||
retFuture.fail(newException(OSError, osErrorMsg(lastError)))
|
retFuture.fail(newException(OSError, osErrorMsg(lastError)))
|
||||||
return retFuture
|
return retFuture
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue