Rename rawsockets module to nativesockets

This change was done to avoid confusion with TCP/IP raw sockets. Native sockets
module represents handling native system low level socket API in general and is
not just limited anyhow to TCP/IP raw sockets.

A stub lib/deprecated/pure/rawsockets.nim module has been added as
compatibility layer for old code using rawsockets, so this change will not
break existing code.
This commit is contained in:
Adam Strzelecki 2015-09-30 13:36:43 +02:00
commit be991ed413
16 changed files with 91 additions and 65 deletions

View file

@ -244,7 +244,7 @@ Internet Protocols and Support
This module implements a high-level sockets API. It will replace the This module implements a high-level sockets API. It will replace the
``sockets`` module in the future. ``sockets`` module in the future.
* `rawsockets <rawsockets.html>`_ * `nativesockets <nativesockets.html>`_
This module implements a low-level sockets API. This module implements a low-level sockets API.
* `selectors <selectors.html>`_ * `selectors <selectors.html>`_
@ -406,6 +406,10 @@ Deprecated modules
Use the `net <net.html>`_ or the `rawsockets <rawsockets.html>`_ module Use the `net <net.html>`_ or the `rawsockets <rawsockets.html>`_ module
instead. instead.
* `rawsockets <rawsockets.html>`_
**Deprecated since version 0.11.4:**
This module has been renamed to `nativesockets <nativesockets.html>`_.
Impure libraries Impure libraries
================ ================

View file

@ -11,7 +11,7 @@ include "system/inclrtl"
import sockets, strutils, parseutils, times, os, asyncio import sockets, strutils, parseutils, times, os, asyncio
from asyncnet import nil from asyncnet import nil
from rawsockets import nil from nativesockets import nil
from asyncdispatch import PFuture from asyncdispatch import PFuture
## **Note**: This module is deprecated since version 0.11.3. ## **Note**: This module is deprecated since version 0.11.3.
## You should use the async version of this module ## You should use the async version of this module
@ -55,7 +55,7 @@ type
user*, pass*: string user*, pass*: string
address*: string address*: string
when SockType is asyncnet.AsyncSocket: when SockType is asyncnet.AsyncSocket:
port*: rawsockets.Port port*: nativesockets.Port
else: else:
port*: Port port*: Port

View file

@ -0,0 +1,14 @@
import nativesockets
export nativesockets
{.warning: "rawsockets module is deprecated, use nativesockets instead".}
template newRawSocket*(domain, sockType, protocol: cint): expr =
{.warning: "newRawSocket is deprecated, use newNativeSocket instead".}
newNativeSocket(domain, sockType, protocol)
template newRawSocket*(domain: Domain = AF_INET,
sockType: SockType = SOCK_STREAM,
protocol: Protocol = IPPROTO_TCP): expr =
{.warning: "newRawSocket is deprecated, use newNativeSocket instead".}
newNativeSocket(domain, sockType, protocol)

View file

@ -9,7 +9,7 @@
## **Warning:** Since version 0.10.2 this module is deprecated. ## **Warning:** Since version 0.10.2 this module is deprecated.
## Use the `net <net.html>`_ or the ## Use the `net <net.html>`_ or the
## `rawsockets <rawsockets.html>`_ module instead. ## `nativesockets <nativesockets.html>`_ module instead.
## ##
## This module implements portable sockets, it supports a mix of different types ## This module implements portable sockets, it supports a mix of different types
## of sockets. Sockets are buffered by default meaning that data will be ## of sockets. Sockets are buffered by default meaning that data will be

View file

