title: how to check if connection is established when use libev with non-block socket
body: <p>I have some code use libev on how to deal with connection timeout as below (please refer to <a href="http://lists.schmorp.de/pipermail/libev/2011q2/001365.html" rel="nofollow">http://lists.schmorp.de/pipermail/libev/2011q2/001365.html</a>):</p>
  
  <pre><code>sd = create_socket()
  set_socket_nonblock(sd)
  connect("127.0.0.1", port) // connect to an invalid port
  ev_io_init(&amp;w_io, connect_cb, sd, EV_WRITE)
  ev_io_start(...)
  ev_timer_init(&amp;w_timer, timeout_cb, 5.0, 0)
  ev_timer_start(...)
  </code></pre>
  
  <p>and in someplace perform ev_run. The connect_cb is called and in this callback function I checked the revents with EV_ERROR, the result is no error. This is strange because I provide an invalid port number which is not listening in local machine. Anyway, I try to send a message in the connect_cb function, got an error 111, which means that connection refused. I'm confused! How to check if the connection is established correctly when use non-block socket?</p>