[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [Libevent-users] got error when call bufferevent_free after bufferevent_write



You freed an event in its callback! Despite what you want, it's a bad idea.


2013/7/10 贺正波 <zbhe@xxxxxxxxxxxxxxxx>
hi,
void ClientReadCB(struct bufferevent *bufev, void *_arg)
{
        bufferevent_write(bufev, "bye\n", 4);
        int Fd = bufev->ev_read.ev_fd;
        bufferevent_free(bufev);
        close(Fd);
}
bufferevent* bev = bufferevent_new(UserFd, ClientReadCB, NULL, ClientErrorCB, NULL );

I got error with above code:
[warn] Epoll MOD(1) on fd 7 failed.  Old events were 6; read change was 0 (none); write change was 2 (del): Bad file descriptor

Maybe the bufferevent_free didn't call event_del when the write buffer isn't empty?
how can I free a bufferevent when there is some data in it's buffer?

thanks!

--------------
tony
2013-07-09

***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.