polyphony 0.43.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (221) hide show
  1. checksums.yaml +7 -0
  2. data/.gitbook.yaml +4 -0
  3. data/.github/workflows/test.yml +29 -0
  4. data/.gitignore +59 -0
  5. data/.rubocop.yml +175 -0
  6. data/CHANGELOG.md +393 -0
  7. data/Gemfile +3 -0
  8. data/Gemfile.lock +141 -0
  9. data/LICENSE +21 -0
  10. data/README.md +51 -0
  11. data/Rakefile +26 -0
  12. data/TODO.md +201 -0
  13. data/bin/polyphony-debug +87 -0
  14. data/docs/_config.yml +64 -0
  15. data/docs/_includes/head.html +40 -0
  16. data/docs/_includes/title.html +1 -0
  17. data/docs/_sass/custom/custom.scss +10 -0
  18. data/docs/_sass/overrides.scss +0 -0
  19. data/docs/_user-guide/all-about-timers.md +126 -0
  20. data/docs/_user-guide/index.md +9 -0
  21. data/docs/_user-guide/web-server.md +136 -0
  22. data/docs/api-reference/exception.md +27 -0
  23. data/docs/api-reference/fiber.md +425 -0
  24. data/docs/api-reference/index.md +9 -0
  25. data/docs/api-reference/io.md +36 -0
  26. data/docs/api-reference/object.md +99 -0
  27. data/docs/api-reference/polyphony-baseexception.md +33 -0
  28. data/docs/api-reference/polyphony-cancel.md +26 -0
  29. data/docs/api-reference/polyphony-moveon.md +24 -0
  30. data/docs/api-reference/polyphony-net.md +20 -0
  31. data/docs/api-reference/polyphony-process.md +28 -0
  32. data/docs/api-reference/polyphony-resourcepool.md +59 -0
  33. data/docs/api-reference/polyphony-restart.md +18 -0
  34. data/docs/api-reference/polyphony-terminate.md +18 -0
  35. data/docs/api-reference/polyphony-threadpool.md +67 -0
  36. data/docs/api-reference/polyphony-throttler.md +77 -0
  37. data/docs/api-reference/polyphony.md +36 -0
  38. data/docs/api-reference/thread.md +88 -0
  39. data/docs/assets/img/echo-fibers.svg +1 -0
  40. data/docs/assets/img/sleeping-fiber.svg +1 -0
  41. data/docs/faq.md +195 -0
  42. data/docs/favicon.ico +0 -0
  43. data/docs/getting-started/index.md +10 -0
  44. data/docs/getting-started/installing.md +34 -0
  45. data/docs/getting-started/overview.md +486 -0
  46. data/docs/getting-started/tutorial.md +359 -0
  47. data/docs/index.md +94 -0
  48. data/docs/main-concepts/concurrency.md +151 -0
  49. data/docs/main-concepts/design-principles.md +161 -0
  50. data/docs/main-concepts/exception-handling.md +291 -0
  51. data/docs/main-concepts/extending.md +89 -0
  52. data/docs/main-concepts/fiber-scheduling.md +197 -0
  53. data/docs/main-concepts/index.md +9 -0
  54. data/docs/polyphony-logo.png +0 -0
  55. data/examples/adapters/concurrent-ruby.rb +9 -0
  56. data/examples/adapters/pg_client.rb +36 -0
  57. data/examples/adapters/pg_notify.rb +35 -0
  58. data/examples/adapters/pg_pool.rb +43 -0
  59. data/examples/adapters/pg_transaction.rb +31 -0
  60. data/examples/adapters/redis_blpop.rb +12 -0
  61. data/examples/adapters/redis_channels.rb +122 -0
  62. data/examples/adapters/redis_client.rb +19 -0
  63. data/examples/adapters/redis_pubsub.rb +26 -0
  64. data/examples/adapters/redis_pubsub_perf.rb +68 -0
  65. data/examples/core/01-spinning-up-fibers.rb +18 -0
  66. data/examples/core/02-awaiting-fibers.rb +20 -0
  67. data/examples/core/03-interrupting.rb +39 -0
  68. data/examples/core/04-handling-signals.rb +19 -0
  69. data/examples/core/xx-agent.rb +102 -0
  70. data/examples/core/xx-at_exit.rb +29 -0
  71. data/examples/core/xx-caller.rb +12 -0
  72. data/examples/core/xx-channels.rb +45 -0
  73. data/examples/core/xx-daemon.rb +14 -0
  74. data/examples/core/xx-deadlock.rb +8 -0
  75. data/examples/core/xx-deferring-an-operation.rb +14 -0
  76. data/examples/core/xx-erlang-style-genserver.rb +81 -0
  77. data/examples/core/xx-exception-backtrace.rb +40 -0
  78. data/examples/core/xx-fork-cleanup.rb +22 -0
  79. data/examples/core/xx-fork-spin.rb +42 -0
  80. data/examples/core/xx-fork-terminate.rb +27 -0
  81. data/examples/core/xx-forking.rb +24 -0
  82. data/examples/core/xx-move_on.rb +23 -0
  83. data/examples/core/xx-pingpong.rb +18 -0
  84. data/examples/core/xx-queue-async.rb +120 -0
  85. data/examples/core/xx-readpartial.rb +18 -0
  86. data/examples/core/xx-recurrent-timer.rb +12 -0
  87. data/examples/core/xx-resource_delegate.rb +31 -0
  88. data/examples/core/xx-signals.rb +16 -0
  89. data/examples/core/xx-sleep-forever.rb +9 -0
  90. data/examples/core/xx-sleeping.rb +25 -0
  91. data/examples/core/xx-snooze-starve.rb +16 -0
  92. data/examples/core/xx-spin-fork.rb +49 -0
  93. data/examples/core/xx-spin_error_backtrace.rb +33 -0
  94. data/examples/core/xx-state-machine.rb +51 -0
  95. data/examples/core/xx-stop.rb +20 -0
  96. data/examples/core/xx-supervise-process.rb +30 -0
  97. data/examples/core/xx-supervisors.rb +21 -0
  98. data/examples/core/xx-thread-selector-sleep.rb +51 -0
  99. data/examples/core/xx-thread-selector-snooze.rb +46 -0
  100. data/examples/core/xx-thread-sleep.rb +17 -0
  101. data/examples/core/xx-thread-snooze.rb +34 -0
  102. data/examples/core/xx-thread_pool.rb +17 -0
  103. data/examples/core/xx-throttling.rb +18 -0
  104. data/examples/core/xx-timeout.rb +10 -0
  105. data/examples/core/xx-timer-gc.rb +17 -0
  106. data/examples/core/xx-trace.rb +79 -0
  107. data/examples/core/xx-using-a-mutex.rb +21 -0
  108. data/examples/core/xx-worker-thread.rb +30 -0
  109. data/examples/io/tunnel.rb +48 -0
  110. data/examples/io/xx-backticks.rb +11 -0
  111. data/examples/io/xx-echo_client.rb +25 -0
  112. data/examples/io/xx-echo_client_from_stdin.rb +21 -0
  113. data/examples/io/xx-echo_pipe.rb +16 -0
  114. data/examples/io/xx-echo_server.rb +17 -0
  115. data/examples/io/xx-echo_server_with_timeout.rb +34 -0
  116. data/examples/io/xx-echo_stdin.rb +14 -0
  117. data/examples/io/xx-happy-eyeballs.rb +36 -0
  118. data/examples/io/xx-httparty.rb +38 -0
  119. data/examples/io/xx-irb.rb +17 -0
  120. data/examples/io/xx-net-http.rb +15 -0
  121. data/examples/io/xx-open.rb +16 -0
  122. data/examples/io/xx-switch.rb +15 -0
  123. data/examples/io/xx-system.rb +11 -0
  124. data/examples/io/xx-tcpserver.rb +15 -0
  125. data/examples/io/xx-tcpsocket.rb +18 -0
  126. data/examples/io/xx-zip.rb +19 -0
  127. data/examples/performance/fiber_transfer.rb +47 -0
  128. data/examples/performance/fs_read.rb +38 -0
  129. data/examples/performance/mem-usage.rb +56 -0
  130. data/examples/performance/messaging.rb +29 -0
  131. data/examples/performance/multi_snooze.rb +33 -0
  132. data/examples/performance/snooze.rb +39 -0
  133. data/examples/performance/snooze_raw.rb +39 -0
  134. data/examples/performance/thread-vs-fiber/polyphony_mt_server.rb +74 -0
  135. data/examples/performance/thread-vs-fiber/polyphony_server.rb +45 -0
  136. data/examples/performance/thread-vs-fiber/polyphony_server_read_loop.rb +58 -0
  137. data/examples/performance/thread-vs-fiber/threaded_server.rb +27 -0
  138. data/examples/performance/thread-vs-fiber/xx-httparty_multi.rb +36 -0
  139. data/examples/performance/thread-vs-fiber/xx-httparty_threaded.rb +29 -0
  140. data/examples/performance/thread_pool_perf.rb +63 -0
  141. data/examples/performance/xx-array.rb +11 -0
  142. data/examples/performance/xx-fiber-switch.rb +9 -0
  143. data/examples/performance/xx-snooze.rb +15 -0
  144. data/examples/xx-spin.rb +32 -0
  145. data/ext/libev/Changes +548 -0
  146. data/ext/libev/LICENSE +37 -0
  147. data/ext/libev/README +59 -0
  148. data/ext/libev/README.embed +3 -0
  149. data/ext/libev/ev.c +5279 -0
  150. data/ext/libev/ev.h +856 -0
  151. data/ext/libev/ev_epoll.c +296 -0
  152. data/ext/libev/ev_kqueue.c +224 -0
  153. data/ext/libev/ev_linuxaio.c +642 -0
  154. data/ext/libev/ev_poll.c +156 -0
  155. data/ext/libev/ev_port.c +192 -0
  156. data/ext/libev/ev_select.c +316 -0
  157. data/ext/libev/ev_vars.h +215 -0
  158. data/ext/libev/ev_win32.c +162 -0
  159. data/ext/libev/ev_wrap.h +216 -0
  160. data/ext/libev/test_libev_win32.c +123 -0
  161. data/ext/polyphony/extconf.rb +20 -0
  162. data/ext/polyphony/fiber.c +109 -0
  163. data/ext/polyphony/libev.c +2 -0
  164. data/ext/polyphony/libev.h +9 -0
  165. data/ext/polyphony/libev_agent.c +882 -0
  166. data/ext/polyphony/polyphony.c +71 -0
  167. data/ext/polyphony/polyphony.h +97 -0
  168. data/ext/polyphony/polyphony_ext.c +21 -0
  169. data/ext/polyphony/queue.c +168 -0
  170. data/ext/polyphony/ring_buffer.c +96 -0
  171. data/ext/polyphony/ring_buffer.h +28 -0
  172. data/ext/polyphony/thread.c +208 -0
  173. data/ext/polyphony/tracing.c +11 -0
  174. data/lib/polyphony.rb +136 -0
  175. data/lib/polyphony/adapters/fs.rb +19 -0
  176. data/lib/polyphony/adapters/irb.rb +52 -0
  177. data/lib/polyphony/adapters/postgres.rb +110 -0
  178. data/lib/polyphony/adapters/process.rb +33 -0
  179. data/lib/polyphony/adapters/redis.rb +67 -0
  180. data/lib/polyphony/adapters/trace.rb +138 -0
  181. data/lib/polyphony/core/channel.rb +46 -0
  182. data/lib/polyphony/core/exceptions.rb +36 -0
  183. data/lib/polyphony/core/global_api.rb +124 -0
  184. data/lib/polyphony/core/resource_pool.rb +117 -0
  185. data/lib/polyphony/core/sync.rb +21 -0
  186. data/lib/polyphony/core/thread_pool.rb +64 -0
  187. data/lib/polyphony/core/throttler.rb +41 -0
  188. data/lib/polyphony/event.rb +17 -0
  189. data/lib/polyphony/extensions/core.rb +174 -0
  190. data/lib/polyphony/extensions/fiber.rb +379 -0
  191. data/lib/polyphony/extensions/io.rb +221 -0
  192. data/lib/polyphony/extensions/openssl.rb +81 -0
  193. data/lib/polyphony/extensions/socket.rb +150 -0
  194. data/lib/polyphony/extensions/thread.rb +108 -0
  195. data/lib/polyphony/net.rb +77 -0
  196. data/lib/polyphony/version.rb +5 -0
  197. data/polyphony.gemspec +40 -0
  198. data/test/coverage.rb +54 -0
  199. data/test/eg.rb +27 -0
  200. data/test/helper.rb +56 -0
  201. data/test/q.rb +24 -0
  202. data/test/run.rb +5 -0
  203. data/test/stress.rb +25 -0
  204. data/test/test_agent.rb +130 -0
  205. data/test/test_event.rb +59 -0
  206. data/test/test_ext.rb +196 -0
  207. data/test/test_fiber.rb +988 -0
  208. data/test/test_global_api.rb +352 -0
  209. data/test/test_io.rb +249 -0
  210. data/test/test_kernel.rb +57 -0
  211. data/test/test_process_supervision.rb +46 -0
  212. data/test/test_queue.rb +112 -0
  213. data/test/test_resource_pool.rb +138 -0
  214. data/test/test_signal.rb +100 -0
  215. data/test/test_socket.rb +34 -0
  216. data/test/test_supervise.rb +103 -0
  217. data/test/test_thread.rb +170 -0
  218. data/test/test_thread_pool.rb +101 -0
  219. data/test/test_throttler.rb +50 -0
  220. data/test/test_trace.rb +68 -0
  221. metadata +482 -0