@ -11,7 +11,7 @@ include "system/inclrtl"
import os, oids, tables, strutils, macros, times import os, oids, tables, strutils, macros, times
import rawsockets, net import nativesockets, net
export Port, SocketFlag export Port, SocketFlag
@ -475,7 +475,7 @@ when defined(windows) or defined(nimdoc):
addr bytesRet, nil, nil) == 0 addr bytesRet, nil, nil) == 0
proc initAll() = proc initAll() =
let dummySock = newRawSocket() let dummySock = newNativeSocket()
if not initPointer(dummySock, connectExPtr, WSAID_CONNECTEX): if not initPointer(dummySock, connectExPtr, WSAID_CONNECTEX):
raiseOSError(osLastError()) raiseOSError(osLastError())
if not initPointer(dummySock, acceptExPtr, WSAID_ACCEPTEX): if not initPointer(dummySock, acceptExPtr, WSAID_ACCEPTEX):
@ -528,7 +528,7 @@ when defined(windows) or defined(nimdoc):
RemoteSockaddr, RemoteSockaddrLength) RemoteSockaddr, RemoteSockaddrLength)
proc connect*(socket: AsyncFD, address: string, port: Port, proc connect*(socket: AsyncFD, address: string, port: Port,
domain = rawsockets.AF_INET): Future[void] = domain = nativesockets.AF_INET): Future[void] =
## Connects ``socket`` to server at ``address:port``. ## Connects ``socket`` to server at ``address:port``.
## ##
## Returns a ``Future`` which will complete when the connection succeeds ## Returns a ``Future`` which will complete when the connection succeeds
@ -827,7 +827,7 @@ when defined(windows) or defined(nimdoc):
verifyPresence(socket) verifyPresence(socket)
var retFuture = newFuture[tuple[address: string, client: AsyncFD]]("acceptAddr") var retFuture = newFuture[tuple[address: string, client: AsyncFD]]("acceptAddr")
var clientSock = newRawSocket() var clientSock = newNativeSocket()
if clientSock == osInvalidSocket: raiseOSError(osLastError()) if clientSock == osInvalidSocket: raiseOSError(osLastError())
const lpOutputLen = 1024 const lpOutputLen = 1024
@ -900,17 +900,17 @@ when defined(windows) or defined(nimdoc):
return retFuture return retFuture
proc newAsyncRawSocket*(domain, sockType, protocol: cint): AsyncFD = proc newAsyncNativeSocket*(domain, sockType, protocol: cint): AsyncFD =
## Creates a new socket and registers it with the dispatcher implicitly. ## Creates a new socket and registers it with the dispatcher implicitly.
result = newRawSocket(domain, sockType, protocol).AsyncFD result = newNativeSocket(domain, sockType, protocol).AsyncFD
result.SocketHandle.setBlocking(false) result.SocketHandle.setBlocking(false)
register(result) register(result)
proc newAsyncRawSocket*(domain: Domain = rawsockets.AF_INET, proc newAsyncNativeSocket*(domain: Domain = nativesockets.AF_INET,
sockType: SockType = SOCK_STREAM, sockType: SockType = SOCK_STREAM,
protocol: Protocol = IPPROTO_TCP): AsyncFD = protocol: Protocol = IPPROTO_TCP): AsyncFD =
## Creates a new socket and registers it with the dispatcher implicitly. ## Creates a new socket and registers it with the dispatcher implicitly.
result = newRawSocket(domain, sockType, protocol).AsyncFD result = newNativeSocket(domain, sockType, protocol).AsyncFD
result.SocketHandle.setBlocking(false) result.SocketHandle.setBlocking(false)
register(result) register(result)
@ -973,18 +973,18 @@ else:
var data = PData(fd: fd, readCBs: @[], writeCBs: @[]) var data = PData(fd: fd, readCBs: @[], writeCBs: @[])
p.selector.register(fd.SocketHandle, {}, data.RootRef) p.selector.register(fd.SocketHandle, {}, data.RootRef)
proc newAsyncRawSocket*(domain: cint, sockType: cint, proc newAsyncNativeSocket*(domain: cint, sockType: cint,
protocol: cint): AsyncFD = protocol: cint): AsyncFD =
result = newRawSocket(domain, sockType, protocol).AsyncFD result = newNativeSocket(domain, sockType, protocol).AsyncFD
result.SocketHandle.setBlocking(false) result.SocketHandle.setBlocking(false)
when defined(macosx): when defined(macosx):
result.SocketHandle.setSockOptInt(SOL_SOCKET, SO_NOSIGPIPE, 1) result.SocketHandle.setSockOptInt(SOL_SOCKET, SO_NOSIGPIPE, 1)
register(result) register(result)
proc newAsyncRawSocket*(domain: Domain = AF_INET, proc newAsyncNativeSocket*(domain: Domain = AF_INET,
sockType: SockType = SOCK_STREAM, sockType: SockType = SOCK_STREAM,
protocol: Protocol = IPPROTO_TCP): AsyncFD = protocol: Protocol = IPPROTO_TCP): AsyncFD =
result = newRawSocket(domain, sockType, protocol).AsyncFD result = newNativeSocket(domain, sockType, protocol).AsyncFD
result.SocketHandle.setBlocking(false) result.SocketHandle.setBlocking(false)
when defined(macosx): when defined(macosx):
result.SocketHandle.setSockOptInt(SOL_SOCKET, SO_NOSIGPIPE, 1) result.SocketHandle.setSockOptInt(SOL_SOCKET, SO_NOSIGPIPE, 1)

