mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-12 13:58:58 -04:00
introduce bufferevent_setcb and bufferevent_setfd to allow better manipulation of bufferevents
svn:r737
This commit is contained in:
parent
22c8a40402
commit
9485ff9a66
@ -75,6 +75,7 @@ Changes in current version:
|
|||||||
o fix a bug in buffrevent read water marks and add a test for them
|
o fix a bug in buffrevent read water marks and add a test for them
|
||||||
o fix a bug in which bufferevent_write_buffer would not schedule a write event
|
o fix a bug in which bufferevent_write_buffer would not schedule a write event
|
||||||
o provide bufferevent_input and bufferevent_output without requiring knowledge of the structure
|
o provide bufferevent_input and bufferevent_output without requiring knowledge of the structure
|
||||||
|
o introduce bufferevent_setcb and bufferevent_setfd to allow better manipulation of bufferevents
|
||||||
|
|
||||||
Changes in 1.4.0:
|
Changes in 1.4.0:
|
||||||
o allow \r or \n individually to separate HTTP headers instead of the standard "\r\n"; from Charles Kerr.
|
o allow \r or \n individually to separate HTTP headers instead of the standard "\r\n"; from Charles Kerr.
|
||||||
|
35
evbuffer.c
35
evbuffer.c
@ -257,11 +257,7 @@ bufferevent_new(evutil_socket_t fd, evbuffercb readcb, evbuffercb writecb,
|
|||||||
event_set(&bufev->ev_read, fd, EV_READ, bufferevent_readcb, bufev);
|
event_set(&bufev->ev_read, fd, EV_READ, bufferevent_readcb, bufev);
|
||||||
event_set(&bufev->ev_write, fd, EV_WRITE, bufferevent_writecb, bufev);
|
event_set(&bufev->ev_write, fd, EV_WRITE, bufferevent_writecb, bufev);
|
||||||
|
|
||||||
bufev->readcb = readcb;
|
bufferevent_setcb(bufev, readcb, writecb, errorcb, cbarg);
|
||||||
bufev->writecb = writecb;
|
|
||||||
bufev->errorcb = errorcb;
|
|
||||||
|
|
||||||
bufev->cbarg = cbarg;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set to EV_WRITE so that using bufferevent_write is going to
|
* Set to EV_WRITE so that using bufferevent_write is going to
|
||||||
@ -273,6 +269,33 @@ bufferevent_new(evutil_socket_t fd, evbuffercb readcb, evbuffercb writecb,
|
|||||||
return (bufev);
|
return (bufev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
bufferevent_setcb(struct bufferevent *bufev,
|
||||||
|
evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg)
|
||||||
|
{
|
||||||
|
bufev->readcb = readcb;
|
||||||
|
bufev->writecb = writecb;
|
||||||
|
bufev->errorcb = errorcb;
|
||||||
|
|
||||||
|
bufev->cbarg = cbarg;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
bufferevent_setfd(struct bufferevent *bufev, evutil_socket_t fd)
|
||||||
|
{
|
||||||
|
event_del(&bufev->ev_read);
|
||||||
|
event_del(&bufev->ev_write);
|
||||||
|
|
||||||
|
event_set(&bufev->ev_read, fd, EV_READ, bufferevent_readcb, bufev);
|
||||||
|
event_set(&bufev->ev_write, fd, EV_WRITE, bufferevent_writecb, bufev);
|
||||||
|
if (bufev->ev_base != NULL) {
|
||||||
|
event_base_set(bufev->ev_base, &bufev->ev_read);
|
||||||
|
event_base_set(bufev->ev_base, &bufev->ev_write);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* might have to manually trigger event registration */
|
||||||
|
}
|
||||||
|
|
||||||
struct evbuffer *
|
struct evbuffer *
|
||||||
bufferevent_input(struct bufferevent *bufev)
|
bufferevent_input(struct bufferevent *bufev)
|
||||||
{
|
{
|
||||||
@ -430,6 +453,8 @@ bufferevent_base_set(struct event_base *base, struct bufferevent *bufev)
|
|||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
|
bufev->ev_base = base;
|
||||||
|
|
||||||
res = event_base_set(base, &bufev->ev_read);
|
res = event_base_set(base, &bufev->ev_read);
|
||||||
if (res == -1)
|
if (res == -1)
|
||||||
return (res);
|
return (res);
|
||||||
|
@ -140,6 +140,31 @@ int bufferevent_priority_set(struct bufferevent *bufev, int pri);
|
|||||||
void bufferevent_free(struct bufferevent *bufev);
|
void bufferevent_free(struct bufferevent *bufev);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Changes the callbacks for a bufferevent.
|
||||||
|
|
||||||
|
@param bufev the bufferevent object for which to change callbacks
|
||||||
|
@param readcb callback to invoke when there is data to be read, or NULL if
|
||||||
|
no callback is desired
|
||||||
|
@param writecb callback to invoke when the file descriptor is ready for
|
||||||
|
writing, or NULL if no callback is desired
|
||||||
|
@param errorcb callback to invoke when there is an error on the file
|
||||||
|
descriptor
|
||||||
|
@param cbarg an argument that will be supplied to each of the callbacks
|
||||||
|
(readcb, writecb, and errorcb)
|
||||||
|
@see bufferevent_new()
|
||||||
|
*/
|
||||||
|
void bufferevent_setcb(struct bufferevent *bufev,
|
||||||
|
evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Changes the file descriptor on which the bufferevent operates.
|
||||||
|
|
||||||
|
@param bufev the bufferevent object for which to change the file descriptor
|
||||||
|
@param fd the file descriptor to operate on
|
||||||
|
*/
|
||||||
|
void bufferevent_setfd(struct bufferevent *bufev, evutil_socket_t fd);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Write data to a bufferevent buffer.
|
Write data to a bufferevent buffer.
|
||||||
|
|
||||||
|
@ -65,6 +65,8 @@ struct event_watermark {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct bufferevent {
|
struct bufferevent {
|
||||||
|
struct event_base *ev_base;
|
||||||
|
|
||||||
struct event ev_read;
|
struct event ev_read;
|
||||||
struct event ev_write;
|
struct event ev_write;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user