eventmachine-mkroman 1.3.0.dev.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (182) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +179 -0
  3. data/GNU +281 -0
  4. data/LICENSE +60 -0
  5. data/README.md +110 -0
  6. data/docs/DocumentationGuidesIndex.md +27 -0
  7. data/docs/GettingStarted.md +520 -0
  8. data/docs/old/ChangeLog +211 -0
  9. data/docs/old/DEFERRABLES +246 -0
  10. data/docs/old/EPOLL +141 -0
  11. data/docs/old/INSTALL +13 -0
  12. data/docs/old/KEYBOARD +42 -0
  13. data/docs/old/LEGAL +25 -0
  14. data/docs/old/LIGHTWEIGHT_CONCURRENCY +130 -0
  15. data/docs/old/PURE_RUBY +75 -0
  16. data/docs/old/RELEASE_NOTES +94 -0
  17. data/docs/old/SMTP +4 -0
  18. data/docs/old/SPAWNED_PROCESSES +148 -0
  19. data/docs/old/TODO +8 -0
  20. data/examples/guides/getting_started/01_eventmachine_echo_server.rb +18 -0
  21. data/examples/guides/getting_started/02_eventmachine_echo_server_that_recognizes_exit_command.rb +22 -0
  22. data/examples/guides/getting_started/03_simple_chat_server.rb +149 -0
  23. data/examples/guides/getting_started/04_simple_chat_server_step_one.rb +27 -0
  24. data/examples/guides/getting_started/05_simple_chat_server_step_two.rb +43 -0
  25. data/examples/guides/getting_started/06_simple_chat_server_step_three.rb +98 -0
  26. data/examples/guides/getting_started/07_simple_chat_server_step_four.rb +121 -0
  27. data/examples/guides/getting_started/08_simple_chat_server_step_five.rb +141 -0
  28. data/examples/old/ex_channel.rb +43 -0
  29. data/examples/old/ex_queue.rb +2 -0
  30. data/examples/old/ex_tick_loop_array.rb +15 -0
  31. data/examples/old/ex_tick_loop_counter.rb +32 -0
  32. data/examples/old/helper.rb +2 -0
  33. data/ext/binder.cpp +124 -0
  34. data/ext/binder.h +52 -0
  35. data/ext/cmain.cpp +1046 -0
  36. data/ext/ed.cpp +2243 -0
  37. data/ext/ed.h +463 -0
  38. data/ext/em.cpp +2378 -0
  39. data/ext/em.h +266 -0
  40. data/ext/eventmachine.h +152 -0
  41. data/ext/extconf.rb +291 -0
  42. data/ext/fastfilereader/extconf.rb +120 -0
  43. data/ext/fastfilereader/mapper.cpp +214 -0
  44. data/ext/fastfilereader/mapper.h +59 -0
  45. data/ext/fastfilereader/rubymain.cpp +126 -0
  46. data/ext/kb.cpp +79 -0
  47. data/ext/page.cpp +107 -0
  48. data/ext/page.h +51 -0
  49. data/ext/pipe.cpp +354 -0
  50. data/ext/project.h +174 -0
  51. data/ext/rubymain.cpp +1643 -0
  52. data/ext/ssl.cpp +701 -0
  53. data/ext/ssl.h +103 -0
  54. data/ext/wait_for_single_fd.h +36 -0
  55. data/java/.classpath +8 -0
  56. data/java/.project +17 -0
  57. data/java/src/com/rubyeventmachine/EmReactor.java +625 -0
  58. data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
  59. data/java/src/com/rubyeventmachine/EmReactorInterface.java +70 -0
  60. data/java/src/com/rubyeventmachine/EventableChannel.java +72 -0
  61. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +201 -0
  62. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +415 -0
  63. data/java/src/com/rubyeventmachine/NullEmReactor.java +157 -0
  64. data/java/src/com/rubyeventmachine/NullEventableChannel.java +81 -0
  65. data/lib/em/buftok.rb +59 -0
  66. data/lib/em/callback.rb +58 -0
  67. data/lib/em/channel.rb +69 -0
  68. data/lib/em/completion.rb +307 -0
  69. data/lib/em/connection.rb +802 -0
  70. data/lib/em/deferrable/pool.rb +2 -0
  71. data/lib/em/deferrable.rb +210 -0
  72. data/lib/em/file_watch.rb +73 -0
  73. data/lib/em/future.rb +61 -0
  74. data/lib/em/io_streamer.rb +68 -0
  75. data/lib/em/iterator.rb +252 -0
  76. data/lib/em/messages.rb +66 -0
  77. data/lib/em/pool.rb +151 -0
  78. data/lib/em/process_watch.rb +45 -0
  79. data/lib/em/processes.rb +123 -0
  80. data/lib/em/protocols/header_and_content.rb +138 -0
  81. data/lib/em/protocols/httpclient.rb +303 -0
  82. data/lib/em/protocols/httpclient2.rb +602 -0
  83. data/lib/em/protocols/line_and_text.rb +125 -0
  84. data/lib/em/protocols/line_protocol.rb +33 -0
  85. data/lib/em/protocols/linetext2.rb +179 -0
  86. data/lib/em/protocols/memcache.rb +331 -0
  87. data/lib/em/protocols/object_protocol.rb +46 -0
  88. data/lib/em/protocols/postgres3.rb +246 -0
  89. data/lib/em/protocols/saslauth.rb +175 -0
  90. data/lib/em/protocols/smtpclient.rb +394 -0
  91. data/lib/em/protocols/smtpserver.rb +666 -0
  92. data/lib/em/protocols/socks4.rb +66 -0
  93. data/lib/em/protocols/stomp.rb +205 -0
  94. data/lib/em/protocols/tcptest.rb +54 -0
  95. data/lib/em/protocols.rb +37 -0
  96. data/lib/em/pure_ruby.rb +1300 -0
  97. data/lib/em/queue.rb +80 -0
  98. data/lib/em/resolver.rb +232 -0
  99. data/lib/em/spawnable.rb +84 -0
  100. data/lib/em/streamer.rb +118 -0
  101. data/lib/em/threaded_resource.rb +90 -0
  102. data/lib/em/tick_loop.rb +85 -0
  103. data/lib/em/timers.rb +61 -0
  104. data/lib/em/version.rb +3 -0
  105. data/lib/eventmachine.rb +1602 -0
  106. data/lib/jeventmachine.rb +319 -0
  107. data/rakelib/package.rake +120 -0
  108. data/rakelib/test.rake +6 -0
  109. data/rakelib/test_pure.rake +11 -0
  110. data/tests/client.crt +31 -0
  111. data/tests/client.key +51 -0
  112. data/tests/dhparam.pem +13 -0
  113. data/tests/em_ssl_handlers.rb +165 -0
  114. data/tests/em_test_helper.rb +198 -0
  115. data/tests/encoded_client.key +54 -0
  116. data/tests/jruby/test_jeventmachine.rb +38 -0
  117. data/tests/test_attach.rb +199 -0
  118. data/tests/test_basic.rb +321 -0
  119. data/tests/test_channel.rb +75 -0
  120. data/tests/test_completion.rb +178 -0
  121. data/tests/test_connection_count.rb +83 -0
  122. data/tests/test_connection_write.rb +35 -0
  123. data/tests/test_defer.rb +35 -0
  124. data/tests/test_deferrable.rb +35 -0
  125. data/tests/test_epoll.rb +141 -0
  126. data/tests/test_error_handler.rb +38 -0
  127. data/tests/test_exc.rb +37 -0
  128. data/tests/test_file_watch.rb +86 -0
  129. data/tests/test_fork.rb +75 -0
  130. data/tests/test_futures.rb +170 -0
  131. data/tests/test_handler_check.rb +35 -0
  132. data/tests/test_hc.rb +155 -0
  133. data/tests/test_httpclient.rb +238 -0
  134. data/tests/test_httpclient2.rb +132 -0
  135. data/tests/test_idle_connection.rb +31 -0
  136. data/tests/test_inactivity_timeout.rb +102 -0
  137. data/tests/test_io_streamer.rb +48 -0
  138. data/tests/test_ipv4.rb +96 -0
  139. data/tests/test_ipv6.rb +107 -0
  140. data/tests/test_iterator.rb +122 -0
  141. data/tests/test_kb.rb +28 -0
  142. data/tests/test_keepalive.rb +113 -0
  143. data/tests/test_line_protocol.rb +33 -0
  144. data/tests/test_ltp.rb +155 -0
  145. data/tests/test_ltp2.rb +332 -0
  146. data/tests/test_many_fds.rb +21 -0
  147. data/tests/test_next_tick.rb +104 -0
  148. data/tests/test_object_protocol.rb +36 -0
  149. data/tests/test_pause.rb +109 -0
  150. data/tests/test_pending_connect_timeout.rb +52 -0
  151. data/tests/test_pool.rb +196 -0
  152. data/tests/test_process_watch.rb +50 -0
  153. data/tests/test_processes.rb +147 -0
  154. data/tests/test_proxy_connection.rb +180 -0
  155. data/tests/test_pure.rb +156 -0
  156. data/tests/test_queue.rb +64 -0
  157. data/tests/test_resolver.rb +129 -0
  158. data/tests/test_running.rb +14 -0
  159. data/tests/test_sasl.rb +46 -0
  160. data/tests/test_send_file.rb +217 -0
  161. data/tests/test_servers.rb +32 -0
  162. data/tests/test_shutdown_hooks.rb +23 -0
  163. data/tests/test_smtpclient.rb +75 -0
  164. data/tests/test_smtpserver.rb +90 -0
  165. data/tests/test_sock_opt.rb +53 -0
  166. data/tests/test_spawn.rb +290 -0
  167. data/tests/test_ssl_args.rb +70 -0
  168. data/tests/test_ssl_dhparam.rb +57 -0
  169. data/tests/test_ssl_ecdh_curve.rb +57 -0
  170. data/tests/test_ssl_extensions.rb +24 -0
  171. data/tests/test_ssl_inline_cert.rb +222 -0
  172. data/tests/test_ssl_methods.rb +31 -0
  173. data/tests/test_ssl_protocols.rb +190 -0
  174. data/tests/test_ssl_verify.rb +108 -0
  175. data/tests/test_stomp.rb +38 -0
  176. data/tests/test_system.rb +46 -0
  177. data/tests/test_threaded_resource.rb +68 -0
  178. data/tests/test_tick_loop.rb +58 -0
  179. data/tests/test_timers.rb +150 -0
  180. data/tests/test_ud.rb +8 -0
  181. data/tests/test_unbind_reason.rb +40 -0
  182. metadata +389 -0
