smparkes-eventmachine 0.12.10

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 (158) hide show
  1. data/.gitignore +15 -0
  2. data/README +81 -0
  3. data/Rakefile +374 -0
  4. data/docs/COPYING +60 -0
  5. data/docs/ChangeLog +211 -0
  6. data/docs/DEFERRABLES +133 -0
  7. data/docs/EPOLL +141 -0
  8. data/docs/GNU +281 -0
  9. data/docs/INSTALL +13 -0
  10. data/docs/KEYBOARD +38 -0
  11. data/docs/LEGAL +25 -0
  12. data/docs/LIGHTWEIGHT_CONCURRENCY +70 -0
  13. data/docs/PURE_RUBY +75 -0
  14. data/docs/RELEASE_NOTES +94 -0
  15. data/docs/SMTP +2 -0
  16. data/docs/SPAWNED_PROCESSES +89 -0
  17. data/docs/TODO +8 -0
  18. data/eventmachine.gemspec +40 -0
  19. data/examples/ex_channel.rb +43 -0
  20. data/examples/ex_queue.rb +2 -0
  21. data/examples/helper.rb +2 -0
  22. data/ext/binder.cpp +125 -0
  23. data/ext/binder.h +46 -0
  24. data/ext/cmain.cpp +827 -0
  25. data/ext/cplusplus.cpp +202 -0
  26. data/ext/ed.cpp +1901 -0
  27. data/ext/ed.h +424 -0
  28. data/ext/em.cpp +2288 -0
  29. data/ext/em.h +229 -0
  30. data/ext/emwin.cpp +300 -0
  31. data/ext/emwin.h +94 -0
  32. data/ext/epoll.cpp +26 -0
  33. data/ext/epoll.h +25 -0
  34. data/ext/eventmachine.h +122 -0
  35. data/ext/eventmachine_cpp.h +96 -0
  36. data/ext/extconf.rb +150 -0
  37. data/ext/fastfilereader/extconf.rb +85 -0
  38. data/ext/fastfilereader/mapper.cpp +214 -0
  39. data/ext/fastfilereader/mapper.h +59 -0
  40. data/ext/fastfilereader/rubymain.cpp +127 -0
  41. data/ext/files.cpp +94 -0
  42. data/ext/files.h +65 -0
  43. data/ext/kb.cpp +81 -0
  44. data/ext/page.cpp +107 -0
  45. data/ext/page.h +51 -0
  46. data/ext/pipe.cpp +349 -0
  47. data/ext/project.h +156 -0
  48. data/ext/rubymain.cpp +1194 -0
  49. data/ext/sigs.cpp +89 -0
  50. data/ext/sigs.h +32 -0
  51. data/ext/ssl.cpp +460 -0
  52. data/ext/ssl.h +94 -0
  53. data/java/.classpath +8 -0
  54. data/java/.project +17 -0
  55. data/java/src/com/rubyeventmachine/EmReactor.java +570 -0
  56. data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
  57. data/java/src/com/rubyeventmachine/EventableChannel.java +69 -0
  58. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +189 -0
  59. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +364 -0
  60. data/java/src/com/rubyeventmachine/application/Application.java +194 -0
  61. data/java/src/com/rubyeventmachine/application/Connection.java +74 -0
  62. data/java/src/com/rubyeventmachine/application/ConnectionFactory.java +37 -0
  63. data/java/src/com/rubyeventmachine/application/DefaultConnectionFactory.java +46 -0
  64. data/java/src/com/rubyeventmachine/application/PeriodicTimer.java +38 -0
  65. data/java/src/com/rubyeventmachine/application/Timer.java +54 -0
  66. data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +109 -0
  67. data/java/src/com/rubyeventmachine/tests/ConnectTest.java +148 -0
  68. data/java/src/com/rubyeventmachine/tests/EMTest.java +80 -0
  69. data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +53 -0
  70. data/java/src/com/rubyeventmachine/tests/TestServers.java +75 -0
  71. data/java/src/com/rubyeventmachine/tests/TestTimers.java +90 -0
  72. data/lib/em/buftok.rb +138 -0
  73. data/lib/em/callback.rb +26 -0
  74. data/lib/em/channel.rb +57 -0
  75. data/lib/em/connection.rb +564 -0
  76. data/lib/em/deferrable.rb +192 -0
  77. data/lib/em/file_watch.rb +54 -0
  78. data/lib/em/future.rb +61 -0
  79. data/lib/em/messages.rb +66 -0
  80. data/lib/em/process_watch.rb +44 -0
  81. data/lib/em/processes.rb +119 -0
  82. data/lib/em/protocols/header_and_content.rb +138 -0
  83. data/lib/em/protocols/httpclient.rb +263 -0
  84. data/lib/em/protocols/httpclient2.rb +590 -0
  85. data/lib/em/protocols/line_and_text.rb +125 -0
  86. data/lib/em/protocols/linetext2.rb +161 -0
  87. data/lib/em/protocols/memcache.rb +323 -0
  88. data/lib/em/protocols/object_protocol.rb +45 -0
  89. data/lib/em/protocols/postgres3.rb +247 -0
  90. data/lib/em/protocols/saslauth.rb +175 -0
  91. data/lib/em/protocols/smtpclient.rb +357 -0
  92. data/lib/em/protocols/smtpserver.rb +547 -0
  93. data/lib/em/protocols/socks4.rb +66 -0
  94. data/lib/em/protocols/stomp.rb +200 -0
  95. data/lib/em/protocols/tcptest.rb +53 -0
  96. data/lib/em/protocols.rb +36 -0
  97. data/lib/em/queue.rb +61 -0
  98. data/lib/em/spawnable.rb +85 -0
  99. data/lib/em/streamer.rb +130 -0
  100. data/lib/em/timers.rb +56 -0
  101. data/lib/em/version.rb +3 -0
  102. data/lib/eventmachine.rb +1592 -0
  103. data/lib/evma/callback.rb +32 -0
  104. data/lib/evma/container.rb +75 -0
  105. data/lib/evma/factory.rb +77 -0
  106. data/lib/evma/protocol.rb +87 -0
  107. data/lib/evma/reactor.rb +48 -0
  108. data/lib/evma.rb +32 -0
  109. data/lib/jeventmachine.rb +257 -0
  110. data/lib/pr_eventmachine.rb +1022 -0
  111. data/setup.rb +1585 -0
  112. data/tasks/cpp.rake_example +77 -0
  113. data/tests/client.crt +31 -0
  114. data/tests/client.key +51 -0
  115. data/tests/test_attach.rb +126 -0
  116. data/tests/test_basic.rb +284 -0
  117. data/tests/test_channel.rb +63 -0
  118. data/tests/test_connection_count.rb +35 -0
  119. data/tests/test_defer.rb +47 -0
  120. data/tests/test_epoll.rb +160 -0
  121. data/tests/test_error_handler.rb +35 -0
  122. data/tests/test_errors.rb +82 -0
  123. data/tests/test_exc.rb +55 -0
  124. data/tests/test_file_watch.rb +49 -0
  125. data/tests/test_futures.rb +198 -0
  126. data/tests/test_get_sock_opt.rb +30 -0
  127. data/tests/test_handler_check.rb +37 -0
  128. data/tests/test_hc.rb +218 -0
  129. data/tests/test_httpclient.rb +218 -0
  130. data/tests/test_httpclient2.rb +153 -0
  131. data/tests/test_inactivity_timeout.rb +50 -0
  132. data/tests/test_kb.rb +60 -0
  133. data/tests/test_ltp.rb +182 -0
  134. data/tests/test_ltp2.rb +317 -0
  135. data/tests/test_next_tick.rb +133 -0
  136. data/tests/test_object_protocol.rb +37 -0
  137. data/tests/test_pause.rb +70 -0
  138. data/tests/test_pending_connect_timeout.rb +48 -0
  139. data/tests/test_process_watch.rb +48 -0
  140. data/tests/test_processes.rb +128 -0
  141. data/tests/test_proxy_connection.rb +92 -0
  142. data/tests/test_pure.rb +125 -0
  143. data/tests/test_queue.rb +44 -0
  144. data/tests/test_running.rb +42 -0
  145. data/tests/test_sasl.rb +72 -0
  146. data/tests/test_send_file.rb +242 -0
  147. data/tests/test_servers.rb +76 -0
  148. data/tests/test_smtpclient.rb +83 -0
  149. data/tests/test_smtpserver.rb +85 -0
  150. data/tests/test_spawn.rb +322 -0
  151. data/tests/test_ssl_args.rb +79 -0
  152. data/tests/test_ssl_methods.rb +50 -0
  153. data/tests/test_ssl_verify.rb +82 -0
  154. data/tests/test_timers.rb +162 -0
  155. data/tests/test_ud.rb +36 -0
  156. data/tests/testem.rb +31 -0
  157. data/web/whatis +7 -0
  158. metadata +237 -0
