mirror of
https://github.com/libevent/libevent.git
synced 2025-01-31 09:12:55 +08:00
fromtrunk: fix a bug in buffrevent read water marks and add a test for them
svn:r732
This commit is contained in:
parent
47abd3eaa5
commit
f2b8f9b090
@ -4,6 +4,7 @@ Changes in 1.4.4-stable:
|
||||
o Correctly handle timeouts larger than 35 minutes on Linux with epoll.c. This is probably a kernel defect, but we'll have to support old kernels anyway even if it gets fixed.
|
||||
o Fix a potential stack corruption bug in tagging on 64-bit CPUs.
|
||||
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.3-stable:
|
||||
|
@ -143,9 +143,8 @@ bufferevent_readcb(int 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 */
|
||||
|
@ -44,6 +44,7 @@
|
||||
#include <sys/socket.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/signal.h>
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
@ -905,6 +906,10 @@ test_evbuffer_find(void)
|
||||
evbuffer_free(buf);
|
||||
}
|
||||
|
||||
/*
|
||||
* simple bufferevent test
|
||||
*/
|
||||
|
||||
static void
|
||||
readcb(struct bufferevent *bev, void *arg)
|
||||
{
|
||||
@ -958,6 +963,74 @@ test_bufferevent(void)
|
||||
cleanup_test();
|
||||
}
|
||||
|
||||
/*
|
||||
* test watermarks and bufferevent
|
||||
*/
|
||||
|
||||
static void
|
||||
wm_readcb(struct bufferevent *bev, void *arg)
|
||||
{
|
||||
int len = EVBUFFER_LENGTH(bev->input);
|
||||
static int nread;
|
||||
|
||||
assert(len >= 10 && len <= 20);
|
||||
|
||||
evbuffer_drain(bev->input, len);
|
||||
|
||||
nread += len;
|
||||
if (nread == 65000) {
|
||||
bufferevent_disable(bev, EV_READ);
|
||||
test_ok++;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
@ -1391,6 +1464,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