View file

@ -56,7 +56,7 @@
## ##
import asyncdispatch import asyncdispatch
import rawsockets import nativesockets
import net import net
import os import os
@ -112,8 +112,8 @@ proc newAsyncSocket*(domain: Domain = AF_INET, sockType: SockType = SOCK_STREAM,
## ##
## This procedure will also create a brand new file descriptor for ## This procedure will also create a brand new file descriptor for
## this socket. ## this socket.
result = newAsyncSocket(newAsyncRawSocket(domain, sockType, protocol), domain, result = newAsyncSocket(newAsyncNativeSocket(domain, sockType, protocol),
sockType, protocol, buffered) domain, sockType, protocol, buffered)
proc newAsyncSocket*(domain, sockType, protocol: cint, proc newAsyncSocket*(domain, sockType, protocol: cint,
buffered = true): AsyncSocket = buffered = true): AsyncSocket =
@ -121,8 +121,9 @@ proc newAsyncSocket*(domain, sockType, protocol: cint,
## ##
## This procedure will also create a brand new file descriptor for ## This procedure will also create a brand new file descriptor for
## this socket. ## this socket.
result = newAsyncSocket(newAsyncRawSocket(domain, sockType, protocol), result = newAsyncSocket(newAsyncNativeSocket(domain, sockType, protocol),
Domain(domain), SockType(sockType), Protocol(protocol), buffered) Domain(domain), SockType(sockType),
Protocol(protocol), buffered)
when defined(ssl): when defined(ssl):
proc getSslError(handle: SslPtr, err: cint): cint = proc getSslError(handle: SslPtr, err: cint): cint =

View file

@ -81,7 +81,7 @@
import net, strutils, uri, parseutils, strtabs, base64, os, mimetypes, math import net, strutils, uri, parseutils, strtabs, base64, os, mimetypes, math
import asyncnet, asyncdispatch import asyncnet, asyncdispatch
import rawsockets import nativesockets
type type
Response* = tuple[ Response* = tuple[
@ -764,10 +764,10 @@ proc newConnection(client: AsyncHttpClient, url: Uri) {.async.} =
let port = let port =
if url.port == "": if url.port == "":
if url.scheme.toLower() == "https": if url.scheme.toLower() == "https":
rawsockets.Port(443) nativesockets.Port(443)
else: else:
rawsockets.Port(80) nativesockets.Port(80)
else: rawsockets.Port(url.port.parseInt) else: nativesockets.Port(url.port.parseInt)
if url.scheme.toLower() == "https": if url.scheme.toLower() == "https":
when defined(ssl): when defined(ssl):

View file

@ -93,8 +93,8 @@ when useWinVersion:
IOC_IN* = int(-2147483648) IOC_IN* = int(-2147483648)
FIONBIO* = IOC_IN.int32 or ((sizeof(int32) and IOCPARM_MASK) shl 16) or FIONBIO* = IOC_IN.int32 or ((sizeof(int32) and IOCPARM_MASK) shl 16) or
(102 shl 8) or 126 (102 shl 8) or 126
rawAfInet = winlean.AF_INET nativeAfInet = winlean.AF_INET
rawAfInet6 = winlean.AF_INET6 nativeAfInet6 = winlean.AF_INET6
proc ioctlsocket*(s: SocketHandle, cmd: clong, proc ioctlsocket*(s: SocketHandle, cmd: clong,
argptr: ptr clong): cint {. argptr: ptr clong): cint {.
@ -102,8 +102,8 @@ when useWinVersion:
else: else:
let let
osInvalidSocket* = posix.INVALID_SOCKET osInvalidSocket* = posix.INVALID_SOCKET
rawAfInet = posix.AF_INET nativeAfInet = posix.AF_INET
rawAfInet6 = posix.AF_INET6 nativeAfInet6 = posix.AF_INET6
proc `==`*(a, b: Port): bool {.borrow.} proc `==`*(a, b: Port): bool {.borrow.}
## ``==`` for ports. ## ``==`` for ports.
@ -157,12 +157,14 @@ else:
result = cint(ord(p)) result = cint(ord(p))
proc newRawSocket*(domain: Domain = AF_INET, sockType: SockType = SOCK_STREAM, proc newNativeSocket*(domain: Domain = AF_INET,
protocol: Protocol = IPPROTO_TCP): SocketHandle = sockType: SockType = SOCK_STREAM,
protocol: Protocol = IPPROTO_TCP): SocketHandle =
## Creates a new socket; returns `InvalidSocket` if an error occurs. ## Creates a new socket; returns `InvalidSocket` if an error occurs.
socket(toInt(domain), toInt(sockType), toInt(protocol)) socket(toInt(domain), toInt(sockType), toInt(protocol))
proc newRawSocket*(domain: cint, sockType: cint, protocol: cint): SocketHandle = proc newNativeSocket*(domain: cint, sockType: cint,
protocol: cint): SocketHandle =
## Creates a new socket; returns `InvalidSocket` if an error occurs. ## Creates a new socket; returns `InvalidSocket` if an error occurs.
## ##
## Use this overload if one of the enums specified above does ## Use this overload if one of the enums specified above does
@ -231,17 +233,17 @@ proc ntohs*(x: int16): int16 =
when cpuEndian == bigEndian: result = x when cpuEndian == bigEndian: result = x
else: result = (x shr 8'i16) or (x shl 8'i16) else: result = (x shr 8'i16) or (x shl 8'i16)
proc htonl*(x: int32): int32 = template htonl*(x: int32): expr =
## 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.
result = rawsockets.ntohl(x) nativesockets.ntohl(x)
proc htons*(x: int16): int16 = template htons*(x: int16): expr =
## Converts 16-bit positive integers from host to network byte order. ## Converts 16-bit positive 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.
result = rawsockets.ntohs(x) nativesockets.ntohs(x)
proc getServByName*(name, proto: string): Servent {.tags: [ReadIOEffect].} = proc getServByName*(name, proto: string): Servent {.tags: [ReadIOEffect].} =
## Searches the database from the beginning and finds the first entry for ## Searches the database from the beginning and finds the first entry for
@ -282,7 +284,7 @@ proc getHostByAddr*(ip: string): Hostent {.tags: [ReadIOEffect].} =
when useWinVersion: when useWinVersion:
var s = winlean.gethostbyaddr(addr(myaddr), sizeof(myaddr).cuint, var s = winlean.gethostbyaddr(addr(myaddr), sizeof(myaddr).cuint,
cint(rawsockets.AF_INET)) cint(AF_INET))
if s == nil: raiseOSError(osLastError()) if s == nil: raiseOSError(osLastError())
else: else:
var s = posix.gethostbyaddr(addr(myaddr), sizeof(myaddr).Socklen, var s = posix.gethostbyaddr(addr(myaddr), sizeof(myaddr).Socklen,
@ -332,9 +334,9 @@ proc getSockDomain*(socket: SocketHandle): Domain =
if getsockname(socket, cast[ptr SockAddr](addr(name)), if getsockname(socket, cast[ptr SockAddr](addr(name)),
addr(namelen)) == -1'i32: addr(namelen)) == -1'i32:
raiseOSError(osLastError()) raiseOSError(osLastError())
if name.sa_family == rawAfInet: if name.sa_family == nativeAfInet:
result = AF_INET result = AF_INET
elif name.sa_family == rawAfInet6: elif name.sa_family == nativeAfInet6:
result = AF_INET6 result = AF_INET6
else: else:
raiseOSError(osLastError(), "unknown socket family in getSockFamily") raiseOSError(osLastError(), "unknown socket family in getSockFamily")
@ -342,9 +344,9 @@ proc getSockDomain*(socket: SocketHandle): Domain =
proc getAddrString*(sockAddr: ptr SockAddr): string = proc getAddrString*(sockAddr: ptr SockAddr): string =
## return the string representation of address within sockAddr ## return the string representation of address within sockAddr
if sockAddr.sa_family == rawAfInet: if sockAddr.sa_family == nativeAfInet:
result = $inet_ntoa(cast[ptr Sockaddr_in](sockAddr).sin_addr) result = $inet_ntoa(cast[ptr Sockaddr_in](sockAddr).sin_addr)
elif sockAddr.sa_family == rawAfInet6: elif sockAddr.sa_family == nativeAfInet6:
when not useWinVersion: when not useWinVersion:
# TODO: Windows # TODO: Windows
var v6addr = cast[ptr Sockaddr_in6](sockAddr).sin6_addr var v6addr = cast[ptr Sockaddr_in6](sockAddr).sin6_addr
@ -371,7 +373,7 @@ proc getSockName*(socket: SocketHandle): Port =
if getsockname(socket, cast[ptr SockAddr](addr(name)), if getsockname(socket, cast[ptr SockAddr](addr(name)),
addr(namelen)) == -1'i32: addr(namelen)) == -1'i32:
raiseOSError(osLastError()) raiseOSError(osLastError())
result = Port(rawsockets.ntohs(name.sin_port)) result = Port(nativesockets.ntohs(name.sin_port))
proc getLocalAddr*(socket: SocketHandle, domain: Domain): (string, Port) = proc getLocalAddr*(socket: SocketHandle, domain: Domain): (string, Port) =
## returns the socket's local address and port number. ## returns the socket's local address and port number.
@ -388,7 +390,8 @@ proc getLocalAddr*(socket: SocketHandle, domain: Domain): (string, Port) =
if getsockname(socket, cast[ptr SockAddr](addr(name)), if getsockname(socket, cast[ptr SockAddr](addr(name)),
addr(namelen)) == -1'i32: addr(namelen)) == -1'i32:
raiseOSError(osLastError()) raiseOSError(osLastError())
result = ($inet_ntoa(name.sin_addr), Port(rawsockets.ntohs(name.sin_port))) result = ($inet_ntoa(name.sin_addr),
Port(nativesockets.ntohs(name.sin_port)))
of AF_INET6: of AF_INET6:
var name: Sockaddr_in6 var name: Sockaddr_in6
when useWinVersion: when useWinVersion:
@ -404,7 +407,7 @@ proc getLocalAddr*(socket: SocketHandle, domain: Domain): (string, Port) =
if inet_ntop(name.sin6_family.cint, if inet_ntop(name.sin6_family.cint,
addr name, buf.cstring, sizeof(buf).int32).isNil: addr name, buf.cstring, sizeof(buf).int32).isNil:
raiseOSError(osLastError()) raiseOSError(osLastError())
result = ($buf, Port(rawsockets.ntohs(name.sin6_port))) result = ($buf, Port(nativesockets.ntohs(name.sin6_port)))
else: else:
raiseOSError(OSErrorCode(-1), "invalid socket family in getLocalAddr") raiseOSError(OSErrorCode(-1), "invalid socket family in getLocalAddr")
@ -423,7 +426,8 @@ proc getPeerAddr*(socket: SocketHandle, domain: Domain): (string, Port) =
if getpeername(socket, cast[ptr SockAddr](addr(name)), if getpeername(socket, cast[ptr SockAddr](addr(name)),
addr(namelen)) == -1'i32: addr(namelen)) == -1'i32:
raiseOSError(osLastError()) raiseOSError(osLastError())
result = ($inet_ntoa(name.sin_addr), Port(rawsockets.ntohs(name.sin_port))) result = ($inet_ntoa(name.sin_addr),
Port(nativesockets.ntohs(name.sin_port)))
of AF_INET6: of AF_INET6:
var name: Sockaddr_in6 var name: Sockaddr_in6
when useWinVersion: when useWinVersion:
@ -439,7 +443,7 @@ proc getPeerAddr*(socket: SocketHandle, domain: Domain): (string, Port) =
if inet_ntop(name.sin6_family.cint, if inet_ntop(name.sin6_family.cint,
addr name, buf.cstring, sizeof(buf).int32).isNil: addr name, buf.cstring, sizeof(buf).int32).isNil:
raiseOSError(osLastError()) raiseOSError(osLastError())
result = ($buf, Port(rawsockets.ntohs(name.sin6_port))) result = ($buf, Port(nativesockets.ntohs(name.sin6_port)))
else: else:
raiseOSError(OSErrorCode(-1), "invalid socket family in getLocalAddr") raiseOSError(OSErrorCode(-1), "invalid socket family in getLocalAddr")

View file

@ -10,7 +10,7 @@
## This module implements a high-level cross-platform sockets interface. ## This module implements a high-level cross-platform sockets interface.
{.deadCodeElim: on.} {.deadCodeElim: on.}
import rawsockets, os, strutils, unsigned, parseutils, times import nativesockets, os, strutils, unsigned, parseutils, times
export Port, `$`, `==` export Port, `$`, `==`
const useWinVersion = defined(Windows) or defined(nimdoc) const useWinVersion = defined(Windows) or defined(nimdoc)
@ -145,7 +145,7 @@ proc newSocket*(domain, sockType, protocol: cint, buffered = true): Socket =
## Creates a new socket. ## Creates a new socket.
## ##
## If an error occurs EOS will be raised. ## If an error occurs EOS will be raised.
let fd = newRawSocket(domain, sockType, protocol) let fd = newNativeSocket(domain, sockType, protocol)
if fd == osInvalidSocket: if fd == osInvalidSocket:
raiseOSError(osLastError()) raiseOSError(osLastError())
result = newSocket(fd, domain.Domain, sockType.SockType, protocol.Protocol, result = newSocket(fd, domain.Domain, sockType.SockType, protocol.Protocol,
@ -156,7 +156,7 @@ proc newSocket*(domain: Domain = AF_INET, sockType: SockType = SOCK_STREAM,
## Creates a new socket. ## Creates a new socket.
## ##
## If an error occurs EOS will be raised. ## If an error occurs EOS will be raised.
let fd = newRawSocket(domain, sockType, protocol) let fd = newNativeSocket(domain, sockType, protocol)
if fd == osInvalidSocket: if fd == osInvalidSocket:
raiseOSError(osLastError()) raiseOSError(osLastError())
result = newSocket(fd, domain, sockType, protocol, buffered) result = newSocket(fd, domain, sockType, protocol, buffered)
@ -354,7 +354,7 @@ proc listen*(socket: Socket, backlog = SOMAXCONN) {.tags: [ReadIOEffect].} =
## queue of pending connections. ## queue of pending connections.
## ##
## Raises an EOS error upon failure. ## Raises an EOS error upon failure.
if rawsockets.listen(socket.fd, backlog) < 0'i32: if nativesockets.listen(socket.fd, backlog) < 0'i32:
raiseOSError(osLastError()) raiseOSError(osLastError())
proc bindAddr*(socket: Socket, port = Port(0), address = "") {. proc bindAddr*(socket: Socket, port = Port(0), address = "") {.

View file

@ -2,7 +2,7 @@ discard """
file: "tasyncawait.nim" file: "tasyncawait.nim"
output: "5000" output: "5000"
""" """
import asyncdispatch, rawsockets, net, strutils, os import asyncdispatch, nativesockets, net, strutils, os
var msgCount = 0 var msgCount = 0
@ -18,7 +18,7 @@ proc sendMessages(client: TAsyncFD) {.async.} =
proc launchSwarm(port: TPort) {.async.} = proc launchSwarm(port: TPort) {.async.} =
for i in 0 .. <swarmSize: for i in 0 .. <swarmSize:
var sock = newAsyncRawSocket() var sock = newAsyncNativeSocket()
await connect(sock, "localhost", port) await connect(sock, "localhost", port)
await sendMessages(sock) await sendMessages(sock)
@ -38,7 +38,7 @@ proc readMessages(client: TAsyncFD) {.async.} =
doAssert false doAssert false
proc createServer(port: TPort) {.async.} = proc createServer(port: TPort) {.async.} =
var server = newAsyncRawSocket() var server = newAsyncNativeSocket()
block: block:
var name: Sockaddr_in var name: Sockaddr_in
when defined(windows): when defined(windows):

View file

@ -19,7 +19,7 @@ when defined(windows) or defined(nimdoc):
quit("Error: unhandled exception: Connection refused") quit("Error: unhandled exception: Connection refused")
else: else:
proc testAsyncConnect() {.async.} = proc testAsyncConnect() {.async.} =
var s = newAsyncRawSocket() var s = newAsyncNativeSocket()
await s.connect(testHost, testPort) await s.connect(testHost, testPort)

View file

@ -7,7 +7,7 @@ discard """
import import
asyncdispatch, asyncdispatch,
asyncnet, asyncnet,
rawsockets, nativesockets,
os os
@ -21,7 +21,7 @@ when defined(windows) or defined(nimdoc):
quit("Error: unhandled exception: Connection reset by peer") quit("Error: unhandled exception: Connection reset by peer")
else: else:
proc createListenSocket(host: string, port: Port): TAsyncFD = proc createListenSocket(host: string, port: Port): TAsyncFD =
result = newAsyncRawSocket() result = newAsyncNativeSocket()
SocketHandle(result).setSockOptInt(SOL_SOCKET, SO_REUSEADDR, 1) SocketHandle(result).setSockOptInt(SOL_SOCKET, SO_REUSEADDR, 1)

View file

@ -2,4 +2,4 @@ discard """
cmd: "nim cpp $file" cmd: "nim cpp $file"
""" """
import rawsockets import nativesockets

View file

@ -1,6 +1,6 @@
import rawsockets, asyncdispatch, macros import nativesockets, asyncdispatch, macros
var p = newDispatcher() var p = newDispatcher()
var sock = newAsyncRawSocket() var sock = newAsyncNativeSocket()
proc convertReturns(node, retFutureSym: NimNode): NimNode {.compileTime.} = proc convertReturns(node, retFutureSym: NimNode): NimNode {.compileTime.} =
case node.kind case node.kind

View file

@ -5,7 +5,7 @@ discard """
import mexporta import mexporta
# bug #1029: # bug #1029:
from rawsockets import accept from nativesockets import accept
# B.TMyObject has been imported implicitly here: # B.TMyObject has been imported implicitly here:
var x: TMyObject var x: TMyObject

View file

@ -9,6 +9,9 @@ News
Changes affecting backwards compatibility Changes affecting backwards compatibility
----------------------------------------- -----------------------------------------
- The ``rawsockets`` module has been renamed to ``nativesockets`` to avoid
confusion with TCP/IP raw sockets, so ``newNativeSocket`` should be used
instead of ``newRawSocket``.
- The ``miliseconds`` property of ``times.TimeInterval`` is now ``milliseconds``. - The ``miliseconds`` property of ``times.TimeInterval`` is now ``milliseconds``.
Code accessing that property is deprecated and code using ``miliseconds`` Code accessing that property is deprecated and code using ``miliseconds``
during object initialization or as a named parameter of ``initInterval()`` during object initialization or as a named parameter of ``initInterval()``