Hello, I have an eventloop with a bufferevent set up in an application. When handling read events everything is done on the event loop thread, and some writes are done as a direct result of data being read there, but writes are typically placed on a queue by a separate threads. But I want the writes to be handled on the eventloop thread as well.
i.e. I have a readcb() function which reads incoming frames from the remote system. Each frame typically leads to some kind of response. These I can send directly using bufferevent_write() as soon as the complete frames have been received and parsed. However, the bufferevent also has a context associated with it which contains a mutex and a linked list which is shared with the rest of the application. Other parts of the application can place frames on the outqueue at any time. Could one set up both a read and write callback, but not enable EV_WRITE. Then, on the separate threads, lock the outqueue, add frames to the queue, unlock the queue and finally call bufferevent_enable(bev, EV_WRITE)? I.e. would enabling EV_WRITE cause the write callback to be called? ..and once all the frames have been written, the write callback would call bufferevent_disable(bev, EV_WRITE) again? .. essentially using the EV_WRITE flag as a condvar, in some perverted sense. Does switching on EV_WRITE trigger a call to the write callback? Is it safe to do it from another thread? (Yes, I have enabled thread support in the library, and am initializing the thread support properly). Is there some other way to do it? (For various reasons I don't want to call bufferevent_write() directly from the threads which generate output frames). /Jan *********************************************************************** To unsubscribe, send an e-mail to [email protected] with unsubscribe libevent-users in the body.
