mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-11 05:14:46 -04:00
add persist test
svn:r47
This commit is contained in:
parent
bedded8230
commit
481799afd2
@ -49,6 +49,7 @@ static char wbuf[4096];
|
|||||||
static char rbuf[4096];
|
static char rbuf[4096];
|
||||||
static int woff;
|
static int woff;
|
||||||
static int roff;
|
static int roff;
|
||||||
|
static int usepersist;
|
||||||
static struct timeval tset;
|
static struct timeval tset;
|
||||||
static struct timeval tcalled;
|
static struct timeval tcalled;
|
||||||
|
|
||||||
@ -104,9 +105,12 @@ multiple_write_cb(int fd, short event, void *arg)
|
|||||||
|
|
||||||
if (woff >= sizeof(wbuf)) {
|
if (woff >= sizeof(wbuf)) {
|
||||||
shutdown(pair[0], SHUT_WR);
|
shutdown(pair[0], SHUT_WR);
|
||||||
|
if (usepersist)
|
||||||
|
event_del(ev);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!usepersist)
|
||||||
event_add(ev, NULL);
|
event_add(ev, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,10 +125,14 @@ multiple_read_cb(int fd, short event, void *arg)
|
|||||||
fprintf(stderr, "%s: read\n", __func__);
|
fprintf(stderr, "%s: read\n", __func__);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (len == 0)
|
if (len == 0) {
|
||||||
|
if (usepersist)
|
||||||
|
event_del(ev);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
roff += len;
|
roff += len;
|
||||||
|
if (!usepersist)
|
||||||
event_add(ev, NULL);
|
event_add(ev, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,7 +213,7 @@ main (int argc, char **argv)
|
|||||||
event_init();
|
event_init();
|
||||||
|
|
||||||
/* Very simple read test */
|
/* Very simple read test */
|
||||||
setup_test("Simple read :");
|
setup_test("Simple read: ");
|
||||||
|
|
||||||
write(pair[0], TEST1, strlen(TEST1)+1);
|
write(pair[0], TEST1, strlen(TEST1)+1);
|
||||||
shutdown(pair[0], SHUT_WR);
|
shutdown(pair[0], SHUT_WR);
|
||||||
@ -227,10 +235,12 @@ main (int argc, char **argv)
|
|||||||
|
|
||||||
/* Multiple read and write test */
|
/* Multiple read and write test */
|
||||||
setup_test("Multiple read/write: ");
|
setup_test("Multiple read/write: ");
|
||||||
|
memset(rbuf, 0, sizeof(rbuf));
|
||||||
for (i = 0; i < sizeof(wbuf); i++)
|
for (i = 0; i < sizeof(wbuf); i++)
|
||||||
wbuf[i] = i;
|
wbuf[i] = i;
|
||||||
|
|
||||||
roff = woff = 0;
|
roff = woff = 0;
|
||||||
|
usepersist = 0;
|
||||||
|
|
||||||
event_set(&ev, pair[0], EV_WRITE, multiple_write_cb, &ev);
|
event_set(&ev, pair[0], EV_WRITE, multiple_write_cb, &ev);
|
||||||
event_add(&ev, NULL);
|
event_add(&ev, NULL);
|
||||||
@ -243,6 +253,26 @@ main (int argc, char **argv)
|
|||||||
|
|
||||||
cleanup_test();
|
cleanup_test();
|
||||||
|
|
||||||
|
/* Multiple read and write test with persist */
|
||||||
|
setup_test("Persist read/write: ");
|
||||||
|
memset(rbuf, 0, sizeof(rbuf));
|
||||||
|
for (i = 0; i < sizeof(wbuf); i++)
|
||||||
|
wbuf[i] = i;
|
||||||
|
|
||||||
|
roff = woff = 0;
|
||||||
|
usepersist = 1;
|
||||||
|
|
||||||
|
event_set(&ev, pair[0], EV_WRITE|EV_PERSIST, multiple_write_cb, &ev);
|
||||||
|
event_add(&ev, NULL);
|
||||||
|
event_set(&ev2, pair[1], EV_READ|EV_PERSIST, multiple_read_cb, &ev2);
|
||||||
|
event_add(&ev2, NULL);
|
||||||
|
event_dispatch();
|
||||||
|
|
||||||
|
if (roff == woff)
|
||||||
|
test_ok = memcmp(rbuf, wbuf, sizeof(wbuf)) == 0;
|
||||||
|
|
||||||
|
cleanup_test();
|
||||||
|
|
||||||
setup_test("Simple timeout: ");
|
setup_test("Simple timeout: ");
|
||||||
|
|
||||||
tv.tv_usec = 0;
|
tv.tv_usec = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user