mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 09:24:36 +00:00
deprecated nativesockets.dealloc, use freeAddrInfo instead; fixed stdlib deprecations
This commit is contained in:
@@ -438,7 +438,7 @@ when defined(windows) or defined(nimdoc):
|
||||
success = false
|
||||
it = it.ai_next
|
||||
|
||||
dealloc(aiList)
|
||||
freeAddrInfo(aiList)
|
||||
if not success:
|
||||
retFuture.fail(newException(OSError, osErrorMsg(lastError)))
|
||||
return retFuture
|
||||
@@ -750,7 +750,7 @@ when defined(windows) or defined(nimdoc):
|
||||
var lpOutputBuf = newString(lpOutputLen)
|
||||
var dwBytesReceived: Dword
|
||||
let dwReceiveDataLength = 0.Dword # We don't want any data to be read.
|
||||
let dwLocalAddressLength = Dword(sizeof (Sockaddr_in) + 16)
|
||||
let dwLocalAddressLength = Dword(sizeof(Sockaddr_in) + 16)
|
||||
let dwRemoteAddressLength = Dword(sizeof(Sockaddr_in) + 16)
|
||||
|
||||
template completeAccept() {.dirty.} =
|
||||
@@ -1047,7 +1047,7 @@ else:
|
||||
p.selector[fd.SocketHandle].data.PData.writeCBs.add(cb)
|
||||
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
|
||||
# we are iterating over it at the same time. We therefore
|
||||
# make a copy to iterate over.
|
||||
@@ -1147,7 +1147,7 @@ else:
|
||||
success = false
|
||||
it = it.ai_next
|
||||
|
||||
dealloc(aiList)
|
||||
freeAddrInfo(aiList)
|
||||
if not success:
|
||||
retFuture.fail(newException(OSError, osErrorMsg(lastError)))
|
||||
return retFuture
|
||||
|
||||
@@ -96,7 +96,7 @@ proc generateExceptionCheck(futSym,
|
||||
result.add elseNode
|
||||
|
||||
template useVar(result: var NimNode, futureVarNode: NimNode, valueReceiver,
|
||||
rootReceiver: expr, fromNode: NimNode) =
|
||||
rootReceiver: untyped, fromNode: NimNode) =
|
||||
## Params:
|
||||
## futureVarNode: The NimNode which is a symbol identifying the Future[T]
|
||||
## variable to yield.
|
||||
@@ -114,7 +114,7 @@ template useVar(result: var NimNode, futureVarNode: NimNode, valueReceiver,
|
||||
|
||||
template createVar(result: var NimNode, futSymName: string,
|
||||
asyncProc: NimNode,
|
||||
valueReceiver, rootReceiver: expr,
|
||||
valueReceiver, rootReceiver: untyped,
|
||||
fromNode: NimNode) =
|
||||
result = newNimNode(nnkStmtList, fromNode)
|
||||
var futSym = genSym(nskVar, "future")
|
||||
@@ -207,7 +207,7 @@ proc processBody(node, retFutureSym: NimNode,
|
||||
of nnkTryStmt:
|
||||
# try: await x; except: ...
|
||||
result = newNimNode(nnkStmtList, node)
|
||||
template wrapInTry(n, tryBody: expr) =
|
||||
template wrapInTry(n, tryBody: untyped) =
|
||||
var temp = n
|
||||
n[0] = tryBody
|
||||
tryBody = temp
|
||||
|
||||
@@ -603,9 +603,9 @@ proc bindAddr*(socket: AsyncSocket, port = Port(0), address = "") {.
|
||||
|
||||
var aiList = getAddrInfo(realaddr, port, socket.domain)
|
||||
if bindAddr(socket.fd, aiList.ai_addr, aiList.ai_addrlen.Socklen) < 0'i32:
|
||||
dealloc(aiList)
|
||||
freeAddrInfo(aiList)
|
||||
raiseOSError(osLastError())
|
||||
dealloc(aiList)
|
||||
freeAddrInfo(aiList)
|
||||
|
||||
proc close*(socket: AsyncSocket) =
|
||||
## Closes the socket.
|
||||
|
||||
@@ -31,7 +31,8 @@ else:
|
||||
|
||||
export SocketHandle, Sockaddr_in, Addrinfo, INADDR_ANY, SockAddr, SockLen,
|
||||
Sockaddr_in6,
|
||||
inet_ntoa, recv, `==`, connect, send, accept, recvfrom, sendto
|
||||
inet_ntoa, recv, `==`, connect, send, accept, recvfrom, sendto,
|
||||
freeAddrInfo
|
||||
|
||||
export
|
||||
SO_ERROR,
|
||||
@@ -197,7 +198,7 @@ proc getAddrInfo*(address: string, port: Port, domain: Domain = AF_INET,
|
||||
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
|
||||
result = nil
|
||||
hints.ai_family = toInt(domain)
|
||||
@@ -216,7 +217,8 @@ proc getAddrInfo*(address: string, port: Port, domain: Domain = AF_INET,
|
||||
else:
|
||||
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)
|
||||
|
||||
proc ntohl*(x: uint32): uint32 =
|
||||
@@ -229,7 +231,7 @@ proc ntohl*(x: uint32): uint32 =
|
||||
(x shl 8'u32 and 0xff0000'u32) or
|
||||
(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.
|
||||
## 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.
|
||||
@@ -245,7 +247,7 @@ proc ntohs*(x: uint16): uint16 =
|
||||
when cpuEndian == bigEndian: result = x
|
||||
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
|
||||
## 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.
|
||||
@@ -254,7 +256,7 @@ template ntohs*(x: int16): expr {.deprecated.} =
|
||||
## this template.
|
||||
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
|
||||
## 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.
|
||||
@@ -263,13 +265,13 @@ template htonl*(x: int32): expr {.deprecated.} =
|
||||
## version of this template.
|
||||
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
|
||||
## 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.
|
||||
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.
|
||||
## 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.
|
||||
@@ -278,7 +280,7 @@ template htons*(x: int16): expr {.deprecated.} =
|
||||
## this template.
|
||||
nativesockets.ntohs(x)
|
||||
|
||||
template htons*(x: uint16): expr =
|
||||
template htons*(x: uint16): untyped =
|
||||
## Converts 16-bit unsigned integers from host to 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 2-byte swap operation.
|
||||
@@ -570,7 +572,7 @@ proc select*(readfds: var seq[SocketHandle], timeout = 500): int {.deprecated.}
|
||||
result = int(select(cint(m+1), addr(rd), nil, nil, nil))
|
||||
|
||||
pruneSocketSet(readfds, (rd))
|
||||
|
||||
|
||||
proc selectRead*(readfds: var seq[SocketHandle], timeout = 500): int =
|
||||
## When a socket in ``readfds`` is ready to be read from then a non-zero
|
||||
## value will be returned specifying the count of the sockets which can be
|
||||
|
||||
@@ -204,12 +204,12 @@ proc newSocket*(fd: SocketHandle, domain: Domain = AF_INET,
|
||||
protocol: Protocol = IPPROTO_TCP, buffered = true): Socket =
|
||||
## Creates a new socket as specified by the params.
|
||||
assert fd != osInvalidSocket
|
||||
new(result)
|
||||
result.fd = fd
|
||||
result.isBuffered = buffered
|
||||
result.domain = domain
|
||||
result.sockType = sockType
|
||||
result.protocol = protocol
|
||||
result = Socket(
|
||||
fd: fd,
|
||||
isBuffered: buffered,
|
||||
domain: domain,
|
||||
sockType: sockType,
|
||||
protocol: protocol)
|
||||
if buffered:
|
||||
result.currPos = 0
|
||||
|
||||
@@ -425,7 +425,7 @@ when defineSsl:
|
||||
## **Disclaimer**: This code is not well tested, may be very unsafe and
|
||||
## prone to security vulnerabilities.
|
||||
|
||||
assert (not socket.isSSL)
|
||||
assert(not socket.isSSL)
|
||||
socket.isSSL = true
|
||||
socket.sslContext = ctx
|
||||
socket.sslHandle = SSLNew(socket.sslContext.context)
|
||||
@@ -549,9 +549,9 @@ proc bindAddr*(socket: Socket, port = Port(0), address = "") {.
|
||||
else:
|
||||
var aiList = getAddrInfo(address, port, socket.domain)
|
||||
if bindAddr(socket.fd, aiList.ai_addr, aiList.ai_addrlen.SockLen) < 0'i32:
|
||||
dealloc(aiList)
|
||||
freeAddrInfo(aiList)
|
||||
raiseOSError(osLastError())
|
||||
dealloc(aiList)
|
||||
freeAddrInfo(aiList)
|
||||
|
||||
proc acceptAddr*(server: Socket, client: var Socket, address: var string,
|
||||
flags = {SocketFlag.SafeDisconn}) {.
|
||||
@@ -1182,7 +1182,7 @@ proc sendTo*(socket: Socket, address: string, port: Port, data: pointer,
|
||||
break
|
||||
it = it.ai_next
|
||||
|
||||
dealloc(aiList)
|
||||
freeAddrInfo(aiList)
|
||||
|
||||
proc sendTo*(socket: Socket, address: string, port: Port,
|
||||
data: string): int {.tags: [WriteIOEffect].} =
|
||||
@@ -1503,7 +1503,7 @@ proc connect*(socket: Socket, address: string,
|
||||
else: lastError = osLastError()
|
||||
it = it.ai_next
|
||||
|
||||
dealloc(aiList)
|
||||
freeAddrInfo(aiList)
|
||||
if not success: raiseOSError(lastError)
|
||||
|
||||
when defineSsl:
|
||||
@@ -1551,7 +1551,7 @@ proc connectAsync(socket: Socket, name: string, port = Port(0),
|
||||
|
||||
it = it.ai_next
|
||||
|
||||
dealloc(aiList)
|
||||
freeAddrInfo(aiList)
|
||||
if not success: raiseOSError(lastError)
|
||||
|
||||
proc connect*(socket: Socket, address: string, port = Port(0),
|
||||
|
||||
@@ -378,7 +378,7 @@ when defined(windows) or defined(nimdoc):
|
||||
success = false
|
||||
it = it.ai_next
|
||||
|
||||
dealloc(aiList)
|
||||
freeAddrInfo(aiList)
|
||||
if not success:
|
||||
retFuture.fail(newException(OSError, osErrorMsg(lastError)))
|
||||
return retFuture
|
||||
@@ -1348,7 +1348,7 @@ else:
|
||||
success = false
|
||||
it = it.ai_next
|
||||
|
||||
dealloc(aiList)
|
||||
freeAddrInfo(aiList)
|
||||
if not success:
|
||||
retFuture.fail(newException(OSError, osErrorMsg(lastError)))
|
||||
return retFuture
|
||||
|
||||
Reference in New Issue
Block a user