mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-09 14:32:53 +00:00
committed by
Andreas Rumpf
parent
d24b6667c6
commit
1a2351f95f
@@ -235,6 +235,10 @@ styledEcho "Red on Green.", resetStyle
|
||||
- ``\n`` is now only the single line feed character like in most
|
||||
other programming languages. The new platform specific newline escape sequence is
|
||||
written as ``\p``. This change only affects the Windows platform.
|
||||
- ``newAsyncNativeSocket`` is now named ``createAsyncNativeSocket``
|
||||
and it no longer raises an OS error but returns an ``osInvalidSocket`` when
|
||||
creation fails.
|
||||
- ``newNativeSocket`` is now named ``createNativeSocket``.
|
||||
- Type inference for generic type parameters involving numeric types is now symetric. See
|
||||
[Generic type inference for numeric types](https://nim-lang.org/docs/manual.html#generics-generic-type-inference-fornumeric-types)
|
||||
for more information.
|
||||
|
||||
@@ -1648,4 +1648,8 @@ proc waitFor*[T](fut: Future[T]): T =
|
||||
|
||||
fut.read
|
||||
|
||||
{.deprecated: [setEvent: trigger].}
|
||||
proc setEvent*(ev: AsyncEvent) {.deprecated.} =
|
||||
## Set event ``ev`` to signaled state.
|
||||
##
|
||||
## **Deprecated since v0.18.0:** Use ``trigger`` instead.
|
||||
ev.trigger()
|
||||
@@ -163,8 +163,10 @@ proc newAsyncSocket*(domain: Domain = AF_INET, sockType: SockType = SOCK_STREAM,
|
||||
##
|
||||
## This procedure will also create a brand new file descriptor for
|
||||
## this socket.
|
||||
result = newAsyncSocket(newAsyncNativeSocket(domain, sockType, protocol),
|
||||
domain, sockType, protocol, buffered)
|
||||
let fd = createAsyncNativeSocket(domain, sockType, protocol)
|
||||
if fd.SocketHandle == osInvalidSocket:
|
||||
raiseOSError(osLastError())
|
||||
result = newAsyncSocket(fd, domain, sockType, protocol, buffered)
|
||||
|
||||
proc newAsyncSocket*(domain, sockType, protocol: cint,
|
||||
buffered = true): AsyncSocket =
|
||||
@@ -172,8 +174,10 @@ proc newAsyncSocket*(domain, sockType, protocol: cint,
|
||||
##
|
||||
## This procedure will also create a brand new file descriptor for
|
||||
## this socket.
|
||||
result = newAsyncSocket(newAsyncNativeSocket(domain, sockType, protocol),
|
||||
Domain(domain), SockType(sockType),
|
||||
let fd = createAsyncNativeSocket(domain, sockType, protocol)
|
||||
if fd.SocketHandle == osInvalidSocket:
|
||||
raiseOSError(osLastError())
|
||||
result = newAsyncSocket(fd, Domain(domain), SockType(sockType),
|
||||
Protocol(protocol), buffered)
|
||||
|
||||
when defineSsl:
|
||||
|
||||
@@ -1,21 +1,31 @@
|
||||
template newAsyncNativeSocketImpl(domain, sockType, protocol) =
|
||||
template createAsyncNativeSocketImpl(domain, sockType, protocol) =
|
||||
let handle = newNativeSocket(domain, sockType, protocol)
|
||||
if handle == osInvalidSocket:
|
||||
raiseOSError(osLastError())
|
||||
return osInvalidSocket.AsyncFD
|
||||
handle.setBlocking(false)
|
||||
when defined(macosx) and not defined(nimdoc):
|
||||
handle.setSockOptInt(SOL_SOCKET, SO_NOSIGPIPE, 1)
|
||||
result = handle.AsyncFD
|
||||
register(result)
|
||||
|
||||
proc newAsyncNativeSocket*(domain: cint, sockType: cint,
|
||||
proc createAsyncNativeSocket*(domain: cint, sockType: cint,
|
||||
protocol: cint): AsyncFD =
|
||||
newAsyncNativeSocketImpl(domain, sockType, protocol)
|
||||
createAsyncNativeSocketImpl(domain, sockType, protocol)
|
||||
|
||||
proc createAsyncNativeSocket*(domain: Domain = Domain.AF_INET,
|
||||
sockType: SockType = SOCK_STREAM,
|
||||
protocol: Protocol = IPPROTO_TCP): AsyncFD =
|
||||
createAsyncNativeSocketImpl(domain, sockType, protocol)
|
||||
|
||||
proc newAsyncNativeSocket*(domain: cint, sockType: cint,
|
||||
protocol: cint): AsyncFD {.deprecated.} =
|
||||
createAsyncNativeSocketImpl(domain, sockType, protocol)
|
||||
|
||||
proc newAsyncNativeSocket*(domain: Domain = Domain.AF_INET,
|
||||
sockType: SockType = SOCK_STREAM,
|
||||
protocol: Protocol = IPPROTO_TCP): AsyncFD =
|
||||
newAsyncNativeSocketImpl(domain, sockType, protocol)
|
||||
protocol: Protocol = IPPROTO_TCP): AsyncFD
|
||||
{.deprecated.} =
|
||||
createAsyncNativeSocketImpl(domain, sockType, protocol)
|
||||
|
||||
when defined(windows) or defined(nimdoc):
|
||||
proc bindToDomain(handle: SocketHandle, domain: Domain) =
|
||||
|
||||
@@ -184,13 +184,13 @@ proc toSockType*(protocol: Protocol): SockType =
|
||||
of IPPROTO_IP, IPPROTO_IPV6, IPPROTO_RAW, IPPROTO_ICMP:
|
||||
SOCK_RAW
|
||||
|
||||
proc newNativeSocket*(domain: Domain = AF_INET,
|
||||
proc createNativeSocket*(domain: Domain = AF_INET,
|
||||
sockType: SockType = SOCK_STREAM,
|
||||
protocol: Protocol = IPPROTO_TCP): SocketHandle =
|
||||
## Creates a new socket; returns `osInvalidSocket` if an error occurs.
|
||||
socket(toInt(domain), toInt(sockType), toInt(protocol))
|
||||
|
||||
proc newNativeSocket*(domain: cint, sockType: cint,
|
||||
proc createNativeSocket*(domain: cint, sockType: cint,
|
||||
protocol: cint): SocketHandle =
|
||||
## Creates a new socket; returns `osInvalidSocket` if an error occurs.
|
||||
##
|
||||
@@ -198,6 +198,26 @@ proc newNativeSocket*(domain: cint, sockType: cint,
|
||||
## not contain what you need.
|
||||
socket(domain, sockType, protocol)
|
||||
|
||||
proc newNativeSocket*(domain: Domain = AF_INET,
|
||||
sockType: SockType = SOCK_STREAM,
|
||||
protocol: Protocol = IPPROTO_TCP): SocketHandle
|
||||
{.deprecated.} =
|
||||
## Creates a new socket; returns `osInvalidSocket` if an error occurs.
|
||||
##
|
||||
## **Deprecated since v0.18.0:** Use ``createNativeSocket`` instead.
|
||||
createNativeSocket(domain, sockType, protocol)
|
||||
|
||||
proc newNativeSocket*(domain: cint, sockType: cint,
|
||||
protocol: cint): SocketHandle
|
||||
{.deprecated.} =
|
||||
## Creates a new socket; returns `osInvalidSocket` if an error occurs.
|
||||
##
|
||||
## Use this overload if one of the enums specified above does
|
||||
## not contain what you need.
|
||||
##
|
||||
## **Deprecated since v0.18.0:** Use ``createNativeSocket`` instead.
|
||||
createNativeSocket(domain, sockType, protocol)
|
||||
|
||||
proc close*(socket: SocketHandle) =
|
||||
## closes a socket.
|
||||
when useWinVersion:
|
||||
|
||||
@@ -221,7 +221,7 @@ proc newSocket*(domain, sockType, protocol: cint, buffered = true): Socket =
|
||||
## Creates a new socket.
|
||||
##
|
||||
## If an error occurs EOS will be raised.
|
||||
let fd = newNativeSocket(domain, sockType, protocol)
|
||||
let fd = createNativeSocket(domain, sockType, protocol)
|
||||
if fd == osInvalidSocket:
|
||||
raiseOSError(osLastError())
|
||||
result = newSocket(fd, domain.Domain, sockType.SockType, protocol.Protocol,
|
||||
@@ -232,7 +232,7 @@ proc newSocket*(domain: Domain = AF_INET, sockType: SockType = SOCK_STREAM,
|
||||
## Creates a new socket.
|
||||
##
|
||||
## If an error occurs EOS will be raised.
|
||||
let fd = newNativeSocket(domain, sockType, protocol)
|
||||
let fd = createNativeSocket(domain, sockType, protocol)
|
||||
if fd == osInvalidSocket:
|
||||
raiseOSError(osLastError())
|
||||
result = newSocket(fd, domain, sockType, protocol, buffered)
|
||||
@@ -1544,7 +1544,7 @@ proc dial*(address: string, port: Port,
|
||||
domain = domainOpt.unsafeGet()
|
||||
lastFd = fdPerDomain[ord(domain)]
|
||||
if lastFd == osInvalidSocket:
|
||||
lastFd = newNativeSocket(domain, sockType, protocol)
|
||||
lastFd = createNativeSocket(domain, sockType, protocol)
|
||||
if lastFd == osInvalidSocket:
|
||||
# we always raise if socket creation failed, because it means a
|
||||
# network system problem (e.g. not enough FDs), and not an unreachable
|
||||
|
||||
@@ -315,6 +315,21 @@ else:
|
||||
else:
|
||||
include ioselects/ioselectors_poll
|
||||
|
||||
{.deprecated: [setEvent: trigger].}
|
||||
{.deprecated: [register: registerHandle].}
|
||||
{.deprecated: [update: updateHandle].}
|
||||
proc register*[T](s: Selector[T], fd: int | SocketHandle,
|
||||
events: set[Event], data: T) {.deprecated.} =
|
||||
## **Deprecated since v0.18.0:** Use ``registerHandle`` instead.
|
||||
s.registerHandle(fd, events, data)
|
||||
|
||||
proc setEvent*(ev: SelectEvent) {.deprecated.} =
|
||||
## Trigger event ``ev``.
|
||||
##
|
||||
## **Deprecated since v0.18.0:** Use ``trigger`` instead.
|
||||
ev.trigger()
|
||||
|
||||
proc update*[T](s: Selector[T], fd: int | SocketHandle,
|
||||
events: set[Event]) {.deprecated.} =
|
||||
## Update file/socket descriptor ``fd``, registered in selector
|
||||
## ``s`` with new events set ``event``.
|
||||
##
|
||||
## **Deprecated since v0.18.0:** Use ``updateHandle`` instead.
|
||||
s.updateHandle()
|
||||
|
||||
Reference in New Issue
Block a user