mirror of
https://github.com/cuberite/libevent.git
synced 2025-08-28 05:27:33 -04:00
another test
svn:r53
This commit is contained in:
parent
28d248e006
commit
adf0bb84cd
@ -169,6 +169,51 @@ signal_cb(int fd, short event, void *arg)
|
||||
test_ok = 1;
|
||||
}
|
||||
|
||||
struct both {
|
||||
struct event ev;
|
||||
int nread;
|
||||
};
|
||||
|
||||
void
|
||||
combined_read_cb(int fd, short event, void *arg)
|
||||
{
|
||||
struct both *both = arg;
|
||||
char buf[128];
|
||||
int len;
|
||||
|
||||
len = read(fd, buf, sizeof(buf));
|
||||
if (len == -1)
|
||||
fprintf(stderr, "%s: read\n", __func__);
|
||||
if (len <= 0)
|
||||
return;
|
||||
|
||||
both->nread += len;
|
||||
event_add(&both->ev, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
combined_write_cb(int fd, short event, void *arg)
|
||||
{
|
||||
struct both *both = arg;
|
||||
char buf[128];
|
||||
int len;
|
||||
|
||||
len = sizeof(buf);
|
||||
if (len > both->nread)
|
||||
len = both->nread;
|
||||
|
||||
len = write(fd, buf, len);
|
||||
if (len == -1)
|
||||
fprintf(stderr, "%s: write\n", __func__);
|
||||
if (len <= 0) {
|
||||
shutdown(fd, SHUT_WR);
|
||||
return;
|
||||
}
|
||||
|
||||
both->nread -= len;
|
||||
event_add(&both->ev, NULL);
|
||||
}
|
||||
|
||||
/* Test infrastructure */
|
||||
|
||||
int
|
||||
@ -209,6 +254,7 @@ main (int argc, char **argv)
|
||||
struct event ev, ev2;
|
||||
struct timeval tv;
|
||||
struct itimerval itv;
|
||||
struct both r1, r2, w1, w2;
|
||||
int i;
|
||||
|
||||
setvbuf(stdout, NULL, _IONBF, 0);
|
||||
@ -277,6 +323,32 @@ main (int argc, char **argv)
|
||||
|
||||
cleanup_test();
|
||||
|
||||
setup_test("Combined read/write: ");
|
||||
memset(&r1, 0, sizeof(r1));
|
||||
memset(&r2, 0, sizeof(r2));
|
||||
memset(&w1, 0, sizeof(w1));
|
||||
memset(&w2, 0, sizeof(w2));
|
||||
|
||||
w1.nread = 4096;
|
||||
w2.nread = 8192;
|
||||
|
||||
event_set(&r1.ev, pair[0], EV_READ, combined_read_cb, &r1);
|
||||
event_set(&w1.ev, pair[0], EV_WRITE, combined_write_cb, &w1);
|
||||
event_set(&r2.ev, pair[1], EV_READ, combined_read_cb, &r2);
|
||||
event_set(&w2.ev, pair[1], EV_WRITE, combined_write_cb, &w2);
|
||||
event_add(&r1.ev, NULL);
|
||||
event_add(&w1.ev, NULL);
|
||||
event_add(&r2.ev, NULL);
|
||||
event_add(&w2.ev, NULL);
|
||||
|
||||
event_dispatch();
|
||||
|
||||
if (r1.nread == 8192 && r2.nread == 4096)
|
||||
test_ok = 1;
|
||||
|
||||
cleanup_test();
|
||||
|
||||
|
||||
setup_test("Simple timeout: ");
|
||||
|
||||
tv.tv_usec = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user