data/ext/page.h ADDED
@@ -0,0 +1,51 @@
1
+ /*****************************************************************************
2
+
3
+ $Id$
4
+
5
+ File: page.h
6
+ Date: 30Apr06
7
+
8
+ Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
9
+ Gmail: blackhedd
10
+
11
+ This program is free software; you can redistribute it and/or modify
12
+ it under the terms of either: 1) the GNU General Public License
13
+ as published by the Free Software Foundation; either version 2 of the
14
+ License, or (at your option) any later version; or 2) Ruby's License.
15
+
16
+ See the file COPYING for complete licensing information.
17
+
18
+ *****************************************************************************/
19
+
20
+
21
+ #ifndef __PageManager__H_
22
+ #define __PageManager__H_
23
+
24
+
25
+ /**************
26
+ class PageList
27
+ **************/
28
+
29
+ class PageList
30
+ {
31
+ struct Page {
32
+ Page (const char *b, size_t s): Buffer(b), Size(s) {}
33
+ const char *Buffer;
34
+ size_t Size;
35
+ };
36
+
37
+ public:
38
+ PageList();
39
+ virtual ~PageList();
40
+
41
+ void Push (const char*, int);
42
+ bool HasPages();
43
+ void Front (const char**, int*);
44
+ void PopFront();
45
+
46
+ private:
47
+ std::deque<Page> Pages;
48
+ };
49
+
50
+
51
+ #endif // __PageManager__H_
data/ext/pipe.cpp ADDED
@@ -0,0 +1,354 @@
1
+ /*****************************************************************************
2
+
3
+ $Id$
4
+
5
+ File: pipe.cpp
6
+ Date: 30May07
7
+
8
+ Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
9
+ Gmail: blackhedd
10
+
11
+ This program is free software; you can redistribute it and/or modify
12
+ it under the terms of either: 1) the GNU General Public License
13
+ as published by the Free Software Foundation; either version 2 of the
14
+ License, or (at your option) any later version; or 2) Ruby's License.
15
+
16
+ See the file COPYING for complete licensing information.
17
+
18
+ *****************************************************************************/
19
+
20
+ #include "project.h"
21
+
22
+
23
+ #ifdef OS_UNIX
24
+ // THIS ENTIRE FILE IS ONLY COMPILED ON UNIX-LIKE SYSTEMS.
25
+
26
+ /******************************
27
+ PipeDescriptor::PipeDescriptor
28
+ ******************************/
29
+
30
+ PipeDescriptor::PipeDescriptor (int fd, pid_t subpid, EventMachine_t *parent_em):
31
+ EventableDescriptor (fd, parent_em),
32
+ bReadAttemptedAfterClose (false),
33
+ OutboundDataSize (0),
34
+ SubprocessPid (subpid)
35
+ {
36
+ #ifdef HAVE_EPOLL
37
+ EpollEvent.events = EPOLLIN;
38
+ #endif
39
+ #ifdef HAVE_KQUEUE
40
+ MyEventMachine->ArmKqueueReader (this);
41
+ #endif
42
+ }
43
+
44
+
45
+ /*******************************
46
+ PipeDescriptor::~PipeDescriptor
47
+ *******************************/
48
+
49
+ PipeDescriptor::~PipeDescriptor() NO_EXCEPT_FALSE
50
+ {
51
+ // Run down any stranded outbound data.
52
+ for (size_t i=0; i < OutboundPages.size(); i++)
53
+ OutboundPages[i].Free();
54
+
55
+ /* As a virtual destructor, we come here before the base-class
56
+ * destructor that closes our file-descriptor.
57
+ * We have to make sure the subprocess goes down (if it's not
58
+ * already down) and we have to reap the zombie.
59
+ *
60
+ * This implementation is PROVISIONAL and will surely be improved.
61
+ * The intention here is that we never block, hence the highly
62
+ * undesirable sleeps. But if we can't reap the subprocess even
63
+ * after sending it SIGKILL, then something is wrong and we
64
+ * throw a fatal exception, which is also not something we should
65
+ * be doing.
66
+ *
67
+ * Eventually the right thing to do will be to have the reactor
68
+ * core respond to SIGCHLD by chaining a handler on top of the
69
+ * one Ruby may have installed, and dealing with a list of dead
70
+ * children that are pending cleanup.
71
+ *
72
+ * Since we want to have a signal processor integrated into the
73
+ * client-visible API, let's wait until that is done before cleaning
74
+ * this up.
75
+ *
76
+ * Added a very ugly hack to support passing the subprocess's exit
77
+ * status to the user. It only makes logical sense for user code to access
78
+ * the subprocess exit status in the unbind callback. But unbind is called
79
+ * back during the EventableDescriptor destructor. So by that time there's
80
+ * no way to call back this object through an object binding, because it's
81
+ * already been cleaned up. We might have added a parameter to the unbind
82
+ * callback, but that would probably break a huge amount of existing code.
83
+ * So the hack-solution is to define an instance variable in the EventMachine
84
+ * object and stick the exit status in there, where it can easily be accessed
85
+ * with an accessor visible to user code.
86
+ * User code should ONLY access the exit status from within the unbind callback.
87
+ * Otherwise there's no guarantee it'll be valid.
88
+ * This hack won't make it impossible to run multiple EventMachines in a single
89
+ * process, but it will make it impossible to reliably nest unbind calls
90
+ * within other unbind calls. (Not sure if that's even possible.)
91
+ */
92
+
93
+ assert (MyEventMachine);
94
+
95
+ /* Another hack to make the SubprocessPid available to get_subprocess_status */
96
+ MyEventMachine->SubprocessPid = SubprocessPid;
97
+
98
+ /* 01Mar09: Updated to use a small nanosleep in a loop. When nanosleep is interrupted by SIGCHLD,
99
+ * it resumes the system call after processing the signal (resulting in unnecessary latency).
100
+ * Calling nanosleep in a loop avoids this problem.
101
+ */
102
+ struct timespec req = {0, 50000000}; // 0.05s
103
+ int n;
104
+
105
+ // wait 0.5s for the process to die
106
+ for (n=0; n<10; n++) {
107
+ if (waitpid (SubprocessPid, &(MyEventMachine->SubprocessExitStatus), WNOHANG) != 0) return;
108
+ nanosleep (&req, NULL);
109
+ }
110
+
111
+ // send SIGTERM and wait another 1s
112
+ kill (SubprocessPid, SIGTERM);
113
+ for (n=0; n<20; n++) {
114
+ nanosleep (&req, NULL);
115
+ if (waitpid (SubprocessPid, &(MyEventMachine->SubprocessExitStatus), WNOHANG) != 0) return;
116
+ }
117
+
118
+ // send SIGKILL and wait another 5s
119
+ kill (SubprocessPid, SIGKILL);
120
+ for (n=0; n<100; n++) {
121
+ nanosleep (&req, NULL);
122
+ if (waitpid (SubprocessPid, &(MyEventMachine->SubprocessExitStatus), WNOHANG) != 0) return;
123
+ }
124
+
125
+ // still not dead, give up!
126
+ throw std::runtime_error ("unable to reap subprocess");
127
+ }
128
+
129
+
130
+
131
+ /********************
132
+ PipeDescriptor::Read
133
+ ********************/
134
+
135
+ void PipeDescriptor::Read()
136
+ {
137
+ int sd = GetSocket();
138
+ if (sd == INVALID_SOCKET) {
139
+ assert (!bReadAttemptedAfterClose);
140
+ bReadAttemptedAfterClose = true;
141
+ return;
142
+ }
143
+
144
+ LastActivity = MyEventMachine->GetCurrentLoopTime();
145
+
146
+ int total_bytes_read = 0;
147
+ char readbuffer [16 * 1024];
148
+
149
+ for (int i=0; i < 10; i++) {
150
+ // Don't read just one buffer and then move on. This is faster
151
+ // if there is a lot of incoming.
152
+ // But don't read indefinitely. Give other sockets a chance to run.
153
+ // NOTICE, we're reading one less than the buffer size.
154
+ // That's so we can put a guard byte at the end of what we send
155
+ // to user code.
156
+ // Use read instead of recv, which on Linux gives a "socket operation
157
+ // on nonsocket" error.
158
+
159
+
160
+ int r = read (sd, readbuffer, sizeof(readbuffer) - 1);
161
+ //cerr << "<R:" << r << ">";
162
+
163
+ if (r > 0) {
164
+ total_bytes_read += r;
165
+
166
+ // Add a null-terminator at the the end of the buffer
167
+ // that we will send to the callback.
168
+ // DO NOT EVER CHANGE THIS. We want to explicitly allow users
169
+ // to be able to depend on this behavior, so they will have
170
+ // the option to do some things faster. Additionally it's
171
+ // a security guard against buffer overflows.
172
+ readbuffer [r] = 0;
173
+ _GenericInboundDispatch(readbuffer, r);
174
+ }
175
+ else if (r == 0) {
176
+ break;
177
+ }
178
+ else {
179
+ // Basically a would-block, meaning we've read everything there is to read.
180
+ break;
181
+ }
182
+
183
+ }
184
+
185
+
186
+ if (total_bytes_read == 0) {
187
+ // If we read no data on a socket that selected readable,
188
+ // it generally means the other end closed the connection gracefully.
189
+ ScheduleClose (false);
190
+ //bCloseNow = true;
191
+ }
192
+
193
+ }
194
+
195
+ /*********************
196
+ PipeDescriptor::Write
197
+ *********************/
198
+
199
+ void PipeDescriptor::Write()
200
+ {
201
+ int sd = GetSocket();
202
+ assert (sd != INVALID_SOCKET);
203
+
204
+ LastActivity = MyEventMachine->GetCurrentLoopTime();
205
+ char output_buffer [16 * 1024];
206
+ size_t nbytes = 0;
207
+
208
+ while ((OutboundPages.size() > 0) && (nbytes < sizeof(output_buffer))) {
209
+ OutboundPage *op = &(OutboundPages[0]);
210
+ if ((nbytes + op->Length - op->Offset) < sizeof (output_buffer)) {
211
+ memcpy (output_buffer + nbytes, op->Buffer + op->Offset, op->Length - op->Offset);
212
+ nbytes += (op->Length - op->Offset);
213
+ op->Free();
214
+ OutboundPages.pop_front();
215
+ }
216
+ else {
217
+ int len = sizeof(output_buffer) - nbytes;
218
+ memcpy (output_buffer + nbytes, op->Buffer + op->Offset, len);
219
+ op->Offset += len;
220
+ nbytes += len;
221
+ }
222
+ }
223
+
224
+ // We should never have gotten here if there were no data to write,
225
+ // so assert that as a sanity check.
226
+ // Don't bother to make sure nbytes is less than output_buffer because
227
+ // if it were we probably would have crashed already.
228
+ assert (nbytes > 0);
229
+
230
+ assert (GetSocket() != INVALID_SOCKET);
231
+ int bytes_written = write (GetSocket(), output_buffer, nbytes);
232
+ #ifdef OS_WIN32
233
+ int e = WSAGetLastError();
234
+ #else
235
+ int e = errno;
236
+ #endif
237
+
238
+ if (bytes_written > 0) {
239
+ OutboundDataSize -= bytes_written;
240
+ if ((size_t)bytes_written < nbytes) {
241
+ int len = nbytes - bytes_written;
242
+ char *buffer = (char*) malloc (len + 1);
243
+ if (!buffer)
244
+ throw std::runtime_error ("bad alloc throwing back data");
245
+ memcpy (buffer, output_buffer + bytes_written, len);
246
+ buffer [len] = 0;
247
+ OutboundPages.push_front (OutboundPage (buffer, len));
248
+ }
249
+ #ifdef HAVE_EPOLL
250
+ EpollEvent.events = EPOLLIN;
251
+ if (SelectForWrite())
252
+ EpollEvent.events |= EPOLLOUT;
253
+ assert (MyEventMachine);
254
+ MyEventMachine->Modify (this);
255
+ #endif
256
+ }
257
+ else {
258
+ #ifdef OS_UNIX
259
+ if ((e != EINPROGRESS) && (e != EWOULDBLOCK) && (e != EINTR))
260
+ #endif
261
+ #ifdef OS_WIN32
262
+ if ((e != WSAEINPROGRESS) && (e != WSAEWOULDBLOCK))
263
+ #endif
264
+ Close();
265
+ }
266
+ }
267
+
268
+
269
+ /*************************
270
+ PipeDescriptor::Heartbeat
271
+ *************************/
272
+
273
+ void PipeDescriptor::Heartbeat()
274
+ {
275
+ // If an inactivity timeout is defined, then check for it.
276
+ if (InactivityTimeout && ((MyEventMachine->GetCurrentLoopTime() - LastActivity) >= InactivityTimeout))
277
+ ScheduleClose (false);
278
+ //bCloseNow = true;
279
+ }
280
+
281
+
282
+ /*****************************
283
+ PipeDescriptor::SelectForRead
284
+ *****************************/
285
+
286
+ bool PipeDescriptor::SelectForRead()
287
+ {
288
+ /* Pipe descriptors, being local by definition, don't have
289
+ * a pending state, so this is simpler than for the
290
+ * ConnectionDescriptor object.
291
+ */
292
+ return bPaused ? false : true;
293
+ }
294
+
295
+ /******************************
296
+ PipeDescriptor::SelectForWrite
297
+ ******************************/
298
+
299
+ bool PipeDescriptor::SelectForWrite()
300
+ {
301
+ /* Pipe descriptors, being local by definition, don't have
302
+ * a pending state, so this is simpler than for the
303
+ * ConnectionDescriptor object.
304
+ */
305
+ return (GetOutboundDataSize() > 0) && !bPaused ? true : false;
306
+ }
307
+
308
+
309
+
310
+
311
+ /********************************
312
+ PipeDescriptor::SendOutboundData
313
+ ********************************/
314
+
315
+ int PipeDescriptor::SendOutboundData (const char *data, unsigned long length)
316
+ {
317
+ //if (bCloseNow || bCloseAfterWriting)
318
+ if (IsCloseScheduled())
319
+ return 0;
320
+
321
+ if (!data && (length > 0))
322
+ throw std::runtime_error ("bad outbound data");
323
+ char *buffer = (char *) malloc (length + 1);
324
+ if (!buffer)
325
+ throw std::runtime_error ("no allocation for outbound data");
326
+ memcpy (buffer, data, length);
327
+ buffer [length] = 0;
328
+ OutboundPages.push_back (OutboundPage (buffer, length));
329
+ OutboundDataSize += length;
330
+ #ifdef HAVE_EPOLL
331
+ EpollEvent.events = (EPOLLIN | EPOLLOUT);
332
+ assert (MyEventMachine);
333
+ MyEventMachine->Modify (this);
334
+ #endif
335
+ return length;
336
+ }
337
+
338
+ /********************************
339
+ PipeDescriptor::GetSubprocessPid
340
+ ********************************/
341
+
342
+ bool PipeDescriptor::GetSubprocessPid (pid_t *pid)
343
+ {
344
+ bool ok = false;
345
+ if (pid && (SubprocessPid > 0)) {
346
+ *pid = SubprocessPid;
347
+ ok = true;
348
+ }
349
+ return ok;
350
+ }
351
+
352
+
353
+ #endif // OS_UNIX
354
+
data/ext/project.h ADDED
@@ -0,0 +1,174 @@
1
+ /*****************************************************************************
2
+
3
+ $Id$
4
+
5
+ File: project.h
6
+ Date: 06Apr06
7
+
8
+ Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
9
+ Gmail: blackhedd
10
+
11
+ This program is free software; you can redistribute it and/or modify
12
+ it under the terms of either: 1) the GNU General Public License
13
+ as published by the Free Software Foundation; either version 2 of the
14
+ License, or (at your option) any later version; or 2) Ruby's License.
15
+
16
+ See the file COPYING for complete licensing information.
17
+
18
+ *****************************************************************************/
19
+
20
+
21
+ #ifndef __Project__H_
22
+ #define __Project__H_
23
+
24
+
25
+ #include <iostream>
26
+ #include <map>
27
+ #include <set>
28
+ #include <vector>
29
+ #include <deque>
30
+ #include <string>
31
+ #include <sstream>
32
+ #include <stdexcept>
33
+
34
+
35
+ #ifdef OS_UNIX
36
+ #include <signal.h>
37
+ #include <netdb.h>
38
+ #include <time.h>
39
+ #include <sys/time.h>
40
+ #include <sys/types.h>
41
+ #include <sys/stat.h>
42
+ #include <sys/socket.h>
43
+ #include <sys/un.h>
44
+ #include <sys/resource.h>
45
+ #include <sys/wait.h>
46
+ #include <assert.h>
47
+ #include <unistd.h>
48
+ #include <fcntl.h>
49
+ #include <errno.h>
50
+ #include <netinet/in.h>
51
+ #include <netinet/tcp.h>
52
+ #include <arpa/inet.h>
53
+ #include <pwd.h>
54
+ #include <string.h>
55
+ typedef int SOCKET;
56
+ #define INVALID_SOCKET -1
57
+ #define SOCKET_ERROR -1
58
+ #ifdef OS_SOLARIS8
59
+ #include <strings.h>
60
+ #include <sys/un.h>
61
+ #ifndef AF_LOCAL
62
+ #define AF_LOCAL AF_UNIX
63
+ #endif
64
+ // INADDR_NONE is undefined on Solaris < 8. Thanks to Brett Eisenberg and Tim Pease.
65
+ #ifndef INADDR_NONE
66
+ #define INADDR_NONE ((unsigned long)-1)
67
+ #endif
68
+ #endif /* OS_SOLARIS8 */
69
+
70
+ #ifdef _AIX
71
+ #include <strings.h>
72
+ #ifndef AF_LOCAL
73
+ #define AF_LOCAL AF_UNIX
74
+ #endif
75
+ #endif /* _AIX */
76
+
77
+ #ifdef OS_DARWIN
78
+ #include <mach/mach.h>
79
+ #include <mach/mach_time.h>
80
+ #endif /* OS_DARWIN */
81
+
82
+ #endif /* OS_UNIX */
83
+
84
+ #ifdef OS_WIN32
85
+ // 21Sep09: windows limits select() to 64 sockets by default, we increase it to 1024 here (before including winsock2.h)
86
+ // 18Jun12: fd_setsize must be changed in the ruby binary (not in this extension). redefining it also causes segvs, see eventmachine/eventmachine#333
87
+ //#define FD_SETSIZE 1024
88
+
89
+ // WIN32_LEAN_AND_MEAN excludes APIs such as Cryptography, DDE, RPC, Shell, and Windows Sockets.
90
+ #define WIN32_LEAN_AND_MEAN
91
+
92
+ #include <windows.h>
93
+ #include <winsock2.h>
94
+ #include <ws2tcpip.h>
95
+ #include <rpc.h>
96
+ #include <fcntl.h>
97
+ #include <assert.h>
98
+
99
+ // Older versions of MinGW in the Ruby Dev Kit do not provide the getaddrinfo hint flags
100
+ #ifndef AI_ADDRCONFIG
101
+ #define AI_ADDRCONFIG 0x0400
102
+ #endif
103
+
104
+ #ifndef AI_NUMERICSERV
105
+ #define AI_NUMERICSERV 0x0008
106
+ #endif
107
+
108
+ // Use the Win32 wrapper library that Ruby owns to be able to close sockets with the close() function
109
+ #define RUBY_EXPORT
110
+ #include <ruby/defines.h>
111
+ #include <ruby/win32.h>
112
+ #endif /* OS_WIN32 */
113
+
114
+ #if !defined(_MSC_VER) || _MSC_VER > 1500
115
+ #include <stdint.h>
116
+ #endif
117
+
118
+ #ifdef WITH_SSL
119
+ #include <openssl/ssl.h>
120
+ #include <openssl/err.h>
121
+ #endif
122
+
123
+ #ifdef HAVE_EPOLL
124
+ #include <sys/epoll.h>
125
+ #endif
126
+
127
+ #ifdef HAVE_KQUEUE
128
+ #include <sys/event.h>
129
+ #include <sys/queue.h>
130
+ #endif
131
+
132
+ #ifdef HAVE_INOTIFY
133
+ #include <sys/inotify.h>
134
+ #endif
135
+
136
+ #ifdef HAVE_OLD_INOTIFY
137
+ #include <sys/syscall.h>
138
+ #include <linux/inotify.h>
139
+ static inline int inotify_init (void) { return syscall (__NR_inotify_init); }
140
+ static inline int inotify_add_watch (int fd, const char *name, __u32 mask) { return syscall (__NR_inotify_add_watch, fd, name, mask); }
141
+ static inline int inotify_rm_watch (int fd, __u32 wd) { return syscall (__NR_inotify_rm_watch, fd, wd); }
142
+ #define HAVE_INOTIFY 1
143
+ #endif
144
+
145
+ #ifdef HAVE_INOTIFY
146
+ #define INOTIFY_EVENT_SIZE (sizeof(struct inotify_event))
147
+ #endif
148
+
149
+ #ifdef HAVE_WRITEV
150
+ #include <sys/uio.h>
151
+ #endif
152
+
153
+ #if __cplusplus
154
+ extern "C" {
155
+ #endif
156
+ typedef void (*EMCallback)(const unsigned long, int, const char*, const unsigned long);
157
+ #if __cplusplus
158
+ }
159
+ #endif
160
+
161
+ #if defined(__GNUC__) && (__GNUC__ >= 3)
162
+ #define UNUSED __attribute__ ((unused))
163
+ #else
164
+ #define UNUSED
165
+ #endif
166
+
167
+ #include "binder.h"
168
+ #include "em.h"
169
+ #include "ed.h"
170
+ #include "page.h"
171
+ #include "ssl.h"
172
+ #include "eventmachine.h"
173
+
174
+ #endif // __Project__H_