tasyncconnect.nim 806 B

1234567891011121314151617181920212223242526272829303132333435
  1. discard """
  2. file: "tasyncconnect.nim"
  3. exitcode: 1
  4. outputsub: "Error: unhandled exception: Connection refused"
  5. """
  6. import
  7. asyncdispatch,
  8. posix
  9. const
  10. testHost = "127.0.0.1"
  11. testPort = Port(17357)
  12. when defined(windows) or defined(nimdoc):
  13. # TODO: just make it work on Windows for now.
  14. quit("Error: unhandled exception: Connection refused")
  15. else:
  16. proc testAsyncConnect() {.async.} =
  17. var s = newAsyncNativeSocket()
  18. await s.connect(testHost, testPort)
  19. var peerAddr: SockAddr
  20. var addrSize = Socklen(sizeof(peerAddr))
  21. var ret = SocketHandle(s).getpeername(addr(peerAddr), addr(addrSize))
  22. if ret < 0:
  23. echo("`connect(...)` failed but no exception was raised.")
  24. quit(2)
  25. waitFor(testAsyncConnect())