> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Niels Provos
> Sent: Wednesday, November 01, 2006 5:34 AM
> To: Matt Pearson
> Cc: libevent-users@monkey.org
> Subject: Re: [Libevent-users] questions about bufferevent
> 
> Hi Matt,
> 
> that's about right.  You get the write callback when the 
> write buffer is below the watermark (which is usually 0 
> bytes).  You either supply more data then or disable the 
> write callback.  It get's automatically reneabled when you 
> call bufferevent_write.
> 
> Niels.

thank you  Niels and Matt .

i  write an example code  according you . Please  check  that.

====my code====
...
void connection_accept()
{
...
//accept a new nonblock connfd
cs->bev=bufferevent_new(connfd,code_readcb, code_writecb, code_errorcb, cs);
...
bufferevent_enable(cs->bev, EV_READ | EV_WRITE);
...
}


void code_readcb()
{
struct evbuffer* buffer=EVBUFFER_INPUT(bev);
char* buf=(char*)EVBUFFER_DATA(buffer);
size_t len = EVBUFFER_LENGTH(buffer);
...
//transfer  data  to  my_own_biz_functions.
}


void code_writecb()
{
bufferevent_disable(bev,EV_WRITE);
}


void code_errorcb()
{
...
}

void my_functions()
{
...
//produce  data  , and  then  want  to  transfer  them
bufferevent_write(bev,(void*)PubBuf,len);
...
}

====my code====

> 
> On 10/31/06, Matt Pearson <[EMAIL PROTECTED]> wrote:
> > On 10/30/06, cwinl <[EMAIL PROTECTED]> wrote:
> > > i also suspect  my usage of  bufferevent_write.
> > > can you illustrate  an  example ?
> >
> > (Sorry if I mess this up; my first real mailing list post...)
> >
> > When I wrote a simple chat proxy using bufferevents, I added a
> > bufferevent_enable(EV_WRITE) in my read callback after 
> writing data, 
> > and then my write callback consisted of just a 
> > bufferevent_disable(EV_WRITE), because otherwise the write callback 
> > will keep firing because the buffer is empty, and it thinks 
> you want 
> > to write more.  This was my thinking, anyway; I never actually 
> > profiled it or anything because I wrote it in an afternoon and then 
> > didn't touch it after that.
> > _______________________________________________
> > Libevent-users mailing list
> > Libevent-users@monkey.org
> > http://monkey.org/mailman/listinfo/libevent-users
> >
> >
> _______________________________________________
> Libevent-users mailing list
> Libevent-users@monkey.org
> http://monkey.org/mailman/listinfo/libevent-users

_______________________________________________
Libevent-users mailing list
Libevent-users@monkey.org
http://monkey.org/mailman/listinfo/libevent-users

Reply via email to