evdispatch 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/History.txt +3 -0
  2. data/License.txt +20 -0
  3. data/Manifest.txt +96 -0
  4. data/README.txt +73 -0
  5. data/Rakefile +4 -0
  6. data/config/hoe.rb +70 -0
  7. data/config/requirements.rb +15 -0
  8. data/ext/revdispatch/extconf.rb +31 -0
  9. data/ext/revdispatch/libevdispatch/Changelog +0 -0
  10. data/ext/revdispatch/libevdispatch/LICENSE +0 -0
  11. data/ext/revdispatch/libevdispatch/Makefile.am +10 -0
  12. data/ext/revdispatch/libevdispatch/Makefile.in +637 -0
  13. data/ext/revdispatch/libevdispatch/README +3 -0
  14. data/ext/revdispatch/libevdispatch/TODO +5 -0
  15. data/ext/revdispatch/libevdispatch/aclocal.m4 +7459 -0
  16. data/ext/revdispatch/libevdispatch/autogen.sh +11 -0
  17. data/ext/revdispatch/libevdispatch/confdefs.h +32 -0
  18. data/ext/revdispatch/libevdispatch/config.guess +1516 -0
  19. data/ext/revdispatch/libevdispatch/config.h.in +112 -0
  20. data/ext/revdispatch/libevdispatch/config.sub +1626 -0
  21. data/ext/revdispatch/libevdispatch/configure +21949 -0
  22. data/ext/revdispatch/libevdispatch/configure.ac +40 -0
  23. data/ext/revdispatch/libevdispatch/depcomp +584 -0
  24. data/ext/revdispatch/libevdispatch/install-sh +507 -0
  25. data/ext/revdispatch/libevdispatch/libev/Changes +54 -0
  26. data/ext/revdispatch/libevdispatch/libev/LICENSE +25 -0
  27. data/ext/revdispatch/libevdispatch/libev/Makefile.am +18 -0
  28. data/ext/revdispatch/libevdispatch/libev/Makefile.in +677 -0
  29. data/ext/revdispatch/libevdispatch/libev/README +130 -0
  30. data/ext/revdispatch/libevdispatch/libev/aclocal.m4 +7430 -0
  31. data/ext/revdispatch/libevdispatch/libev/autogen.sh +7 -0
  32. data/ext/revdispatch/libevdispatch/libev/config.guess +1516 -0
  33. data/ext/revdispatch/libevdispatch/libev/config.h.in +106 -0
  34. data/ext/revdispatch/libevdispatch/libev/config.sub +1626 -0
  35. data/ext/revdispatch/libevdispatch/libev/configure +21636 -0
  36. data/ext/revdispatch/libevdispatch/libev/configure.ac +18 -0
  37. data/ext/revdispatch/libevdispatch/libev/ev++.h +779 -0
  38. data/ext/revdispatch/libevdispatch/libev/ev.3 +3276 -0
  39. data/ext/revdispatch/libevdispatch/libev/ev.c +2547 -0
  40. data/ext/revdispatch/libevdispatch/libev/ev.h +608 -0
  41. data/ext/revdispatch/libevdispatch/libev/ev.pod +3192 -0
  42. data/ext/revdispatch/libevdispatch/libev/ev_epoll.c +182 -0
  43. data/ext/revdispatch/libevdispatch/libev/ev_kqueue.c +194 -0
  44. data/ext/revdispatch/libevdispatch/libev/ev_poll.c +135 -0
  45. data/ext/revdispatch/libevdispatch/libev/ev_port.c +163 -0
  46. data/ext/revdispatch/libevdispatch/libev/ev_select.c +244 -0
  47. data/ext/revdispatch/libevdispatch/libev/ev_vars.h +157 -0
  48. data/ext/revdispatch/libevdispatch/libev/ev_win32.c +125 -0
  49. data/ext/revdispatch/libevdispatch/libev/ev_wrap.h +144 -0
  50. data/ext/revdispatch/libevdispatch/libev/event.c +404 -0
  51. data/ext/revdispatch/libevdispatch/libev/event.h +152 -0
  52. data/ext/revdispatch/libevdispatch/libev/install-sh +294 -0
  53. data/ext/revdispatch/libevdispatch/libev/libev.m4 +28 -0
  54. data/ext/revdispatch/libevdispatch/libev/ltmain.sh +6930 -0
  55. data/ext/revdispatch/libevdispatch/libev/missing +336 -0
  56. data/ext/revdispatch/libevdispatch/libev/mkinstalldirs +111 -0
  57. data/ext/revdispatch/libevdispatch/ltmain.sh +6930 -0
  58. data/ext/revdispatch/libevdispatch/missing +367 -0
  59. data/ext/revdispatch/libevdispatch/src/Makefile.am +11 -0
  60. data/ext/revdispatch/libevdispatch/src/Makefile.in +486 -0
  61. data/ext/revdispatch/libevdispatch/src/ev_dispatch.cc +264 -0
  62. data/ext/revdispatch/libevdispatch/src/ev_dispatch.h +300 -0
  63. data/ext/revdispatch/libevdispatch/src/ev_http.cc +238 -0
  64. data/ext/revdispatch/libevdispatch/src/ev_http.h +65 -0
  65. data/ext/revdispatch/libevdispatch/test/Makefile.am +16 -0
  66. data/ext/revdispatch/libevdispatch/test/Makefile.in +513 -0
  67. data/ext/revdispatch/libevdispatch/test/helper.rb +94 -0
  68. data/ext/revdispatch/libevdispatch/test/key_test.cc +52 -0
  69. data/ext/revdispatch/libevdispatch/test/next_test.cc +86 -0
  70. data/ext/revdispatch/libevdispatch/test/next_test.rb +8 -0
  71. data/ext/revdispatch/libevdispatch/test/server.rb +9 -0
  72. data/ext/revdispatch/revdispatch.cc +151 -0
  73. data/ext/revdispatch/server.rb +60 -0
  74. data/ext/revdispatch/test.rb +100 -0
  75. data/lib/evdispatch/loop.rb +16 -0
  76. data/lib/evdispatch/version.rb +9 -0
  77. data/lib/evdispatch.rb +8 -0
  78. data/log/debug.log +0 -0
  79. data/script/console +10 -0
  80. data/script/destroy +14 -0
  81. data/script/generate +14 -0
  82. data/script/txt2html +74 -0
  83. data/setup.rb +1585 -0
  84. data/tasks/deployment.rake +34 -0
  85. data/tasks/environment.rake +7 -0
  86. data/tasks/extconf/revdispatch.rake +43 -0
  87. data/tasks/extconf.rake +13 -0
  88. data/tasks/website.rake +17 -0
  89. data/test/test_evdispatch.rb +11 -0
  90. data/test/test_helper.rb +3 -0
  91. data/test/test_revdispatch_extn.rb +14 -0
  92. data/website/index.html +128 -0
  93. data/website/index.txt +55 -0
  94. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  95. data/website/stylesheets/screen.css +138 -0
  96. data/website/template.html.erb +49 -0
  97. metadata +157 -0