@@ -0,0 +1,215 @@
1
+ /*
2
+ * loop member variable declarations
3
+ *
4
+ * Copyright (c) 2007,2008,2009,2010,2011,2012,2013,2019 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
+ #define VARx(type,name) VAR(name, type name)
41
+
42
+ VARx(ev_tstamp, now_floor) /* last time we refreshed rt_time */
43
+ VARx(ev_tstamp, mn_now) /* monotonic clock "now" */
44
+ VARx(ev_tstamp, rtmn_diff) /* difference realtime - monotonic time */
45
+
46
+ /* for reverse feeding of events */
47
+ VARx(W *, rfeeds)
48
+ VARx(int, rfeedmax)
49
+ VARx(int, rfeedcnt)
50
+
51
+ VAR (pendings, ANPENDING *pendings [NUMPRI])
52
+ VAR (pendingmax, int pendingmax [NUMPRI])
53
+ VAR (pendingcnt, int pendingcnt [NUMPRI])
54
+ VARx(int, pendingpri) /* highest priority currently pending */
55
+ VARx(ev_prepare, pending_w) /* dummy pending watcher */
56
+
57
+ VARx(ev_tstamp, io_blocktime)
58
+ VARx(ev_tstamp, timeout_blocktime)
59
+
60
+ VARx(int, backend)
61
+ VARx(int, activecnt) /* total number of active events ("refcount") */
62
+ VARx(EV_ATOMIC_T, loop_done) /* signal by ev_break */
63
+
64
+ VARx(int, backend_fd)
65
+ VARx(ev_tstamp, backend_mintime) /* assumed typical timer resolution */
66
+ VAR (backend_modify, void (*backend_modify)(EV_P_ int fd, int oev, int nev))
67
+ VAR (backend_poll , void (*backend_poll)(EV_P_ ev_tstamp timeout))
68
+
69
+ VARx(ANFD *, anfds)
70
+ VARx(int, anfdmax)
71
+
72
+ VAR (evpipe, int evpipe [2])
73
+ VARx(ev_io, pipe_w)
74
+ VARx(EV_ATOMIC_T, pipe_write_wanted)
75
+ VARx(EV_ATOMIC_T, pipe_write_skipped)
76
+
77
+ #if !defined(_WIN32) || EV_GENWRAP
78
+ VARx(pid_t, curpid)
79
+ #endif
80
+
81
+ VARx(char, postfork) /* true if we need to recreate kernel state after fork */
82
+
83
+ #if EV_USE_SELECT || EV_GENWRAP
84
+ VARx(void *, vec_ri)
85
+ VARx(void *, vec_ro)
86
+ VARx(void *, vec_wi)
87
+ VARx(void *, vec_wo)
88
+ #if defined(_WIN32) || EV_GENWRAP
89
+ VARx(void *, vec_eo)
90
+ #endif
91
+ VARx(int, vec_max)
92
+ #endif
93
+
94
+ #if EV_USE_POLL || EV_GENWRAP
95
+ VARx(struct pollfd *, polls)
96
+ VARx(int, pollmax)
97
+ VARx(int, pollcnt)
98
+ VARx(int *, pollidxs) /* maps fds into structure indices */
99
+ VARx(int, pollidxmax)
100
+ #endif
101
+
102
+ #if EV_USE_EPOLL || EV_GENWRAP
103
+ VARx(struct epoll_event *, epoll_events)
104
+ VARx(int, epoll_eventmax)
105
+ VARx(int *, epoll_eperms)
106
+ VARx(int, epoll_epermcnt)
107
+ VARx(int, epoll_epermmax)
108
+ #endif
109
+
110
+ #if EV_USE_LINUXAIO || EV_GENWRAP
111
+ VARx(aio_context_t, linuxaio_ctx)
112
+ VARx(int, linuxaio_iteration)
113
+ VARx(struct aniocb **, linuxaio_iocbps)
114
+ VARx(int, linuxaio_iocbpmax)
115
+ VARx(struct iocb **, linuxaio_submits)
116
+ VARx(int, linuxaio_submitcnt)
117
+ VARx(int, linuxaio_submitmax)
118
+ VARx(ev_io, linuxaio_epoll_w)
119
+ #endif
120
+
121
+ #if EV_USE_KQUEUE || EV_GENWRAP
122
+ VARx(pid_t, kqueue_fd_pid)
123
+ VARx(struct kevent *, kqueue_changes)
124
+ VARx(int, kqueue_changemax)
125
+ VARx(int, kqueue_changecnt)
126
+ VARx(struct kevent *, kqueue_events)
127
+ VARx(int, kqueue_eventmax)
128
+ #endif
129
+
130
+ #if EV_USE_PORT || EV_GENWRAP
131
+ VARx(struct port_event *, port_events)
132
+ VARx(int, port_eventmax)
133
+ #endif
134
+
135
+ #if EV_USE_IOCP || EV_GENWRAP
136
+ VARx(HANDLE, iocp)
137
+ #endif
138
+
139
+ VARx(int *, fdchanges)
140
+ VARx(int, fdchangemax)
141
+ VARx(int, fdchangecnt)
142
+
143
+ VARx(ANHE *, timers)
144
+ VARx(int, timermax)
145
+ VARx(int, timercnt)
146
+
147
+ #if EV_PERIODIC_ENABLE || EV_GENWRAP
148
+ VARx(ANHE *, periodics)
149
+ VARx(int, periodicmax)
150
+ VARx(int, periodiccnt)
151
+ #endif
152
+
153
+ #if EV_IDLE_ENABLE || EV_GENWRAP
154
+ VAR (idles, ev_idle **idles [NUMPRI])
155
+ VAR (idlemax, int idlemax [NUMPRI])
156
+ VAR (idlecnt, int idlecnt [NUMPRI])
157
+ #endif
158
+ VARx(int, idleall) /* total number */
159
+
160
+ VARx(struct ev_prepare **, prepares)
161
+ VARx(int, preparemax)
162
+ VARx(int, preparecnt)
163
+
164
+ VARx(struct ev_check **, checks)
165
+ VARx(int, checkmax)
166
+ VARx(int, checkcnt)
167
+
168
+ #if EV_FORK_ENABLE || EV_GENWRAP
169
+ VARx(struct ev_fork **, forks)
170
+ VARx(int, forkmax)
171
+ VARx(int, forkcnt)
172
+ #endif
173
+
174
+ #if EV_CLEANUP_ENABLE || EV_GENWRAP
175
+ VARx(struct ev_cleanup **, cleanups)
176
+ VARx(int, cleanupmax)
177
+ VARx(int, cleanupcnt)
178
+ #endif
179
+
180
+ #if EV_ASYNC_ENABLE || EV_GENWRAP
181
+ VARx(EV_ATOMIC_T, async_pending)
182
+ VARx(struct ev_async **, asyncs)
183
+ VARx(int, asyncmax)
184
+ VARx(int, asynccnt)
185
+ #endif
186
+
187
+ #if EV_USE_INOTIFY || EV_GENWRAP
188
+ VARx(int, fs_fd)
189
+ VARx(ev_io, fs_w)
190
+ VARx(char, fs_2625) /* whether we are running in linux 2.6.25 or newer */
191
+ VAR (fs_hash, ANFS fs_hash [EV_INOTIFY_HASHSIZE])
192
+ #endif
193
+
194
+ VARx(EV_ATOMIC_T, sig_pending)
195
+ #if EV_USE_SIGNALFD || EV_GENWRAP
196
+ VARx(int, sigfd)
197
+ VARx(ev_io, sigfd_w)
198
+ VARx(sigset_t, sigfd_set)
199
+ #endif
200
+
201
+ VARx(unsigned int, origflags) /* original loop flags */
202
+
203
+ #if EV_FEATURE_API || EV_GENWRAP
204
+ VARx(unsigned int, loop_count) /* total number of loop iterations/blocks */
205
+ VARx(unsigned int, loop_depth) /* #ev_run enters - #ev_run leaves */
206
+
207
+ VARx(void *, userdata)
208
+ /* C++ doesn't support the ev_loop_callback typedef here. stinks. */
209
+ VAR (release_cb, void (*release_cb)(EV_P) EV_NOEXCEPT)
210
+ VAR (acquire_cb, void (*acquire_cb)(EV_P) EV_NOEXCEPT)
211
+ VAR (invoke_cb , ev_loop_callback invoke_cb)
212
+ #endif
213
+
214
+ #undef VARx
215
+
@@ -0,0 +1,162 @@
1
+ /*
2
+ * libev win32 compatibility cruft (_not_ a backend)
3
+ *
4
+ * Copyright (c) 2007,2008,2009 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
+ #ifdef _WIN32
41
+
42
+ /* note: the comment below could not be substantiated, but what would I care */
43
+ /* MSDN says this is required to handle SIGFPE */
44
+ /* my wild guess would be that using something floating-pointy is required */
45
+ /* for the crt to do something about it */
46
+ volatile double SIGFPE_REQ = 0.0f;
47
+
48
+ static SOCKET
49
+ ev_tcp_socket (void)
50
+ {
51
+ #if EV_USE_WSASOCKET
52
+ return WSASocket (AF_INET, SOCK_STREAM, 0, 0, 0, 0);
53
+ #else
54
+ return socket (AF_INET, SOCK_STREAM, 0);
55
+ #endif
56
+ }
57
+
58
+ /* oh, the humanity! */
59
+ static int
60
+ ev_pipe (int filedes [2])
61
+ {
62
+ struct sockaddr_in addr = { 0 };
63
+ int addr_size = sizeof (addr);
64
+ struct sockaddr_in adr2;
65
+ int adr2_size = sizeof (adr2);
66
+ SOCKET listener;
67
+ SOCKET sock [2] = { -1, -1 };
68
+
69
+ if ((listener = ev_tcp_socket ()) == INVALID_SOCKET)
70
+ return -1;
71
+
72
+ addr.sin_family = AF_INET;
73
+ addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
74
+ addr.sin_port = 0;
75
+
76
+ if (bind (listener, (struct sockaddr *)&addr, addr_size))
77
+ goto fail;
78
+
79
+ if (getsockname (listener, (struct sockaddr *)&addr, &addr_size))
80
+ goto fail;
81
+
82
+ if (listen (listener, 1))
83
+ goto fail;
84
+
85
+ if ((sock [0] = ev_tcp_socket ()) == INVALID_SOCKET)
86
+ goto fail;
87
+
88
+ if (connect (sock [0], (struct sockaddr *)&addr, addr_size))
89
+ goto fail;
90
+
91
+ /* TODO: returns INVALID_SOCKET on winsock accept, not < 0. fix it */
92
+ /* when convenient, probably by just removing error checking altogether? */
93
+ if ((sock [1] = accept (listener, 0, 0)) < 0)
94
+ goto fail;
95
+
96
+ /* windows vista returns fantasy port numbers for sockets:
97
+ * example for two interconnected tcp sockets:
98
+ *
99
+ * (Socket::unpack_sockaddr_in getsockname $sock0)[0] == 53364
100
+ * (Socket::unpack_sockaddr_in getpeername $sock0)[0] == 53363
101
+ * (Socket::unpack_sockaddr_in getsockname $sock1)[0] == 53363
102
+ * (Socket::unpack_sockaddr_in getpeername $sock1)[0] == 53365
103
+ *
104
+ * wow! tridirectional sockets!
105
+ *
106
+ * this way of checking ports seems to work:
107
+ */
108
+ if (getpeername (sock [0], (struct sockaddr *)&addr, &addr_size))
109
+ goto fail;
110
+
111
+ if (getsockname (sock [1], (struct sockaddr *)&adr2, &adr2_size))
112
+ goto fail;
113
+
114
+ errno = WSAEINVAL;
115
+ if (addr_size != adr2_size
116
+ || addr.sin_addr.s_addr != adr2.sin_addr.s_addr /* just to be sure, I mean, it's windows */
117
+ || addr.sin_port != adr2.sin_port)
118
+ goto fail;
119
+
120
+ closesocket (listener);
121
+
122
+ #if EV_SELECT_IS_WINSOCKET
123
+ filedes [0] = EV_WIN32_HANDLE_TO_FD (sock [0]);
124
+ filedes [1] = EV_WIN32_HANDLE_TO_FD (sock [1]);
125
+ #else
126
+ /* when select isn't winsocket, we also expect socket, connect, accept etc.
127
+ * to work on fds */
128
+ filedes [0] = sock [0];
129
+ filedes [1] = sock [1];
130
+ #endif
131
+
132
+ return 0;
133
+
134
+ fail:
135
+ closesocket (listener);
136
+
137
+ if (sock [0] != INVALID_SOCKET) closesocket (sock [0]);
138
+ if (sock [1] != INVALID_SOCKET) closesocket (sock [1]);
139
+
140
+ return -1;
141
+ }
142
+
143
+ #undef pipe
144
+ #define pipe(filedes) ev_pipe (filedes)
145
+
146
+ #define EV_HAVE_EV_TIME 1
147
+ ev_tstamp
148
+ ev_time (void)
149
+ {
150
+ FILETIME ft;
151
+ ULARGE_INTEGER ui;
152
+
153
+ GetSystemTimeAsFileTime (&ft);
154
+ ui.u.LowPart = ft.dwLowDateTime;
155
+ ui.u.HighPart = ft.dwHighDateTime;
156
+
157
+ /* msvc cannot convert ulonglong to double... yes, it is that sucky */
158
+ return (LONGLONG)(ui.QuadPart - 116444736000000000) * 1e-7;
159
+ }
160
+
161
+ #endif
162
+
@@ -0,0 +1,216 @@
1
+ /* DO NOT EDIT, automatically generated by update_ev_wrap */
2
+ #ifndef EV_WRAP_H
3
+ #define EV_WRAP_H
4
+ #define acquire_cb ((loop)->acquire_cb)
5
+ #define activecnt ((loop)->activecnt)
6
+ #define anfdmax ((loop)->anfdmax)
7
+ #define anfds ((loop)->anfds)
8
+ #define async_pending ((loop)->async_pending)
9
+ #define asynccnt ((loop)->asynccnt)
10
+ #define asyncmax ((loop)->asyncmax)
11
+ #define asyncs ((loop)->asyncs)
12
+ #define backend ((loop)->backend)
13
+ #define backend_fd ((loop)->backend_fd)
14
+ #define backend_mintime ((loop)->backend_mintime)
15
+ #define backend_modify ((loop)->backend_modify)
16
+ #define backend_poll ((loop)->backend_poll)
17
+ #define checkcnt ((loop)->checkcnt)
18
+ #define checkmax ((loop)->checkmax)
19
+ #define checks ((loop)->checks)
20
+ #define cleanupcnt ((loop)->cleanupcnt)
21
+ #define cleanupmax ((loop)->cleanupmax)
22
+ #define cleanups ((loop)->cleanups)
23
+ #define curpid ((loop)->curpid)
24
+ #define epoll_epermcnt ((loop)->epoll_epermcnt)
25
+ #define epoll_epermmax ((loop)->epoll_epermmax)
26
+ #define epoll_eperms ((loop)->epoll_eperms)
27
+ #define epoll_eventmax ((loop)->epoll_eventmax)
28
+ #define epoll_events ((loop)->epoll_events)
29
+ #define evpipe ((loop)->evpipe)
30
+ #define fdchangecnt ((loop)->fdchangecnt)
31
+ #define fdchangemax ((loop)->fdchangemax)
32
+ #define fdchanges ((loop)->fdchanges)
33
+ #define forkcnt ((loop)->forkcnt)
34
+ #define forkmax ((loop)->forkmax)
35
+ #define forks ((loop)->forks)
36
+ #define fs_2625 ((loop)->fs_2625)
37
+ #define fs_fd ((loop)->fs_fd)
38
+ #define fs_hash ((loop)->fs_hash)
39
+ #define fs_w ((loop)->fs_w)
40
+ #define idleall ((loop)->idleall)
41
+ #define idlecnt ((loop)->idlecnt)
42
+ #define idlemax ((loop)->idlemax)
43
+ #define idles ((loop)->idles)
44
+ #define invoke_cb ((loop)->invoke_cb)
45
+ #define io_blocktime ((loop)->io_blocktime)
46
+ #define iocp ((loop)->iocp)
47
+ #define kqueue_changecnt ((loop)->kqueue_changecnt)
48
+ #define kqueue_changemax ((loop)->kqueue_changemax)
49
+ #define kqueue_changes ((loop)->kqueue_changes)
50
+ #define kqueue_eventmax ((loop)->kqueue_eventmax)
51
+ #define kqueue_events ((loop)->kqueue_events)
52
+ #define kqueue_fd_pid ((loop)->kqueue_fd_pid)
53
+ #define linuxaio_ctx ((loop)->linuxaio_ctx)
54
+ #define linuxaio_epoll_w ((loop)->linuxaio_epoll_w)
55
+ #define linuxaio_iocbpmax ((loop)->linuxaio_iocbpmax)
56
+ #define linuxaio_iocbps ((loop)->linuxaio_iocbps)
57
+ #define linuxaio_iteration ((loop)->linuxaio_iteration)
58
+ #define linuxaio_submitcnt ((loop)->linuxaio_submitcnt)
59
+ #define linuxaio_submitmax ((loop)->linuxaio_submitmax)
60
+ #define linuxaio_submits ((loop)->linuxaio_submits)
61
+ #define loop_count ((loop)->loop_count)
62
+ #define loop_depth ((loop)->loop_depth)
63
+ #define loop_done ((loop)->loop_done)
64
+ #define mn_now ((loop)->mn_now)
65
+ #define now_floor ((loop)->now_floor)
66
+ #define origflags ((loop)->origflags)
67
+ #define pending_w ((loop)->pending_w)
68
+ #define pendingcnt ((loop)->pendingcnt)
69
+ #define pendingmax ((loop)->pendingmax)
70
+ #define pendingpri ((loop)->pendingpri)
71
+ #define pendings ((loop)->pendings)
72
+ #define periodiccnt ((loop)->periodiccnt)
73
+ #define periodicmax ((loop)->periodicmax)
74
+ #define periodics ((loop)->periodics)
75
+ #define pipe_w ((loop)->pipe_w)
76
+ #define pipe_write_skipped ((loop)->pipe_write_skipped)
77
+ #define pipe_write_wanted ((loop)->pipe_write_wanted)
78
+ #define pollcnt ((loop)->pollcnt)
79
+ #define pollidxmax ((loop)->pollidxmax)
80
+ #define pollidxs ((loop)->pollidxs)
81
+ #define pollmax ((loop)->pollmax)
82
+ #define polls ((loop)->polls)
83
+ #define port_eventmax ((loop)->port_eventmax)
84
+ #define port_events ((loop)->port_events)
85
+ #define postfork ((loop)->postfork)
86
+ #define preparecnt ((loop)->preparecnt)
87
+ #define preparemax ((loop)->preparemax)
88
+ #define prepares ((loop)->prepares)
89
+ #define release_cb ((loop)->release_cb)
90
+ #define rfeedcnt ((loop)->rfeedcnt)
91
+ #define rfeedmax ((loop)->rfeedmax)
92
+ #define rfeeds ((loop)->rfeeds)
93
+ #define rtmn_diff ((loop)->rtmn_diff)
94
+ #define sig_pending ((loop)->sig_pending)
95
+ #define sigfd ((loop)->sigfd)
96
+ #define sigfd_set ((loop)->sigfd_set)
97
+ #define sigfd_w ((loop)->sigfd_w)
98
+ #define timeout_blocktime ((loop)->timeout_blocktime)
99
+ #define timercnt ((loop)->timercnt)
100
+ #define timermax ((loop)->timermax)
101
+ #define timers ((loop)->timers)
102
+ #define userdata ((loop)->userdata)
103
+ #define vec_eo ((loop)->vec_eo)
104
+ #define vec_max ((loop)->vec_max)
105
+ #define vec_ri ((loop)->vec_ri)
106
+ #define vec_ro ((loop)->vec_ro)
107
+ #define vec_wi ((loop)->vec_wi)
108
+ #define vec_wo ((loop)->vec_wo)
109
+ #else
110
+ #undef EV_WRAP_H
111
+ #undef acquire_cb
112
+ #undef activecnt
113
+ #undef anfdmax
114
+ #undef anfds
115
+ #undef async_pending
116
+ #undef asynccnt
117
+ #undef asyncmax
118
+ #undef asyncs
119
+ #undef backend
120
+ #undef backend_fd
121
+ #undef backend_mintime
122
+ #undef backend_modify
123
+ #undef backend_poll
124
+ #undef checkcnt
125
+ #undef checkmax
126
+ #undef checks
127
+ #undef cleanupcnt
128
+ #undef cleanupmax
129
+ #undef cleanups
130
+ #undef curpid
131
+ #undef epoll_epermcnt
132
+ #undef epoll_epermmax
133
+ #undef epoll_eperms
134
+ #undef epoll_eventmax
135
+ #undef epoll_events
136
+ #undef evpipe
137
+ #undef fdchangecnt
138
+ #undef fdchangemax
139
+ #undef fdchanges
140
+ #undef forkcnt
141
+ #undef forkmax
142
+ #undef forks
143
+ #undef fs_2625
144
+ #undef fs_fd
145
+ #undef fs_hash
146
+ #undef fs_w
147
+ #undef idleall
148
+ #undef idlecnt
149
+ #undef idlemax
150
+ #undef idles
151
+ #undef invoke_cb
152
+ #undef io_blocktime
153
+ #undef iocp
154
+ #undef kqueue_changecnt
155
+ #undef kqueue_changemax
156
+ #undef kqueue_changes
157
+ #undef kqueue_eventmax
158
+ #undef kqueue_events
159
+ #undef kqueue_fd_pid
160
+ #undef linuxaio_ctx
161
+ #undef linuxaio_epoll_w
162
+ #undef linuxaio_iocbpmax
163
+ #undef linuxaio_iocbps
164
+ #undef linuxaio_iteration
165
+ #undef linuxaio_submitcnt
166
+ #undef linuxaio_submitmax
167
+ #undef linuxaio_submits
168
+ #undef loop_count
169
+ #undef loop_depth
170
+ #undef loop_done
171
+ #undef mn_now
172
+ #undef now_floor
173
+ #undef origflags
174
+ #undef pending_w
175
+ #undef pendingcnt
176
+ #undef pendingmax
177
+ #undef pendingpri
178
+ #undef pendings
179
+ #undef periodiccnt
180
+ #undef periodicmax
181
+ #undef periodics
182
+ #undef pipe_w
183
+ #undef pipe_write_skipped
184
+ #undef pipe_write_wanted
185
+ #undef pollcnt
186
+ #undef pollidxmax
187
+ #undef pollidxs
188
+ #undef pollmax
189
+ #undef polls
190
+ #undef port_eventmax
191
+ #undef port_events
192
+ #undef postfork
193
+ #undef preparecnt
194
+ #undef preparemax
195
+ #undef prepares
196
+ #undef release_cb
197
+ #undef rfeedcnt
198
+ #undef rfeedmax
199
+ #undef rfeeds
200
+ #undef rtmn_diff
201
+ #undef sig_pending
202
+ #undef sigfd
203
+ #undef sigfd_set
204
+ #undef sigfd_w
205
+ #undef timeout_blocktime
206
+ #undef timercnt
207
+ #undef timermax
208
+ #undef timers
209
+ #undef userdata
210
+ #undef vec_eo
211
+ #undef vec_max
212
+ #undef vec_ri
213
+ #undef vec_ro
214
+ #undef vec_wi
215
+ #undef vec_wo
216
+ #endif