* Implement dial, support IPv6 in httpclient
Added ``dial`` procedure to networking modules: ``net``, ``asyncdispatch``,
``asyncnet``. It merges socket creation, address resolution, and connection
into single step. When using ``dial``, you don't have to worry about
IPv4 vs IPv6 problem.
Fixed addrInfo loop in connect to behave properly.
Previously it would stop on first non-immediate failure, instead of
continuing and trying the remaining addresses.
Fixed newAsyncNativeSocket to raise proper error if socket creation
fails.
Fixes: #3811
* Check domain during connect() only on non-Windows
This is how it was in the previous implementation of connect().
* Call 'osLastError' before 'close' in net.dial
* Record osLastError before freeAddrInfo in net.dial
* Add missing docs for 'dial' proc
* Optimize dial to create one FD per domain, add tests
And make async IPv6 servers work on Windows.
* Add IPv6 test to uri module
* Fix getAddrString error handling
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.
Exporting newSocket(fd) mimics what asyncnet does and lets you pass in your
own socket FD.
newSocket*(fd) and newAsyncSocket*(fd) now both take "buffered" instead of
"isBuff" and defaults to true to match the other constructors on both.
FutureVar[T] is a new distinct Future type which is designed to be used
for situations where the highest performance is needed. It reduces the
number of Future allocations needed. It acts as a replacement for
'var' params in async procs.
This commit modifies @def-'s PR in order to make it safer. The recvLineInto
procedure has been modified to take a ``FutureVar[string]`` param instead of a
``ptr string`` param.
- Export socket field of AsyncHttpServer and addHeaders proc for templates
- Make respond a template instead of proc because of how often it's called.
This means no more "await" when invoking it.
- Optimize respond template with special case for empty headers and
Content-Length entry
- newRequest doesn't allocate a hostname and body anymore because they're
copied in later
- Major changes to processClient to prevent allocations and copies
- readInto, readIntoBuf, are templates instead of procs now
- New recvLineInto template that reads directly into a string instead of
creating a new one. Used by recvLine proc now
- Need fd and bufLen fields of AsyncSocketDesc exported because of the
templates
- recv returns a shallow string to prevent copying
- This gives significant speedups, mostly by using templates instead of
creating new Futures and waiting for them all the time.