var fileContent = reader.read(8192)
while fileContent.len() > 0:
echo("before send")
await socket.send(fileContent)
echo("after send")
fileContent = reader.read(8192)
It worked fine generally, but failed when the peer closed the socket connection. In that case, asyncdispatch.poll simply closes the socket and remove all registered callbacks, thus await socket.send(...) would never return, and everything after the await line will not be executed.
As I can see, there's no way to handle peer disconnection.
I think the correct behavior here is to raise an exception from send when the peer disconnects.
I'm using Nim version 4d8750a from the devel branch
if EvError in info.events:
closeSocket(data.fd)
continue