diff --git a/asyncdispatch2/transports/common.nim b/asyncdispatch2/transports/common.nim index f52cb38..32f996f 100644 --- a/asyncdispatch2/transports/common.nim +++ b/asyncdispatch2/transports/common.nim @@ -157,12 +157,12 @@ proc initTAddress*(address: string, port: int): TransportAddress = proc resolveTAddress*(address: string, family = IpAddressFamily.IPv4): seq[TransportAddress] = ## Resolve string representation of ``address``. - ## + ## ## Supported formats are: ## IPv4 numeric address ``a.b.c.d:port`` ## IPv6 numeric address ``[::]:port`` ## Hostname address ``hostname:port`` - ## + ## ## If hostname address is detected, then network address translation via DNS ## will be performed. var @@ -215,6 +215,3 @@ when defined(windows): const ERROR_SUCCESS* = 0 proc cancelIo*(hFile: HANDLE): WINBOOL {.stdcall, dynlib: "kernel32", importc: "CancelIo".} - -when isMainModule: - echo $resolveTAddress("localhost:443", IpAddressFamily.IPv6) \ No newline at end of file diff --git a/asyncdispatch2/transports/datagram.nim b/asyncdispatch2/transports/datagram.nim index a248fea..008e802 100644 --- a/asyncdispatch2/transports/datagram.nim +++ b/asyncdispatch2/transports/datagram.nim @@ -7,7 +7,7 @@ # Apache License, version 2.0, (LICENSE-APACHEv2) # MIT license (LICENSE-MIT) -import net, nativesockets, os, deques, strutils +import net, nativesockets, os, deques import ../asyncloop, ../handles import common diff --git a/asyncdispatch2/transports/stream.nim b/asyncdispatch2/transports/stream.nim index a24c52e..37380d0 100644 --- a/asyncdispatch2/transports/stream.nim +++ b/asyncdispatch2/transports/stream.nim @@ -7,8 +7,8 @@ # Apache License, version 2.0, (LICENSE-APACHEv2) # MIT license (LICENSE-MIT) -import net, nativesockets, os, deques, strutils -import ../asyncloop, ../asyncsync, ../handles, ../sendfile +import net, nativesockets, os, deques +import ../asyncloop, ../handles, ../sendfile import common when defined(windows): @@ -38,12 +38,6 @@ type fd*: AsyncFD # File descriptor state: set[TransportState] # Current Transport state reader: Future[void] # Current reader Future - # ZAH: I'm not quite certain, but it seems to me that the intermediate - # buffer is not necessary. The receiving code needs to know how to grow - # the output buffer of the future attached to the read operation. If this - # is the case, the buffering can be replaced with direct writing to this - # output buffer. Furthermore, we'll be able to signal additional 'progress' - # events for the future to make the API more complete. buffer: seq[byte] # Reading buffer offset: int # Reading buffer offset error: ref Exception # Current error @@ -101,10 +95,6 @@ template setReadError(t, e: untyped) = (t).state.incl(ReadError) (t).error = newException(TransportOsError, osErrorMsg((e))) -# template setWriteError(t, e: untyped) = -# (t).state.incl(WriteError) -# (t).error = newException(TransportOsError, osErrorMsg((e))) - template finishReader(t: untyped) = var reader = (t).reader reader.complete() @@ -839,15 +829,13 @@ proc write*[T](transp: StreamTransport, msg: seq[T]): Future[int] = return retFuture proc writeFile*(transp: StreamTransport, handle: int, - offset: uint = 0, - size: int = 0): Future[int] = + offset: uint = 0, size: int = 0): Future[int] = ## Write data from file descriptor ``handle`` to transport ``transp``. ## ## You can specify starting ``offset`` in opened file and number of bytes ## to transfer from file to transport via ``size``. var retFuture = newFuture[int]("transport.writeFile") - checkClosed(transp) - + transp.checkClosed(retFuture) var vector = StreamVector(kind: DataFile, writer: retFuture, buf: cast[pointer](size), offset: offset, buflen: handle) @@ -1054,7 +1042,7 @@ proc read*(transp: StreamTransport, n = -1): Future[seq[byte]] {.async.} = raise transp.getError() if (ReadClosed in transp.state) or transp.atEof(): break - + if transp.offset > 0: let s = len(result) let o = s + transp.offset