diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/asyncdispatch.nim | 8 | ||||
-rw-r--r-- | lib/pure/asyncmacro.nim | 6 | ||||
-rw-r--r-- | lib/pure/asyncnet.nim | 4 | ||||
-rw-r--r-- | lib/pure/nativesockets.nim | 22 | ||||
-rw-r--r-- | lib/pure/net.nim | 24 | ||||
-rw-r--r-- | lib/upcoming/asyncdispatch.nim | 4 |
6 files changed, 35 insertions, 33 deletions
diff --git a/lib/pure/asyncdispatch.nim b/lib/pure/asyncdispatch.nim index 6fb460e25..8db7eba25 100644 --- a/lib/pure/asyncdispatch.nim +++ b/lib/pure/asyncdispatch.nim @@ -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 diff --git a/lib/pure/asyncmacro.nim b/lib/pure/asyncmacro.nim index 3d004e84c..2c3a09964 100644 --- a/lib/pure/asyncmacro.nim +++ b/lib/pure/asyncmacro.nim @@ -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 diff --git a/lib/pure/asyncnet.nim b/lib/pure/asyncnet.nim index 12ae45e62..7e2c2f338 100644 --- a/lib/pure/asyncnet.nim +++ b/lib/pure/asyncnet.nim @@ -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. diff --git a/lib/pure/nativesockets.nim b/lib/pure/nativesockets.nim index 534a66449..5f10a7b4c 100644 --- a/lib/pure/nativesockets.nim +++ b/lib/pure/nativesockets.nim @@ -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 diff --git a/lib/pure/net.nim b/lib/pure/net.nim index 5e10f2291..7f6783358 100644 --- a/lib/pure/net.nim +++ b/lib/pure/net.nim @@ -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), diff --git a/lib/upcoming/asyncdispatch.nim b/lib/upcoming/asyncdispatch.nim index 17ddb1a82..31aa6c9cb 100644 --- a/lib/upcoming/asyncdispatch.nim +++ b/lib/upcoming/asyncdispatch.nim @@ -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 |