Hello,

I'm in a bit of confusion, I'm writing a client using bufferevents, what I do 
is:
add a bunch of bufferevents to a base
set timeouts using the bufferevent timeout functions to 5-10s
and then dispatch the base, but this causes the base to return practically 
immediately, the connections get made, but, libevent doesn't seem to wait until 
the timeout is done, nor does it seem to wait forever, it just returns.
I have an eventcb + a readcb + a writecb set for each bev, and, my order of 
operations is:

Set up the bev, using  bufferevent_socket_new, then I set the cbs using 
bufferevent_setcb, then I set up the timeval struct and set the timeouts, 
finally, I set the watermark to 0/1 (just to see if this makes a difference, it 
doesn't), i enable EV_READ|EV_WRITE on the bev, and then actually do 
bufferevent_socket_connect with it.

I do this in a loop(I've tried just a single event too), and then finally, do a 
event_base_dispatch(base), which returns practically immediately (all the conns 
are made, but.. it doesn't seem to wait for anything).

I get one callback before the base stops looping, on my event callback, with 
BEV_EVENT_CONNECTED.

so.. what am I doing wrong?

Right now, I've instead done this:

event_base_loopexit(base, &ten_sec);

while(1)
{
event_base_dispatch(base);
break;
}

This causes it to keep the connection alive for ten seconds (until the loop is 
exited), but, my timeout for the connection at this time is 5s.. the event does 
not timeout during this time.

I'm sure I'm doing something wrong, how do I get the functionality I want? is 
the above the only way? (The above would be fine, except I get no notification 
of closed events, so I can't handle them appropriately, I maintain some structs 
per event (in the callback ptr), that I'd like to take a look at before 
exiting.)

Any ideas?

Thank you!



      

***********************************************************************
To unsubscribe, send an e-mail to [email protected] with
unsubscribe libevent-users    in the body.

Reply via email to