]> granicus.if.org Git - libevent/commitdiff
another test
authorNiels Provos <provos@gmail.com>
Sat, 8 Mar 2003 20:14:39 +0000 (20:14 +0000)
committerNiels Provos <provos@gmail.com>
Sat, 8 Mar 2003 20:14:39 +0000 (20:14 +0000)
svn:r53

test/regress.c

index 5f5c9af86b9146902de30c5867880e3d825a9cc4..a5f7d44fdf39f9e6963e18e10fb2c746262fb044 100644 (file)
@@ -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;