diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2017-05-04 10:58:21 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2017-05-04 10:58:21 +0200 |
commit | c1aa973758a60d7ef0e698c94861b74132612de5 (patch) | |
tree | 154b40aac2ce5eab835b7fa3aee2c94c06cd8d6a /lib/pure/asyncnet.nim | |
parent | 962d03d6717a5b03de52cc18aeb8ad9458a6eb8f (diff) | |
parent | 27b571dd9598d144a1d15963d9c73e75d7d764c4 (diff) | |
download | Nim-c1aa973758a60d7ef0e698c94861b74132612de5.tar.gz |
Merge branch 'devel' of github.com:nim-lang/Nim into devel
Diffstat (limited to 'lib/pure/asyncnet.nim')
-rw-r--r-- | lib/pure/asyncnet.nim | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/pure/asyncnet.nim b/lib/pure/asyncnet.nim index 1ec751a64..11b7998b2 100644 --- a/lib/pure/asyncnet.nim +++ b/lib/pure/asyncnet.nim @@ -244,6 +244,17 @@ when defineSsl: else: raiseSSLError("Socket has been disconnected") +proc dial*(address: string, port: Port, protocol = IPPROTO_TCP, + buffered = true): Future[AsyncSocket] {.async.} = + ## Establishes connection to the specified ``address``:``port`` pair via the + ## specified protocol. The procedure iterates through possible + ## resolutions of the ``address`` until it succeeds, meaning that it + ## seamlessly works with both IPv4 and IPv6. + ## Returns AsyncSocket ready to send or receive data. + let asyncFd = await asyncdispatch.dial(address, port, protocol) + let sockType = protocol.toSockType() + let domain = getSockDomain(asyncFd.SocketHandle) + result = newAsyncSocket(asyncFd, domain, sockType, protocol, buffered) proc connect*(socket: AsyncSocket, address: string, port: Port) {.async.} = ## Connects ``socket`` to server at ``address:port``. |