OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2003 Niels Provos <provos@citi.umich.edu> | 2 * Copyright 2003 Niels Provos <provos@citi.umich.edu> |
3 * All rights reserved. | 3 * All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 26 matching lines...) Expand all Loading... |
37 #include "config.h" | 37 #include "config.h" |
38 #endif | 38 #endif |
39 | 39 |
40 #include <sys/types.h> | 40 #include <sys/types.h> |
41 #include <sys/stat.h> | 41 #include <sys/stat.h> |
42 #include <sys/time.h> | 42 #include <sys/time.h> |
43 #ifdef WIN32 | 43 #ifdef WIN32 |
44 #include <windows.h> | 44 #include <windows.h> |
45 #else | 45 #else |
46 #include <sys/socket.h> | 46 #include <sys/socket.h> |
47 #include <sys/signal.h> | 47 #include <signal.h> |
48 #include <sys/resource.h> | 48 #include <sys/resource.h> |
49 #endif | 49 #endif |
50 #include <fcntl.h> | 50 #include <fcntl.h> |
51 #include <stdlib.h> | 51 #include <stdlib.h> |
52 #include <stdio.h> | 52 #include <stdio.h> |
53 #include <string.h> | 53 #include <string.h> |
54 #include <unistd.h> | 54 #include <unistd.h> |
55 #include <errno.h> | 55 #include <errno.h> |
56 | 56 |
57 #include <event.h> | 57 #include <event.h> |
58 #include <evutil.h> | 58 #include <evutil.h> |
59 | 59 |
60 | 60 |
61 static int count, writes, fired; | 61 static int count, writes, fired; |
62 static int *pipes; | 62 static int *pipes; |
63 static int num_pipes, num_active, num_writes; | 63 static int num_pipes, num_active, num_writes; |
64 static struct event *events; | 64 static struct event *events; |
65 | 65 |
66 | |
67 | |
68 static void | 66 static void |
69 read_cb(int fd, short which, void *arg) | 67 read_cb(int fd, short which, void *arg) |
70 { | 68 { |
71 » int idx = (int) arg, widx = idx + 1; | 69 » long idx = (long) arg, widx = idx + 1; |
72 u_char ch; | 70 u_char ch; |
73 | 71 |
74 count += read(fd, &ch, sizeof(ch)); | 72 count += read(fd, &ch, sizeof(ch)); |
75 if (writes) { | 73 if (writes) { |
76 if (widx >= num_pipes) | 74 if (widx >= num_pipes) |
77 widx -= num_pipes; | 75 widx -= num_pipes; |
78 write(pipes[2 * widx + 1], "e", 1); | 76 write(pipes[2 * widx + 1], "e", 1); |
79 writes--; | 77 writes--; |
80 fired++; | 78 fired++; |
81 } | 79 } |
82 } | 80 } |
83 | 81 |
84 static struct timeval * | 82 static struct timeval * |
85 run_once(void) | 83 run_once(void) |
86 { | 84 { |
87 » int *cp, i, space; | 85 » int *cp, space; |
| 86 » long i; |
88 static struct timeval ts, te; | 87 static struct timeval ts, te; |
89 | 88 |
90 for (cp = pipes, i = 0; i < num_pipes; i++, cp += 2) { | 89 for (cp = pipes, i = 0; i < num_pipes; i++, cp += 2) { |
91 event_del(&events[i]); | 90 event_del(&events[i]); |
92 event_set(&events[i], cp[0], EV_READ | EV_PERSIST, read_cb, (voi
d *) i); | 91 event_set(&events[i], cp[0], EV_READ | EV_PERSIST, read_cb, (voi
d *) i); |
93 event_add(&events[i], NULL); | 92 event_add(&events[i], NULL); |
94 } | 93 } |
95 | 94 |
96 event_loop(EVLOOP_ONCE | EVLOOP_NONBLOCK); | 95 event_loop(EVLOOP_ONCE | EVLOOP_NONBLOCK); |
97 | 96 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 for (i = 0; i < 25; i++) { | 179 for (i = 0; i < 25; i++) { |
181 tv = run_once(); | 180 tv = run_once(); |
182 if (tv == NULL) | 181 if (tv == NULL) |
183 exit(1); | 182 exit(1); |
184 fprintf(stdout, "%ld\n", | 183 fprintf(stdout, "%ld\n", |
185 tv->tv_sec * 1000000L + tv->tv_usec); | 184 tv->tv_sec * 1000000L + tv->tv_usec); |
186 } | 185 } |
187 | 186 |
188 exit(0); | 187 exit(0); |
189 } | 188 } |
OLD | NEW |