[Libevent-users] connect(), EV_WRITE event

Ana Kukec anchie at fer.hr
Mon Feb 4 09:24:38 EST 2008


Hi all,

I tried to use the libevent library (on FreeBSD 7.0) to detect when the 
socket becomes writeable. Actually, i want to detect if destination host 
is reachable and has started tcp listener on desired port:

# if ( connect(fd, ...) < 0 )
#       perror("connect error");
# event_set(&ev_connect, client_s, EV_WRITE, fn, ...);
# event_add(&ev_connect, NULL);

where the function fn is:
# void fn (...) {
#     cout << "Function fn!" << endl;
# }

When i tried to connect to reachable host (but without tcp listener on 
desired port), the situation is following:
connect error: Connection refused
Function fn! (*program enters immediately into function fn*)

On the other hand, when i try to connect to unreachable host i get the 
following:
connect error: Operation now in progress
Function fn! (*after a few seconds*)

So, I have two questions.
How to use libevent (in case of reachable host) to detect that the other 
host really has started tcp listener on desired port?
And the second one.. What is the timeout period after which program 
enters the  function fn?

Tnx in advance,
--
Ana Kukec, B.Sc,
ZTEL <http://www.tel.fer.hr>, FER <http://www.fer.hr>,
http://ana.kukec.net


More information about the Libevent-users mailing list