data/ext/cmain.cpp ADDED
@@ -0,0 +1,827 @@
1
+ /*****************************************************************************
2
+
3
+ $Id$
4
+
5
+ File: cmain.cpp
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
+ #include "project.h"
21
+
22
+ /* 21Sep09: ruby 1.9 defines macros for common i/o functions that point to rb_w32_* implementations.
23
+ We need to undef the stat to fix a build failure in evma_send_file_data_to_connection.
24
+ See http://groups.google.com/group/eventmachine/browse_thread/thread/fc60d9bb738ffc71
25
+ */
26
+ #if defined(BUILD_FOR_RUBY) && defined(OS_WIN32)
27
+ #undef stat
28
+ #endif
29
+
30
+ static EventMachine_t *EventMachine;
31
+ static int bUseEpoll = 0;
32
+ static int bUseKqueue = 0;
33
+
34
+ extern "C" void ensure_eventmachine (const char *caller = "unknown caller")
35
+ {
36
+ if (!EventMachine) {
37
+ const int err_size = 128;
38
+ char err_string[err_size];
39
+ snprintf (err_string, err_size, "eventmachine not initialized: %s", caller);
40
+ #ifdef BUILD_FOR_RUBY
41
+ rb_raise(rb_eRuntimeError, "%s", err_string);
42
+ #else
43
+ throw std::runtime_error (err_string);
44
+ #endif
45
+ }
46
+ }
47
+
48
+ /***********************
49
+ evma_initialize_library
50
+ ***********************/
51
+
52
+ extern "C" void evma_initialize_library (EMCallback cb)
53
+ {
54
+ // Probably a bad idea to mess with the signal mask of a process
55
+ // we're just being linked into.
56
+ //InstallSignalHandlers();
57
+ if (EventMachine)
58
+ #ifdef BUILD_FOR_RUBY
59
+ rb_raise(rb_eRuntimeError, "eventmachine already initialized: evma_initialize_library");
60
+ #else
61
+ throw std::runtime_error ("eventmachine already initialized: evma_initialize_library");
62
+ #endif
63
+ EventMachine = new EventMachine_t (cb);
64
+ if (bUseEpoll)
65
+ EventMachine->_UseEpoll();
66
+ if (bUseKqueue)
67
+ EventMachine->_UseKqueue();
68
+ }
69
+
70
+
71
+ /********************
72
+ evma_release_library
73
+ ********************/
74
+
75
+ extern "C" void evma_release_library()
76
+ {
77
+ ensure_eventmachine("evma_release_library");
78
+ delete EventMachine;
79
+ EventMachine = NULL;
80
+ }
81
+
82
+
83
+ /****************
84
+ evma_run_machine
85
+ ****************/
86
+
87
+ extern "C" void evma_run_machine()
88
+ {
89
+ ensure_eventmachine("evma_run_machine");
90
+ EventMachine->Run();
91
+ }
92
+
93
+
94
+ /**************************
95
+ evma_install_oneshot_timer
96
+ **************************/
97
+
98
+ extern "C" const unsigned long evma_install_oneshot_timer (int seconds)
99
+ {
100
+ ensure_eventmachine("evma_install_oneshot_timer");
101
+ return EventMachine->InstallOneshotTimer (seconds);
102
+ }
103
+
104
+
105
+ /**********************
106
+ evma_connect_to_server
107
+ **********************/
108
+
109
+ extern "C" const unsigned long evma_connect_to_server (const char *bind_addr, int bind_port, const char *server, int port)
110
+ {
111
+ ensure_eventmachine("evma_connect_to_server");
112
+ return EventMachine->ConnectToServer (bind_addr, bind_port, server, port);
113
+ }
114
+
115
+ /***************************
116
+ evma_connect_to_unix_server
117
+ ***************************/
118
+
119
+ extern "C" const unsigned long evma_connect_to_unix_server (const char *server)
120
+ {
121
+ ensure_eventmachine("evma_connect_to_unix_server");
122
+ return EventMachine->ConnectToUnixServer (server);
123
+ }
124
+
125
+ /**************
126
+ evma_attach_fd
127
+ **************/
128
+
129
+ extern "C" const unsigned long evma_attach_fd (int file_descriptor, int watch_mode)
130
+ {
131
+ ensure_eventmachine("evma_attach_fd");
132
+ return EventMachine->AttachFD (file_descriptor, watch_mode ? true : false);
133
+ }
134
+
135
+ /**************
136
+ evma_detach_fd
137
+ **************/
138
+
139
+ extern "C" int evma_detach_fd (const unsigned long binding)
140
+ {
141
+ ensure_eventmachine("evma_detach_fd");
142
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
143
+ if (ed)
144
+ return EventMachine->DetachFD (ed);
145
+ else
146
+ #ifdef BUILD_FOR_RUBY
147
+ rb_raise(rb_eRuntimeError, "invalid binding to detach");
148
+ #else
149
+ throw std::runtime_error ("invalid binding to detach");
150
+ #endif
151
+ }
152
+
153
+ /************************
154
+ evma_get_file_descriptor
155
+ ************************/
156
+
157
+ extern "C" int evma_get_file_descriptor (const unsigned long binding)
158
+ {
159
+ ensure_eventmachine("evma_get_file_descriptor");
160
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
161
+ if (ed)
162
+ return ed->GetSocket();
163
+ else
164
+ #ifdef BUILD_FOR_RUBY
165
+ rb_raise(rb_eRuntimeError, "invalid binding to get_fd");
166
+ #else
167
+ throw std::runtime_error ("invalid binding to get_fd");
168
+ #endif
169
+ }
170
+
171
+ /***********************
172
+ evma_is_notify_readable
173
+ ***********************/
174
+
175
+ extern "C" int evma_is_notify_readable (const unsigned long binding)
176
+ {
177
+ ConnectionDescriptor *cd = dynamic_cast <ConnectionDescriptor*> (Bindable_t::GetObject (binding));
178
+ if (cd)
179
+ return cd->IsNotifyReadable() ? 1 : 0;
180
+ return -1;
181
+ }
182
+
183
+ /************************
184
+ evma_set_notify_readable
185
+ ************************/
186
+
187
+ extern "C" void evma_set_notify_readable (const unsigned long binding, int mode)
188
+ {
189
+ ConnectionDescriptor *cd = dynamic_cast <ConnectionDescriptor*> (Bindable_t::GetObject (binding));
190
+ if (cd)
191
+ cd->SetNotifyReadable (mode ? true : false);
192
+ }
193
+
194
+ /***********************
195
+ evma_is_notify_writable
196
+ ***********************/
197
+
198
+ extern "C" int evma_is_notify_writable (const unsigned long binding)
199
+ {
200
+ ConnectionDescriptor *cd = dynamic_cast <ConnectionDescriptor*> (Bindable_t::GetObject (binding));
201
+ if (cd)
202
+ return cd->IsNotifyWritable() ? 1 : 0;
203
+ return -1;
204
+ }
205
+
206
+ /************************
207
+ evma_set_notify_writable
208
+ ************************/
209
+
210
+ extern "C" void evma_set_notify_writable (const unsigned long binding, int mode)
211
+ {
212
+ ConnectionDescriptor *cd = dynamic_cast <ConnectionDescriptor*> (Bindable_t::GetObject (binding));
213
+ if (cd)
214
+ cd->SetNotifyWritable (mode ? true : false);
215
+ }
216
+
217
+ /**********
218
+ evma_pause
219
+ **********/
220
+
221
+ extern "C" int evma_pause (const unsigned long binding)
222
+ {
223
+ ConnectionDescriptor *cd = dynamic_cast <ConnectionDescriptor*> (Bindable_t::GetObject (binding));
224
+ if (cd)
225
+ return cd->Pause() ? 1 : 0;
226
+
227
+ return 0;
228
+ }
229
+
230
+ /***********
231
+ evma_resume
232
+ ***********/
233
+
234
+ extern "C" int evma_resume (const unsigned long binding)
235
+ {
236
+ ConnectionDescriptor *cd = dynamic_cast <ConnectionDescriptor*> (Bindable_t::GetObject (binding));
237
+ if (cd)
238
+ return cd->Resume() ? 1 : 0;
239
+
240
+ return 0;
241
+ }
242
+
243
+ /**************
244
+ evma_is_paused
245
+ **************/
246
+
247
+ extern "C" int evma_is_paused (const unsigned long binding)
248
+ {
249
+ ConnectionDescriptor *cd = dynamic_cast <ConnectionDescriptor*> (Bindable_t::GetObject (binding));
250
+ if (cd)
251
+ return cd->IsPaused() ? 1 : 0;
252
+
253
+ return 0;
254
+ }
255
+
256
+ /**********************
257
+ evma_create_tcp_server
258
+ **********************/
259
+
260
+ extern "C" const unsigned long evma_create_tcp_server (const char *address, int port)
261
+ {
262
+ ensure_eventmachine("evma_create_tcp_server");
263
+ return EventMachine->CreateTcpServer (address, port);
264
+ }
265
+
266
+ /******************************
267
+ evma_create_unix_domain_server
268
+ ******************************/
269
+
270
+ extern "C" const unsigned long evma_create_unix_domain_server (const char *filename)
271
+ {
272
+ ensure_eventmachine("evma_create_unix_domain_server");
273
+ return EventMachine->CreateUnixDomainServer (filename);
274
+ }
275
+
276
+ /*************************
277
+ evma_open_datagram_socket
278
+ *************************/
279
+
280
+ extern "C" const unsigned long evma_open_datagram_socket (const char *address, int port)
281
+ {
282
+ ensure_eventmachine("evma_open_datagram_socket");
283
+ return EventMachine->OpenDatagramSocket (address, port);
284
+ }
285
+
286
+ /******************
287
+ evma_open_keyboard
288
+ ******************/
289
+
290
+ extern "C" const unsigned long evma_open_keyboard()
291
+ {
292
+ ensure_eventmachine("evma_open_keyboard");
293
+ return EventMachine->OpenKeyboard();
294
+ }
295
+
296
+ /*******************
297
+ evma_watch_filename
298
+ *******************/
299
+
300
+ extern "C" const unsigned long evma_watch_filename (const char *fname)
301
+ {
302
+ ensure_eventmachine("evma_watch_filename");
303
+ return EventMachine->WatchFile(fname);
304
+ }
305
+
306
+ /*********************
307
+ evma_unwatch_filename
308
+ *********************/
309
+
310
+ extern "C" void evma_unwatch_filename (const unsigned long sig)
311
+ {
312
+ ensure_eventmachine("evma_unwatch_file");
313
+ EventMachine->UnwatchFile(sig);
314
+ }
315
+
316
+ /**************
317
+ evma_watch_pid
318
+ **************/
319
+
320
+ extern "C" const unsigned long evma_watch_pid (int pid)
321
+ {
322
+ ensure_eventmachine("evma_watch_pid");
323
+ return EventMachine->WatchPid(pid);
324
+ }
325
+
326
+ /****************
327
+ evma_unwatch_pid
328
+ ****************/
329
+
330
+ extern "C" void evma_unwatch_pid (const unsigned long sig)
331
+ {
332
+ ensure_eventmachine("evma_unwatch_pid");
333
+ EventMachine->UnwatchPid(sig);
334
+ }
335
+
336
+ /****************************
337
+ evma_send_data_to_connection
338
+ ****************************/
339
+
340
+ extern "C" int evma_send_data_to_connection (const unsigned long binding, const char *data, int data_length)
341
+ {
342
+ ensure_eventmachine("evma_send_data_to_connection");
343
+ return ConnectionDescriptor::SendDataToConnection (binding, data, data_length);
344
+ }
345
+
346
+ /******************
347
+ evma_send_datagram
348
+ ******************/
349
+
350
+ extern "C" int evma_send_datagram (const unsigned long binding, const char *data, int data_length, const char *address, int port)
351
+ {
352
+ ensure_eventmachine("evma_send_datagram");
353
+ return DatagramDescriptor::SendDatagram (binding, data, data_length, address, port);
354
+ }
355
+
356
+
357
+ /*********************
358
+ evma_close_connection
359
+ *********************/
360
+
361
+ extern "C" void evma_close_connection (const unsigned long binding, int after_writing)
362
+ {
363
+ ensure_eventmachine("evma_close_connection");
364
+ ConnectionDescriptor::CloseConnection (binding, (after_writing ? true : false));
365
+ }
366
+
367
+ /***********************************
368
+ evma_report_connection_error_status
369
+ ***********************************/
370
+
371
+ extern "C" int evma_report_connection_error_status (const unsigned long binding)
372
+ {
373
+ ensure_eventmachine("evma_report_connection_error_status");
374
+ return ConnectionDescriptor::ReportErrorStatus (binding);
375
+ }
376
+
377
+ /********************
378
+ evma_stop_tcp_server
379
+ ********************/
380
+
381
+ extern "C" void evma_stop_tcp_server (const unsigned long binding)
382
+ {
383
+ ensure_eventmachine("evma_stop_tcp_server");
384
+ AcceptorDescriptor::StopAcceptor (binding);
385
+ }
386
+
387
+
388
+ /*****************
389
+ evma_stop_machine
390
+ *****************/
391
+
392
+ extern "C" void evma_stop_machine()
393
+ {
394
+ ensure_eventmachine("evma_stop_machine");
395
+ EventMachine->ScheduleHalt();
396
+ }
397
+
398
+
399
+ /**************
400
+ evma_start_tls
401
+ **************/
402
+
403
+ extern "C" void evma_start_tls (const unsigned long binding)
404
+ {
405
+ ensure_eventmachine("evma_start_tls");
406
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
407
+ if (ed)
408
+ ed->StartTls();
409
+ }
410
+
411
+ /******************
412
+ evma_set_tls_parms
413
+ ******************/
414
+
415
+ extern "C" void evma_set_tls_parms (const unsigned long binding, const char *privatekey_filename, const char *certchain_filename, int verify_peer)
416
+ {
417
+ ensure_eventmachine("evma_set_tls_parms");
418
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
419
+ if (ed)
420
+ ed->SetTlsParms (privatekey_filename, certchain_filename, (verify_peer == 1 ? true : false));
421
+ }
422
+
423
+ /******************
424
+ evma_get_peer_cert
425
+ ******************/
426
+
427
+ #ifdef WITH_SSL
428
+ extern "C" X509 *evma_get_peer_cert (const unsigned long binding)
429
+ {
430
+ ensure_eventmachine("evma_get_peer_cert");
431
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
432
+ if (ed)
433
+ return ed->GetPeerCert();
434
+ return NULL;
435
+ }
436
+ #endif
437
+
438
+ /********************
439
+ evma_accept_ssl_peer
440
+ ********************/
441
+
442
+ #ifdef WITH_SSL
443
+ extern "C" void evma_accept_ssl_peer (const unsigned long binding)
444
+ {
445
+ ensure_eventmachine("evma_accept_ssl_peer");
446
+ ConnectionDescriptor *cd = dynamic_cast <ConnectionDescriptor*> (Bindable_t::GetObject (binding));
447
+ if (cd)
448
+ cd->AcceptSslPeer();
449
+ }
450
+ #endif
451
+
452
+ /*****************
453
+ evma_get_peername
454
+ *****************/
455
+
456
+ extern "C" int evma_get_peername (const unsigned long binding, struct sockaddr *sa)
457
+ {
458
+ ensure_eventmachine("evma_get_peername");
459
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
460
+ if (ed) {
461
+ return ed->GetPeername (sa) ? 1 : 0;
462
+ }
463
+ else
464
+ return 0;
465
+ }
466
+
467
+ /*****************
468
+ evma_get_sockname
469
+ *****************/
470
+
471
+ extern "C" int evma_get_sockname (const unsigned long binding, struct sockaddr *sa)
472
+ {
473
+ ensure_eventmachine("evma_get_sockname");
474
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
475
+ if (ed) {
476
+ return ed->GetSockname (sa) ? 1 : 0;
477
+ }
478
+ else
479
+ return 0;
480
+ }
481
+
482
+ /***********************
483
+ evma_get_subprocess_pid
484
+ ***********************/
485
+
486
+ extern "C" int evma_get_subprocess_pid (const unsigned long binding, pid_t *pid)
487
+ {
488
+ ensure_eventmachine("evma_get_subprocess_pid");
489
+ #ifdef OS_UNIX
490
+ PipeDescriptor *pd = dynamic_cast <PipeDescriptor*> (Bindable_t::GetObject (binding));
491
+ if (pd) {
492
+ return pd->GetSubprocessPid (pid) ? 1 : 0;
493
+ }
494
+ else if (pid && EventMachine->SubprocessPid) {
495
+ *pid = EventMachine->SubprocessPid;
496
+ return 1;
497
+ }
498
+ else
499
+ return 0;
500
+ #else
501
+ return 0;
502
+ #endif
503
+ }
504
+
505
+ /**************************
506
+ evma_get_subprocess_status
507
+ **************************/
508
+
509
+ extern "C" int evma_get_subprocess_status (const unsigned long binding, int *status)
510
+ {
511
+ ensure_eventmachine("evma_get_subprocess_status");
512
+ if (status) {
513
+ *status = EventMachine->SubprocessExitStatus;
514
+ return 1;
515
+ }
516
+ else
517
+ return 0;
518
+ }
519
+
520
+ /*************************
521
+ evma_get_connection_count
522
+ *************************/
523
+
524
+ extern "C" int evma_get_connection_count()
525
+ {
526
+ ensure_eventmachine("evma_get_connection_count");
527
+ return EventMachine->GetConnectionCount();
528
+ }
529
+
530
+ /*********************
531
+ evma_signal_loopbreak
532
+ *********************/
533
+
534
+ extern "C" void evma_signal_loopbreak()
535
+ {
536
+ ensure_eventmachine("evma_signal_loopbreak");
537
+ EventMachine->SignalLoopBreaker();
538
+ }
539
+
540
+
541
+
542
+ /****************
543
+ evma__write_file
544
+ ****************/
545
+
546
+ extern "C" const unsigned long evma__write_file (const char *filename)
547
+ {
548
+ ensure_eventmachine("evma__write_file");
549
+ return EventMachine->_OpenFileForWriting (filename);
550
+ }
551
+
552
+
553
+ /********************************
554
+ evma_get_comm_inactivity_timeout
555
+ ********************************/
556
+
557
+ extern "C" float evma_get_comm_inactivity_timeout (const unsigned long binding)
558
+ {
559
+ ensure_eventmachine("evma_get_comm_inactivity_timeout");
560
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
561
+ if (ed) {
562
+ return ed->GetCommInactivityTimeout();
563
+ }
564
+ else
565
+ return 0.0; //Perhaps this should be an exception. Access to an unknown binding.
566
+ }
567
+
568
+ /********************************
569
+ evma_set_comm_inactivity_timeout
570
+ ********************************/
571
+
572
+ extern "C" int evma_set_comm_inactivity_timeout (const unsigned long binding, float value)
573
+ {
574
+ ensure_eventmachine("evma_set_comm_inactivity_timeout");
575
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
576
+ if (ed) {
577
+ return ed->SetCommInactivityTimeout (value);
578
+ }
579
+ else
580
+ return 0; //Perhaps this should be an exception. Access to an unknown binding.
581
+ }
582
+
583
+
584
+ /********************************
585
+ evma_get_pending_connect_timeout
586
+ ********************************/
587
+
588
+ extern "C" float evma_get_pending_connect_timeout (const unsigned long binding)
589
+ {
590
+ ensure_eventmachine("evma_get_pending_connect_timeout");
591
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
592
+ if (ed) {
593
+ return ed->GetPendingConnectTimeout();
594
+ }
595
+ else
596
+ return 0.0;
597
+ }
598
+
599
+
600
+ /********************************
601
+ evma_set_pending_connect_timeout
602
+ ********************************/
603
+
604
+ extern "C" int evma_set_pending_connect_timeout (const unsigned long binding, float value)
605
+ {
606
+ ensure_eventmachine("evma_set_pending_connect_timeout");
607
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
608
+ if (ed) {
609
+ return ed->SetPendingConnectTimeout (value);
610
+ }
611
+ else
612
+ return 0;
613
+ }
614
+
615
+
616
+ /**********************
617
+ evma_set_timer_quantum
618
+ **********************/
619
+
620
+ extern "C" void evma_set_timer_quantum (int interval)
621
+ {
622
+ ensure_eventmachine("evma_set_timer_quantum");
623
+ EventMachine->SetTimerQuantum (interval);
624
+ }
625
+
626
+
627
+ /************************
628
+ evma_get_max_timer_count
629
+ ************************/
630
+
631
+ extern "C" int evma_get_max_timer_count()
632
+ {
633
+ return EventMachine_t::GetMaxTimerCount();
634
+ }
635
+
636
+
637
+ /************************
638
+ evma_set_max_timer_count
639
+ ************************/
640
+
641
+ extern "C" void evma_set_max_timer_count (int ct)
642
+ {
643
+ // This may only be called if the reactor is not running.
644
+
645
+ if (EventMachine)
646
+ #ifdef BUILD_FOR_RUBY
647
+ rb_raise(rb_eRuntimeError, "eventmachine already initialized: evma_set_max_timer_count");
648
+ #else
649
+ throw std::runtime_error ("eventmachine already initialized: evma_set_max_timer_count");
650
+ #endif
651
+ EventMachine_t::SetMaxTimerCount (ct);
652
+ }
653
+
654
+ /******************
655
+ evma_setuid_string
656
+ ******************/
657
+
658
+ extern "C" void evma_setuid_string (const char *username)
659
+ {
660
+ // We do NOT need to be running an EM instance because this method is static.
661
+ EventMachine_t::SetuidString (username);
662
+ }
663
+
664
+
665
+ /**********
666
+ evma_popen
667
+ **********/
668
+
669
+ extern "C" const unsigned long evma_popen (char * const*cmd_strings)
670
+ {
671
+ ensure_eventmachine("evma_popen");
672
+ return EventMachine->Socketpair (cmd_strings);
673
+ }
674
+
675
+
676
+ /***************************
677
+ evma_get_outbound_data_size
678
+ ***************************/
679
+
680
+ extern "C" int evma_get_outbound_data_size (const unsigned long binding)
681
+ {
682
+ ensure_eventmachine("evma_get_outbound_data_size");
683
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
684
+ return ed ? ed->GetOutboundDataSize() : 0;
685
+ }
686
+
687
+
688
+ /**************
689
+ evma_set_epoll
690
+ **************/
691
+
692
+ extern "C" void evma_set_epoll (int use)
693
+ {
694
+ bUseEpoll = !!use;
695
+ }
696
+
697
+ /***************
698
+ evma_set_kqueue
699
+ ***************/
700
+
701
+ extern "C" void evma_set_kqueue (int use)
702
+ {
703
+ bUseKqueue = !!use;
704
+ }
705
+
706
+
707
+ /**********************
708
+ evma_set_rlimit_nofile
709
+ **********************/
710
+
711
+ extern "C" int evma_set_rlimit_nofile (int nofiles)
712
+ {
713
+ return EventMachine_t::SetRlimitNofile (nofiles);
714
+ }
715
+
716
+
717
+ /*********************************
718
+ evma_send_file_data_to_connection
719
+ *********************************/
720
+
721
+ extern "C" int evma_send_file_data_to_connection (const unsigned long binding, const char *filename)
722
+ {
723
+ /* This is a sugaring over send_data_to_connection that reads a file into a
724
+ * locally-allocated buffer, and sends the file data to the remote peer.
725
+ * Return the number of bytes written to the caller.
726
+ * TODO, needs to impose a limit on the file size. This is intended only for
727
+ * small files. (I don't know, maybe 8K or less.) For larger files, use interleaved
728
+ * I/O to avoid slowing the rest of the system down.
729
+ * TODO: we should return a code rather than barf, in case of file-not-found.
730
+ * TODO, does this compile on Windows?
731
+ * TODO, given that we want this to work only with small files, how about allocating
732
+ * the buffer on the stack rather than the heap?
733
+ *
734
+ * Modified 25Jul07. This now returns -1 on file-too-large; 0 for success, and a positive
735
+ * errno in case of other errors.
736
+ *
737
+ * Contributed by Kirk Haines.
738
+ */
739
+
740
+ char data[32*1024];
741
+ int r;
742
+
743
+ ensure_eventmachine("evma_send_file_data_to_connection");
744
+
745
+ int Fd = open (filename, O_RDONLY);
746
+
747
+ if (Fd < 0)
748
+ return errno;
749
+ // From here on, all early returns MUST close Fd.
750
+
751
+ struct stat st;
752
+ if (fstat (Fd, &st)) {
753
+ int e = errno;
754
+ close (Fd);
755
+ return e;
756
+ }
757
+
758
+ off_t filesize = st.st_size;
759
+ if (filesize <= 0) {
760
+ close (Fd);
761
+ return 0;
762
+ }
763
+ else if (filesize > (off_t) sizeof(data)) {
764
+ close (Fd);
765
+ return -1;
766
+ }
767
+
768
+
769
+ r = read (Fd, data, filesize);
770
+ if (r != filesize) {
771
+ int e = errno;
772
+ close (Fd);
773
+ return e;
774
+ }
775
+ evma_send_data_to_connection (binding, data, r);
776
+ close (Fd);
777
+
778
+ return 0;
779
+ }
780
+
781
+
782
+ /****************
783
+ evma_start_proxy
784
+ *****************/
785
+
786
+ extern "C" void evma_start_proxy (const unsigned long from, const unsigned long to, const unsigned long bufsize)
787
+ {
788
+ ensure_eventmachine("evma_start_proxy");
789
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (from));
790
+ if (ed)
791
+ ed->StartProxy(to, bufsize);
792
+ }
793
+
794
+
795
+ /***************
796
+ evma_stop_proxy
797
+ ****************/
798
+
799
+ extern "C" void evma_stop_proxy (const unsigned long from)
800
+ {
801
+ ensure_eventmachine("evma_stop_proxy");
802
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (from));
803
+ if (ed)
804
+ ed->StopProxy();
805
+ }
806
+
807
+
808
+ /***************************
809
+ evma_get_heartbeat_interval
810
+ ****************************/
811
+
812
+ extern "C" float evma_get_heartbeat_interval()
813
+ {
814
+ ensure_eventmachine("evma_get_heartbeat_interval");
815
+ return EventMachine->GetHeartbeatInterval();
816
+ }
817
+
818
+
819
+ /***************************
820
+ evma_set_heartbeat_interval
821
+ ****************************/
822
+
823
+ extern "C" int evma_set_heartbeat_interval(float interval)
824
+ {
825
+ ensure_eventmachine("evma_set_heartbeat_interval");
826
+ return EventMachine->SetHeartbeatInterval(interval);
827
+ }