connect_nonblock.py 426 B

1234567891011121314151617181920
  1. # test that socket.connect() on a non-blocking socket raises EINPROGRESS
  2. try:
  3. import usocket as socket
  4. except:
  5. import socket
  6. def test(peer_addr):
  7. s = socket.socket()
  8. s.setblocking(False)
  9. try:
  10. s.connect(peer_addr)
  11. except OSError as er:
  12. print(er.args[0] == 115) # 115 is EINPROGRESS
  13. s.close()
  14. if __name__ == "__main__":
  15. test(socket.getaddrinfo('micropython.org', 80)[0][-1])