Merge branch 'bigbreak' of https://github.com/Araq/Nimrod into bigbreak
This commit is contained in:
commit
d615a29309
4 changed files with 33 additions and 1 deletions
|
|
@ -766,6 +766,12 @@ when defined(windows) or defined(nimdoc):
|
||||||
|
|
||||||
return retFuture
|
return retFuture
|
||||||
|
|
||||||
|
proc newAsyncRawSocket*(domain, typ, protocol: cint): TAsyncFD =
|
||||||
|
## Creates a new socket and registers it with the dispatcher implicitly.
|
||||||
|
result = newRawSocket(domain, typ, protocol).TAsyncFD
|
||||||
|
result.SocketHandle.setBlocking(false)
|
||||||
|
register(result)
|
||||||
|
|
||||||
proc newAsyncRawSocket*(domain: Domain = AF_INET,
|
proc newAsyncRawSocket*(domain: Domain = AF_INET,
|
||||||
typ: SockType = SOCK_STREAM,
|
typ: SockType = SOCK_STREAM,
|
||||||
protocol: Protocol = IPPROTO_TCP): TAsyncFD =
|
protocol: Protocol = IPPROTO_TCP): TAsyncFD =
|
||||||
|
|
@ -832,6 +838,11 @@ else:
|
||||||
var data = PData(sock: sock, readCBs: @[], writeCBs: @[])
|
var data = PData(sock: sock, readCBs: @[], writeCBs: @[])
|
||||||
p.selector.register(sock.SocketHandle, {}, data.PObject)
|
p.selector.register(sock.SocketHandle, {}, data.PObject)
|
||||||
|
|
||||||
|
proc newAsyncRawSocket*(domain: cint, typ: cint, protocol: cint): TAsyncFD =
|
||||||
|
result = newRawSocket(domain, typ, protocol).TAsyncFD
|
||||||
|
result.SocketHandle.setBlocking(false)
|
||||||
|
register(result)
|
||||||
|
|
||||||
proc newAsyncRawSocket*(domain: TDomain = AF_INET,
|
proc newAsyncRawSocket*(domain: TDomain = AF_INET,
|
||||||
typ: TType = SOCK_STREAM,
|
typ: TType = SOCK_STREAM,
|
||||||
protocol: TProtocol = IPPROTO_TCP): TAsyncFD =
|
protocol: TProtocol = IPPROTO_TCP): TAsyncFD =
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
##
|
##
|
||||||
## import asyncnet, asyncdispatch
|
## import asyncnet, asyncdispatch
|
||||||
##
|
##
|
||||||
## var clients: seq[AsyncSocket] = @[]
|
## var clients {.threadvar.}: seq[AsyncSocket]
|
||||||
##
|
##
|
||||||
## proc processClient(client: AsyncSocket) {.async.} =
|
## proc processClient(client: AsyncSocket) {.async.} =
|
||||||
## while true:
|
## while true:
|
||||||
|
|
@ -40,6 +40,7 @@
|
||||||
## await c.send(line & "\c\L")
|
## await c.send(line & "\c\L")
|
||||||
##
|
##
|
||||||
## proc serve() {.async.} =
|
## proc serve() {.async.} =
|
||||||
|
## clients = @[]
|
||||||
## var server = newAsyncSocket()
|
## var server = newAsyncSocket()
|
||||||
## server.bindAddr(Port(12345))
|
## server.bindAddr(Port(12345))
|
||||||
## server.listen()
|
## server.listen()
|
||||||
|
|
@ -101,6 +102,10 @@ proc newAsyncSocket*(domain: TDomain = AF_INET, typ: TType = SOCK_STREAM,
|
||||||
## Creates a new asynchronous socket.
|
## Creates a new asynchronous socket.
|
||||||
result = newSocket(newAsyncRawSocket(domain, typ, protocol), buffered)
|
result = newSocket(newAsyncRawSocket(domain, typ, protocol), buffered)
|
||||||
|
|
||||||
|
proc newAsyncSocket*(domain, typ, protocol: cint, buffered = true): PAsyncSocket =
|
||||||
|
## Creates a new asynchronous socket.
|
||||||
|
result = newSocket(newAsyncRawSocket(domain, typ, protocol), buffered)
|
||||||
|
|
||||||
when defined(ssl):
|
when defined(ssl):
|
||||||
proc getSslError(handle: SslPtr, err: cint): cint =
|
proc getSslError(handle: SslPtr, err: cint): cint =
|
||||||
assert err < 0
|
assert err < 0
|
||||||
|
|
|
||||||
|
|
@ -108,6 +108,15 @@ proc createSocket(fd: SocketHandle, isBuff: bool): Socket =
|
||||||
if isBuff:
|
if isBuff:
|
||||||
result.currPos = 0
|
result.currPos = 0
|
||||||
|
|
||||||
|
proc newSocket*(domain, typ, protocol: cint, buffered = true): Socket =
|
||||||
|
## Creates a new socket.
|
||||||
|
##
|
||||||
|
## If an error occurs EOS will be raised.
|
||||||
|
let fd = newRawSocket(domain, typ, protocol)
|
||||||
|
if fd == osInvalidSocket:
|
||||||
|
raiseOSError(osLastError())
|
||||||
|
result = createSocket(fd, buffered)
|
||||||
|
|
||||||
proc newSocket*(domain: Domain = AF_INET, typ: SockType = SOCK_STREAM,
|
proc newSocket*(domain: Domain = AF_INET, typ: SockType = SOCK_STREAM,
|
||||||
protocol: Protocol = IPPROTO_TCP, buffered = true): Socket =
|
protocol: Protocol = IPPROTO_TCP, buffered = true): Socket =
|
||||||
## Creates a new socket.
|
## Creates a new socket.
|
||||||
|
|
|
||||||
|
|
@ -153,6 +153,13 @@ proc newRawSocket*(domain: Domain = AF_INET, typ: SockType = SOCK_STREAM,
|
||||||
## Creates a new socket; returns `InvalidSocket` if an error occurs.
|
## Creates a new socket; returns `InvalidSocket` if an error occurs.
|
||||||
socket(toInt(domain), toInt(typ), toInt(protocol))
|
socket(toInt(domain), toInt(typ), toInt(protocol))
|
||||||
|
|
||||||
|
proc newRawSocket*(domain: cint, typ: cint, protocol: cint): SocketHandle =
|
||||||
|
## Creates a new socket; returns `InvalidSocket` if an error occurs.
|
||||||
|
##
|
||||||
|
## Use this overload if one of the enums specified above does
|
||||||
|
## not contain what you need.
|
||||||
|
socket(domain, typ, protocol)
|
||||||
|
|
||||||
proc close*(socket: SocketHandle) =
|
proc close*(socket: SocketHandle) =
|
||||||
## closes a socket.
|
## closes a socket.
|
||||||
when useWinVersion:
|
when useWinVersion:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue