Hi Azat,
What I want to do is :
1. a main thread listening on a even_base, let's call it BASE,
2. when a new connection (conn-1) coming, the listening callback is involked, 
and a  bufferevent (event-1) is created.  Then the bufferevent (event-1) is put 
into the BASE with read/write callback functions.
3. when a second connection (conn-2) comming, the listening callback is also 
involked, and another bufferevent (event-2) is created. Then event-2 is also 
put into the BASE with event-2's read/write callback functions.
4. When conn-1 recvs some data, event-1's read callback is involked by 
BASE(main thread). Then, event-1's read callback function reads the message and 
put it into a message queue, and then returns.
5. There is a thread-pool processing the message queue, so diffenent messages 
are parallel processed. For example, thread-1 picks up a message from the 
message queue, process it and put the response message into the socket buffer 
using (eventbuffer_add()).
That you just need to run event_base_loop() in a thread that's all.
Or I'm missing something?
Yes, I know. I can do that.

So even though some requests might take a long time to process, but other other 
requests don't block. Because we have different threads to process the message 
queue.

According to the above model, the event_base and bufferevent should be both 
thread-safe, because
It's better to enable locking for bufferevents anyway.

Are you sure it is ok to lock the bufferevents by our own lock? No need to implement these (http://www.wangafu.net/~nickm/libevent-book/Ref1_libsetup.html <http://www.wangafu.net/%7Enickm/libevent-book/Ref1_libsetup.html> specifically that section about “Locks and threading”)???

How about event_base? lock event_base similar to bufferevents?

1. For bufferevent , different threads can add data with the same bufferevent
2. For event_base, different bufferevents in the same event_base might be free 
and added by different threads.
And globally.
***********************************************************************
To unsubscribe, send an e-mail to [email protected] with
unsubscribe libevent-users    in the body.

Reply via email to