mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-08 11:53:00 -04:00
fix a bug in buffrevent read water marks and add a test for them
svn:r731
This commit is contained in:
parent
3278012f33
commit
3a17aeed7a
@ -72,6 +72,7 @@ Changes in current version:
|
||||
o New functions (event_assign, event_new, event_free) for use by apps that want to be safely threadsafe, or want to remain ignorant of the contents of struct event.
|
||||
o introduce bufferevent_read_buffer; allows reading without memory copy.
|
||||
o expose bufferevent_setwatermark via header files and fix high watermark on read
|
||||
o fix a bug in buffrevent read water marks and add a test for them
|
||||
|
||||
Changes in 1.4.0:
|
||||
o allow \r or \n individually to separate HTTP headers instead of the standard "\r\n"; from Charles Kerr.
|
||||
|
@ -147,9 +147,8 @@ bufferevent_readcb(evutil_socket_t fd, short event, void *arg)
|
||||
struct evbuffer *buf = bufev->input;
|
||||
event_del(&bufev->ev_read);
|
||||
|
||||
/* Now schedule a callback for us */
|
||||
/* Now schedule a callback for us when the buffer changes */
|
||||
evbuffer_setcb(buf, bufferevent_read_pressure_cb, bufev);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Invoke the user callback - must always be called last */
|
||||
|
@ -1302,6 +1302,10 @@ test_evbuffer_find(void)
|
||||
evbuffer_free(buf);
|
||||
}
|
||||
|
||||
/*
|
||||
* simple bufferevent test
|
||||
*/
|
||||
|
||||
static void
|
||||
readcb(struct bufferevent *bev, void *arg)
|
||||
{
|
||||
@ -1365,6 +1369,80 @@ test_bufferevent(void)
|
||||
cleanup_test();
|
||||
}
|
||||
|
||||
/*
|
||||
* test watermarks and bufferevent
|
||||
*/
|
||||
|
||||
static void
|
||||
wm_readcb(struct bufferevent *bev, void *arg)
|
||||
{
|
||||
struct evbuffer *evbuf = evbuffer_new();
|
||||
int len = EVBUFFER_LENGTH(bev->input);
|
||||
static int nread;
|
||||
|
||||
assert(len >= 10 && len <= 20);
|
||||
|
||||
assert(evbuf != NULL);
|
||||
|
||||
/* gratuitous test of bufferevent_read_buffer */
|
||||
bufferevent_read_buffer(bev, evbuf);
|
||||
|
||||
nread += len;
|
||||
if (nread == 65000) {
|
||||
bufferevent_disable(bev, EV_READ);
|
||||
test_ok++;
|
||||
}
|
||||
|
||||
evbuffer_free(evbuf);
|
||||
}
|
||||
|
||||
static void
|
||||
wm_writecb(struct bufferevent *bev, void *arg)
|
||||
{
|
||||
if (EVBUFFER_LENGTH(bev->output) == 0)
|
||||
test_ok++;
|
||||
}
|
||||
|
||||
static void
|
||||
wm_errorcb(struct bufferevent *bev, short what, void *arg)
|
||||
{
|
||||
test_ok = -2;
|
||||
}
|
||||
|
||||
static void
|
||||
test_bufferevent_watermarks(void)
|
||||
{
|
||||
struct bufferevent *bev1, *bev2;
|
||||
char buffer[65000];
|
||||
int i;
|
||||
|
||||
setup_test("Bufferevent Watermarks: ");
|
||||
|
||||
bev1 = bufferevent_new(pair[0], NULL, wm_writecb, wm_errorcb, NULL);
|
||||
bev2 = bufferevent_new(pair[1], wm_readcb, NULL, wm_errorcb, NULL);
|
||||
|
||||
bufferevent_disable(bev1, EV_READ);
|
||||
bufferevent_enable(bev2, EV_READ);
|
||||
|
||||
for (i = 0; i < sizeof(buffer); i++)
|
||||
buffer[i] = i;
|
||||
|
||||
bufferevent_write(bev1, buffer, sizeof(buffer));
|
||||
|
||||
/* limit the reading on the receiving bufferevent */
|
||||
bufferevent_setwatermark(bev2, EV_READ, 10, 20);
|
||||
|
||||
event_dispatch();
|
||||
|
||||
bufferevent_free(bev1);
|
||||
bufferevent_free(bev2);
|
||||
|
||||
if (test_ok != 2)
|
||||
test_ok = 0;
|
||||
|
||||
cleanup_test();
|
||||
}
|
||||
|
||||
struct test_pri_event {
|
||||
struct event ev;
|
||||
int count;
|
||||
@ -1865,6 +1943,7 @@ main (int argc, char **argv)
|
||||
test_evbuffer_find();
|
||||
|
||||
test_bufferevent();
|
||||
test_bufferevent_watermarks();
|
||||
|
||||
test_free_active_base();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user