Hi Nick, Thanks a lot for your reply.
One more doubt about bufferevent. As in socket networking programming, Sometimes It may require more than one read/recv in server side for a single write by a client, depending upon server socket's read buffer availability. Similarly here our read callback may get call more than one for a single write by a client depending upon server socket's read buffer availability. Specially If you are going to deal with big chunk of data. Am i correct here? Thanks Deepak On Tue, May 31, 2011 at 10:33 AM, Nick Mathewson <ni...@freehaven.net>wrote: > On Mon, May 30, 2011 at 5:03 AM, deepak jain <deepakjain...@gmail.com> > wrote: > > Hello, > > I am a new user of libevent and new to asynchronous I/O , so the > question > > may seem quite naive. > > I am building an application based on libevent on linux using epoll > backend. > > Sometime clients of my application can write a huge data to my > application > > say 100K bytes. > > I am using buffer_read_buffer() api for reading data from clients. In > that > > case, would always only one call of buffer_read_buffer be sufficient > > or buffer_read_buffer() will get call multiple time until i did not get > > whole 100K bytes. > > You can read any amount of data from the bufferevent, from one byte up > to all the bytes that are waiting. > > The is one catch here: the read callback that you provide for the > bufferevent will be called when new data arrives, and only when new > data arrives. So if there is 50K waiting on the buffer, and your > callback handles 30K and then returns, Libevent won't invoke your > callback again until some more data is read. So if you want to handle > all the data as it arrives, a callback like this will work fine: > > void readcb(struct bufferevent *bev, void *ctx) { > char bytes[1024]; > size_t n; > while ((n = bufferevent_read(bev, bytes, 1024)) { > process(bytes, n); > } > } > > but a callback like this will potentially leave data around until more > data arrives: > > void readcb(struct bufferevent *bev, void *ctx) { > char bytes[1024]; > size_t n = bufferevent_read(bev, bytes, 1024); > if (n) process(bytes, n); > } > > Also, you might want to look through the interface a little. If you > need more finegrained control over reading and draining data, have a > look at the evbuffer interface, and use the evbuffer commands on the > input buffer returned by bufferevent_get_input(). > > Hoping this helps, > -- > Nick > *********************************************************************** > To unsubscribe, send an e-mail to majord...@freehaven.net with > unsubscribe libevent-users in the body. >