tasyncconnect.nim 781 B

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