@@ -0,0 +1,182 @@
1
+ /*
2
+ * libev epoll fd activity backend
3
+ *
4
+ * Copyright (c) 2007 Marc Alexander Lehmann <libev@schmorp.de>
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without modifica-
8
+ * tion, are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ *
13
+ * 2. Redistributions in binary form must reproduce the above copyright
14
+ * notice, this list of conditions and the following disclaimer in the
15
+ * documentation and/or other materials provided with the distribution.
16
+ *
17
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
18
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER-
19
+ * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
20
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE-
21
+ * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH-
25
+ * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
26
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ *
28
+ * Alternatively, the contents of this file may be used under the terms of
29
+ * the GNU General Public License ("GPL") version 2 or any later version,
30
+ * in which case the provisions of the GPL are applicable instead of
31
+ * the above. If you wish to allow the use of your version of this file
32
+ * only under the terms of the GPL and not to allow others to use your
33
+ * version of this file under the BSD license, indicate your decision
34
+ * by deleting the provisions above and replace them with the notice
35
+ * and other provisions required by the GPL. If you do not delete the
36
+ * provisions above, a recipient may use your version of this file under
37
+ * either the BSD or the GPL.
38
+ */
39
+
40
+ /*
41
+ * general notes about epoll:
42
+ *
43
+ * a) epoll silently removes fds from the fd set. as nothing tells us
44
+ * that an fd has been removed otherwise, we have to continually
45
+ * "rearm" fds that we suspect *might* have changed (same
46
+ * problem with kqueue, but much less costly there).
47
+ * b) the fact that ADD != MOD creates a lot of extra syscalls due to a)
48
+ * and seems not to have any advantage.
49
+ * c) the inability to handle fork or file descriptors (think dup)
50
+ * limits the applicability over poll, so this is not a generic
51
+ * poll replacement.
52
+ *
53
+ * lots of "weird code" and complication handling in this file is due
54
+ * to these design problems with epoll, as we try very hard to avoid
55
+ * epoll_ctl syscalls for common usage patterns.
56
+ */
57
+
58
+ #include <sys/epoll.h>
59
+
60
+ static void
61
+ epoll_modify (EV_P_ int fd, int oev, int nev)
62
+ {
63
+ struct epoll_event ev;
64
+
65
+ /*
66
+ * we handle EPOLL_CTL_DEL by ignoring it here
67
+ * on the assumption that the fd is gone anyways
68
+ * if that is wrong, we have to handle the spurious
69
+ * event in epoll_poll.
70
+ */
71
+ if (!nev)
72
+ return;
73
+
74
+ ev.data.u64 = fd; /* use u64 to fully initialise the struct, for nicer strace etc. */
75
+ ev.events = (nev & EV_READ ? EPOLLIN : 0)
76
+ | (nev & EV_WRITE ? EPOLLOUT : 0);
77
+
78
+ if (expect_true (!epoll_ctl (backend_fd, oev ? EPOLL_CTL_MOD : EPOLL_CTL_ADD, fd, &ev)))
79
+ return;
80
+
81
+ if (expect_true (errno == ENOENT))
82
+ {
83
+ /* on ENOENT the fd went away, so try to do the right thing */
84
+ if (!nev)
85
+ return;
86
+
87
+ if (!epoll_ctl (backend_fd, EPOLL_CTL_ADD, fd, &ev))
88
+ return;
89
+ }
90
+ else if (expect_true (errno == EEXIST))
91
+ {
92
+ /* on EEXIST we ignored a previous DEL */
93
+ if (!epoll_ctl (backend_fd, EPOLL_CTL_MOD, fd, &ev))
94
+ return;
95
+ }
96
+
97
+ fd_kill (EV_A_ fd);
98
+ }
99
+
100
+ static void
101
+ epoll_poll (EV_P_ ev_tstamp timeout)
102
+ {
103
+ int i;
104
+ int eventcnt = epoll_wait (backend_fd, epoll_events, epoll_eventmax, (int)ceil (timeout * 1000.));
105
+
106
+ if (expect_false (eventcnt < 0))
107
+ {
108
+ if (errno != EINTR)
109
+ syserr ("(libev) epoll_wait");
110
+
111
+ return;
112
+ }
113
+
114
+ for (i = 0; i < eventcnt; ++i)
115
+ {
116
+ struct epoll_event *ev = epoll_events + i;
117
+
118
+ int fd = ev->data.u64;
119
+ int got = (ev->events & (EPOLLOUT | EPOLLERR | EPOLLHUP) ? EV_WRITE : 0)
120
+ | (ev->events & (EPOLLIN | EPOLLERR | EPOLLHUP) ? EV_READ : 0);
121
+ int want = anfds [fd].events;
122
+
123
+ if (expect_false (got & ~want))
124
+ {
125
+ /* we received an event but are not interested in it, try mod or del */
126
+ ev->events = (want & EV_READ ? EPOLLIN : 0)
127
+ | (want & EV_WRITE ? EPOLLOUT : 0);
128
+
129
+ epoll_ctl (backend_fd, want ? EPOLL_CTL_MOD : EPOLL_CTL_DEL, fd, ev);
130
+ }
131
+
132
+ fd_event (EV_A_ fd, got);
133
+ }
134
+
135
+ /* if the receive array was full, increase its size */
136
+ if (expect_false (eventcnt == epoll_eventmax))
137
+ {
138
+ ev_free (epoll_events);
139
+ epoll_eventmax = array_nextsize (sizeof (struct epoll_event), epoll_eventmax, epoll_eventmax + 1);
140
+ epoll_events = (struct epoll_event *)ev_malloc (sizeof (struct epoll_event) * epoll_eventmax);
141
+ }
142
+ }
143
+
144
+ int inline_size
145
+ epoll_init (EV_P_ int flags)
146
+ {
147
+ backend_fd = epoll_create (256);
148
+
149
+ if (backend_fd < 0)
150
+ return 0;
151
+
152
+ fcntl (backend_fd, F_SETFD, FD_CLOEXEC);
153
+
154
+ backend_fudge = 0.; /* kernel sources seem to indicate this to be zero */
155
+ backend_modify = epoll_modify;
156
+ backend_poll = epoll_poll;
157
+
158
+ epoll_eventmax = 64; /* intiial number of events receivable per poll */
159
+ epoll_events = (struct epoll_event *)ev_malloc (sizeof (struct epoll_event) * epoll_eventmax);
160
+
161
+ return EVBACKEND_EPOLL;
162
+ }
163
+
164
+ void inline_size
165
+ epoll_destroy (EV_P)
166
+ {
167
+ ev_free (epoll_events);
168
+ }
169
+
170
+ void inline_size
171
+ epoll_fork (EV_P)
172
+ {
173
+ close (backend_fd);
174
+
175
+ while ((backend_fd = epoll_create (256)) < 0)
176
+ syserr ("(libev) epoll_create");
177
+
178
+ fcntl (backend_fd, F_SETFD, FD_CLOEXEC);
179
+
180
+ fd_rearm_all (EV_A);
181
+ }
182
+
@@ -0,0 +1,194 @@
1
+ /*
2
+ * libev kqueue backend
3
+ *
4
+ * Copyright (c) 2007 Marc Alexander Lehmann <libev@schmorp.de>
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without modifica-
8
+ * tion, are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ *
13
+ * 2. Redistributions in binary form must reproduce the above copyright
14
+ * notice, this list of conditions and the following disclaimer in the
15
+ * documentation and/or other materials provided with the distribution.
16
+ *
17
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
18
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER-
19
+ * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
20
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE-
21
+ * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH-
25
+ * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
26
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ *
28
+ * Alternatively, the contents of this file may be used under the terms of
29
+ * the GNU General Public License ("GPL") version 2 or any later version,
30
+ * in which case the provisions of the GPL are applicable instead of
31
+ * the above. If you wish to allow the use of your version of this file
32
+ * only under the terms of the GPL and not to allow others to use your
33
+ * version of this file under the BSD license, indicate your decision
34
+ * by deleting the provisions above and replace them with the notice
35
+ * and other provisions required by the GPL. If you do not delete the
36
+ * provisions above, a recipient may use your version of this file under
37
+ * either the BSD or the GPL.
38
+ */
39
+
40
+ #include <sys/types.h>
41
+ #include <sys/time.h>
42
+ #include <sys/queue.h>
43
+ #include <sys/event.h>
44
+ #include <string.h>
45
+ #include <errno.h>
46
+
47
+ void inline_speed
48
+ kqueue_change (EV_P_ int fd, int filter, int flags, int fflags)
49
+ {
50
+ ++kqueue_changecnt;
51
+ array_needsize (struct kevent, kqueue_changes, kqueue_changemax, kqueue_changecnt, EMPTY2);
52
+
53
+ EV_SET (&kqueue_changes [kqueue_changecnt - 1], fd, filter, flags, fflags, 0, 0);
54
+ }
55
+
56
+ #ifndef NOTE_EOF
57
+ # define NOTE_EOF 0
58
+ #endif
59
+
60
+ static void
61
+ kqueue_modify (EV_P_ int fd, int oev, int nev)
62
+ {
63
+ if (oev != nev)
64
+ {
65
+ if (oev & EV_READ)
66
+ kqueue_change (EV_A_ fd, EVFILT_READ , EV_DELETE, 0);
67
+
68
+ if (oev & EV_WRITE)
69
+ kqueue_change (EV_A_ fd, EVFILT_WRITE, EV_DELETE, 0);
70
+ }
71
+
72
+ /* to detect close/reopen reliably, we have to re-add */
73
+ /* event requests even when oev == nev */
74
+
75
+ if (nev & EV_READ)
76
+ kqueue_change (EV_A_ fd, EVFILT_READ , EV_ADD, NOTE_EOF);
77
+
78
+ if (nev & EV_WRITE)
79
+ kqueue_change (EV_A_ fd, EVFILT_WRITE, EV_ADD, NOTE_EOF);
80
+ }
81
+
82
+ static void
83
+ kqueue_poll (EV_P_ ev_tstamp timeout)
84
+ {
85
+ int res, i;
86
+ struct timespec ts;
87
+
88
+ /* need to resize so there is enough space for errors */
89
+ if (kqueue_changecnt > kqueue_eventmax)
90
+ {
91
+ ev_free (kqueue_events);
92
+ kqueue_eventmax = array_nextsize (sizeof (struct kevent), kqueue_eventmax, kqueue_changecnt);
93
+ kqueue_events = (struct kevent *)ev_malloc (sizeof (struct kevent) * kqueue_eventmax);
94
+ }
95
+
96
+ ts.tv_sec = (time_t)timeout;
97
+ ts.tv_nsec = (long)((timeout - (ev_tstamp)ts.tv_sec) * 1e9);
98
+ res = kevent (backend_fd, kqueue_changes, kqueue_changecnt, kqueue_events, kqueue_eventmax, &ts);
99
+ kqueue_changecnt = 0;
100
+
101
+ if (expect_false (res < 0))
102
+ {
103
+ if (errno != EINTR)
104
+ syserr ("(libev) kevent");
105
+
106
+ return;
107
+ }
108
+
109
+ for (i = 0; i < res; ++i)
110
+ {
111
+ int fd = kqueue_events [i].ident;
112
+
113
+ if (expect_false (kqueue_events [i].flags & EV_ERROR))
114
+ {
115
+ int err = kqueue_events [i].data;
116
+
117
+ /* we are only interested in errors for fds that we are interested in :) */
118
+ if (anfds [fd].events)
119
+ {
120
+ if (err == ENOENT) /* resubmit changes on ENOENT */
121
+ kqueue_modify (EV_A_ fd, 0, anfds [fd].events);
122
+ else if (err == EBADF) /* on EBADF, we re-check the fd */
123
+ {
124
+ if (fd_valid (fd))
125
+ kqueue_modify (EV_A_ fd, 0, anfds [fd].events);
126
+ else
127
+ fd_kill (EV_A_ fd);
128
+ }
129
+ else /* on all other errors, we error out on the fd */
130
+ fd_kill (EV_A_ fd);
131
+ }
132
+ }
133
+ else
134
+ fd_event (
135
+ EV_A_
136
+ fd,
137
+ kqueue_events [i].filter == EVFILT_READ ? EV_READ
138
+ : kqueue_events [i].filter == EVFILT_WRITE ? EV_WRITE
139
+ : 0
140
+ );
141
+ }
142
+
143
+ if (expect_false (res == kqueue_eventmax))
144
+ {
145
+ ev_free (kqueue_events);
146
+ kqueue_eventmax = array_nextsize (sizeof (struct kevent), kqueue_eventmax, kqueue_eventmax + 1);
147
+ kqueue_events = (struct kevent *)ev_malloc (sizeof (struct kevent) * kqueue_eventmax);
148
+ }
149
+ }
150
+
151
+ int inline_size
152
+ kqueue_init (EV_P_ int flags)
153
+ {
154
+ /* Initalize the kernel queue */
155
+ if ((backend_fd = kqueue ()) < 0)
156
+ return 0;
157
+
158
+ fcntl (backend_fd, F_SETFD, FD_CLOEXEC); /* not sure if necessary, hopefully doesn't hurt */
159
+
160
+ backend_fudge = 0.;
161
+ backend_modify = kqueue_modify;
162
+ backend_poll = kqueue_poll;
163
+
164
+ kqueue_eventmax = 64; /* initial number of events receivable per poll */
165
+ kqueue_events = (struct kevent *)ev_malloc (sizeof (struct kevent) * kqueue_eventmax);
166
+
167
+ kqueue_changes = 0;
168
+ kqueue_changemax = 0;
169
+ kqueue_changecnt = 0;
170
+
171
+ return EVBACKEND_KQUEUE;
172
+ }
173
+
174
+ void inline_size
175
+ kqueue_destroy (EV_P)
176
+ {
177
+ ev_free (kqueue_events);
178
+ ev_free (kqueue_changes);
179
+ }
180
+
181
+ void inline_size
182
+ kqueue_fork (EV_P)
183
+ {
184
+ close (backend_fd);
185
+
186
+ while ((backend_fd = kqueue ()) < 0)
187
+ syserr ("(libev) kqueue");
188
+
189
+ fcntl (backend_fd, F_SETFD, FD_CLOEXEC);
190
+
191
+ /* re-register interest in fds */
192
+ fd_rearm_all (EV_A);
193
+ }
194
+
@@ -0,0 +1,135 @@
1
+ /*
2
+ * libev poll fd activity backend
3
+ *
4
+ * Copyright (c) 2007 Marc Alexander Lehmann <libev@schmorp.de>
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without modifica-
8
+ * tion, are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ *
13
+ * 2. Redistributions in binary form must reproduce the above copyright
14
+ * notice, this list of conditions and the following disclaimer in the
15
+ * documentation and/or other materials provided with the distribution.
16
+ *
17
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
18
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER-
19
+ * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
20
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE-
21
+ * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH-
25
+ * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
26
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ *
28
+ * Alternatively, the contents of this file may be used under the terms of
29
+ * the GNU General Public License ("GPL") version 2 or any later version,
30
+ * in which case the provisions of the GPL are applicable instead of
31
+ * the above. If you wish to allow the use of your version of this file
32
+ * only under the terms of the GPL and not to allow others to use your
33
+ * version of this file under the BSD license, indicate your decision
34
+ * by deleting the provisions above and replace them with the notice
35
+ * and other provisions required by the GPL. If you do not delete the
36
+ * provisions above, a recipient may use your version of this file under
37
+ * either the BSD or the GPL.
38
+ */
39
+
40
+ #include <poll.h>
41
+
42
+ void inline_size
43
+ pollidx_init (int *base, int count)
44
+ {
45
+ while (count--)
46
+ *base++ = -1;
47
+ }
48
+
49
+ static void
50
+ poll_modify (EV_P_ int fd, int oev, int nev)
51
+ {
52
+ int idx;
53
+
54
+ if (oev == nev)
55
+ return;
56
+
57
+ array_needsize (int, pollidxs, pollidxmax, fd + 1, pollidx_init);
58
+
59
+ idx = pollidxs [fd];
60
+
61
+ if (idx < 0) /* need to allocate a new pollfd */
62
+ {
63
+ pollidxs [fd] = idx = pollcnt++;
64
+ array_needsize (struct pollfd, polls, pollmax, pollcnt, EMPTY2);
65
+ polls [idx].fd = fd;
66
+ }
67
+
68
+ assert (polls [idx].fd == fd);
69
+
70
+ if (nev)
71
+ polls [idx].events =
72
+ (nev & EV_READ ? POLLIN : 0)
73
+ | (nev & EV_WRITE ? POLLOUT : 0);
74
+ else /* remove pollfd */
75
+ {
76
+ pollidxs [fd] = -1;
77
+
78
+ if (expect_true (idx < --pollcnt))
79
+ {
80
+ polls [idx] = polls [pollcnt];
81
+ pollidxs [polls [idx].fd] = idx;
82
+ }
83
+ }
84
+ }
85
+
86
+ static void
87
+ poll_poll (EV_P_ ev_tstamp timeout)
88
+ {
89
+ int i;
90
+ int res = poll (polls, pollcnt, (int)ceil (timeout * 1000.));
91
+
92
+ if (expect_false (res < 0))
93
+ {
94
+ if (errno == EBADF)
95
+ fd_ebadf (EV_A);
96
+ else if (errno == ENOMEM && !syserr_cb)
97
+ fd_enomem (EV_A);
98
+ else if (errno != EINTR)
99
+ syserr ("(libev) poll");
100
+
101
+ return;
102
+ }
103
+
104
+ for (i = 0; i < pollcnt; ++i)
105
+ if (expect_false (polls [i].revents & POLLNVAL))
106
+ fd_kill (EV_A_ polls [i].fd);
107
+ else
108
+ fd_event (
109
+ EV_A_
110
+ polls [i].fd,
111
+ (polls [i].revents & (POLLOUT | POLLERR | POLLHUP) ? EV_WRITE : 0)
112
+ | (polls [i].revents & (POLLIN | POLLERR | POLLHUP) ? EV_READ : 0)
113
+ );
114
+ }
115
+
116
+ int inline_size
117
+ poll_init (EV_P_ int flags)
118
+ {
119
+ backend_fudge = 0.; /* posix says this is zero */
120
+ backend_modify = poll_modify;
121
+ backend_poll = poll_poll;
122
+
123
+ pollidxs = 0; pollidxmax = 0;
124
+ polls = 0; pollmax = 0; pollcnt = 0;
125
+
126
+ return EVBACKEND_POLL;
127
+ }
128
+
129
+ void inline_size
130
+ poll_destroy (EV_P)
131
+ {
132
+ ev_free (pollidxs);
133
+ ev_free (polls);
134
+ }
135
+
@@ -0,0 +1,163 @@
1
+ /*
2
+ * libev solaris event port backend
3
+ *
4
+ * Copyright (c) 2007 Marc Alexander Lehmann <libev@schmorp.de>
5
+ * All rights reserved.
6
+ *
7
+ * Redistribution and use in source and binary forms, with or without modifica-
8
+ * tion, are permitted provided that the following conditions are met:
9
+ *
10
+ * 1. Redistributions of source code must retain the above copyright notice,
11
+ * this list of conditions and the following disclaimer.
12
+ *
13
+ * 2. Redistributions in binary form must reproduce the above copyright
14
+ * notice, this list of conditions and the following disclaimer in the
15
+ * documentation and/or other materials provided with the distribution.
16
+ *
17
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
18
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER-
19
+ * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
20
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE-
21
+ * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH-
25
+ * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
26
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ *
28
+ * Alternatively, the contents of this file may be used under the terms of
29
+ * the GNU General Public License ("GPL") version 2 or any later version,
30
+ * in which case the provisions of the GPL are applicable instead of
31
+ * the above. If you wish to allow the use of your version of this file
32
+ * only under the terms of the GPL and not to allow others to use your
33
+ * version of this file under the BSD license, indicate your decision
34
+ * by deleting the provisions above and replace them with the notice
35
+ * and other provisions required by the GPL. If you do not delete the
36
+ * provisions above, a recipient may use your version of this file under
37
+ * either the BSD or the GPL.
38
+ */
39
+
40
+ #include <sys/types.h>
41
+ #include <sys/time.h>
42
+ #include <poll.h>
43
+ #include <port.h>
44
+ #include <string.h>
45
+ #include <errno.h>
46
+
47
+ void inline_speed
48
+ port_associate_and_check (EV_P_ int fd, int ev)
49
+ {
50
+ if (0 >
51
+ port_associate (
52
+ backend_fd, PORT_SOURCE_FD, fd,
53
+ (ev & EV_READ ? POLLIN : 0)
54
+ | (ev & EV_WRITE ? POLLOUT : 0),
55
+ 0
56
+ )
57
+ )
58
+ {
59
+ if (errno == EBADFD)
60
+ fd_kill (EV_A_ fd);
61
+ else
62
+ syserr ("(libev) port_associate");
63
+ }
64
+ }
65
+
66
+ static void
67
+ port_modify (EV_P_ int fd, int oev, int nev)
68
+ {
69
+ /* we need to reassociate no matter what, as closes are
70
+ * once more silently being discarded.
71
+ */
72
+ if (!nev)
73
+ {
74
+ if (oev)
75
+ port_dissociate (backend_fd, PORT_SOURCE_FD, fd);
76
+ }
77
+ else
78
+ port_associate_and_check (EV_A_ fd, nev);
79
+ }
80
+
81
+ static void
82
+ port_poll (EV_P_ ev_tstamp timeout)
83
+ {
84
+ int res, i;
85
+ struct timespec ts;
86
+ uint_t nget = 1;
87
+
88
+ ts.tv_sec = (time_t)timeout;
89
+ ts.tv_nsec = (long)(timeout - (ev_tstamp)ts.tv_sec) * 1e9;
90
+ res = port_getn (backend_fd, port_events, port_eventmax, &nget, &ts);
91
+
92
+ if (res < 0)
93
+ {
94
+ if (errno != EINTR && errno != ETIME)
95
+ syserr ("(libev) port_getn");
96
+
97
+ return;
98
+ }
99
+
100
+ for (i = 0; i < nget; ++i)
101
+ {
102
+ if (port_events [i].portev_source == PORT_SOURCE_FD)
103
+ {
104
+ int fd = port_events [i].portev_object;
105
+
106
+ fd_event (
107
+ EV_A_
108
+ fd,
109
+ (port_events [i].portev_events & (POLLOUT | POLLERR | POLLHUP) ? EV_WRITE : 0)
110
+ | (port_events [i].portev_events & (POLLIN | POLLERR | POLLHUP) ? EV_READ : 0)
111
+ );
112
+
113
+ port_associate_and_check (EV_A_ fd, anfds [fd].events);
114
+ }
115
+ }
116
+
117
+ if (expect_false (nget == port_eventmax))
118
+ {
119
+ ev_free (port_events);
120
+ port_eventmax = array_nextsize (sizeof (port_event_t), port_eventmax, port_eventmax + 1);
121
+ port_events = (port_event_t *)ev_malloc (sizeof (port_event_t) * port_eventmax);
122
+ }
123
+ }
124
+
125
+ int inline_size
126
+ port_init (EV_P_ int flags)
127
+ {
128
+ /* Initalize the kernel queue */
129
+ if ((backend_fd = port_create ()) < 0)
130
+ return 0;
131
+
132
+ fcntl (backend_fd, F_SETFD, FD_CLOEXEC); /* not sure if necessary, hopefully doesn't hurt */
133
+
134
+ backend_fudge = 1e-3; /* needed to compensate for port_getn returning early */
135
+ backend_modify = port_modify;
136
+ backend_poll = port_poll;
137
+
138
+ port_eventmax = 64; /* intiial number of events receivable per poll */
139
+ port_events = (port_event_t *)ev_malloc (sizeof (port_event_t) * port_eventmax);
140
+
141
+ return EVBACKEND_PORT;
142
+ }
143
+
144
+ void inline_size
145
+ port_destroy (EV_P)
146
+ {
147
+ ev_free (port_events);
148
+ }
149
+
150
+ void inline_size
151
+ port_fork (EV_P)
152
+ {
153
+ close (backend_fd);
154
+
155
+ while ((backend_fd = port_create ()) < 0)
156
+ syserr ("(libev) port");
157
+
158
+ fcntl (backend_fd, F_SETFD, FD_CLOEXEC);
159
+
160
+ /* re-register interest in fds */
161
+ fd_rearm_all (EV_A);
162
+ }
163
+