how to check if connection is established when use libev with non-block socket -


i have code use libev on how deal connection timeout below (please refer http://lists.schmorp.de/pipermail/libev/2011q2/001365.html):

sd = create_socket() set_socket_nonblock(sd) connect("127.0.0.1", port) // connect invalid port ev_io_init(&w_io, connect_cb, sd, ev_write) ev_io_start(...) ev_timer_init(&w_timer, timeout_cb, 5.0, 0) ev_timer_start(...) 

and in someplace perform ev_run. connect_cb called , in callback function checked revents ev_error, result no error. strange because provide invalid port number not listening in local machine. anyway, try send message in connect_cb function, got error 111, means connection refused. i'm confused! how check if connection established correctly when use non-block socket?

getsockopt possible way if connection has error happen:

int err; socklen_t len = sizeof(err); getsockopt(sd, sol_socket, so_error, &err, &len); if (err) {     // error happen } else {     connection ok } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -