oh, i see and yet.

3, 4 Socket.send do the same thing like send syscall, but 1 definitly means 
send all "if one send did not send all data, send again"

the first send's 
[implementation](https://github.com/nim-lang/Nim/blob/version-1-6/lib/pure/asyncdispatch.nim#L1917-L1934)
    
    
    proc send*(socket: AsyncFD, buf: pointer, size: int,
                 flags = {SocketFlag.SafeDisconn}): owned(Future[void]) =
        var retFuture = newFuture[void]("send")
        
        var written = 0
        
        proc cb(sock: AsyncFD): bool =
          result = true
          let netSize = size-written
          var d = cast[cstring](buf)
          let res = send(sock.SocketHandle, addr d[written], netSize.cint,
                         MSG_NOSIGNAL)
          if res < 0:
            let lastError = osLastError()
            if lastError.int32 != EINTR and
               lastError.int32 != EWOULDBLOCK and
               lastError.int32 != EAGAIN:
              if flags.isDisconnectionError(lastError):
                retFuture.complete()
              else:
                retFuture.fail(newOSError(lastError))
            else:
              result = false # We still want this callback to be called.
          else:
            written.inc(res)
            if res != netSize:
              result = false # We still have data to send.
            else:
              retFuture.complete()
        # TODO: The following causes crashes.
        #if not cb(socket):
        addWrite(socket, cb)
        return retFuture
    
    
    Run

Reply via email to