sensu-em 2.4.0-x86-mingw32

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 (178) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/.travis.yml +12 -0
  4. data/.yardopts +7 -0
  5. data/CHANGELOG.md +33 -0
  6. data/GNU +281 -0
  7. data/Gemfile +2 -0
  8. data/LICENSE +60 -0
  9. data/README.md +109 -0
  10. data/Rakefile +20 -0
  11. data/docs/DocumentationGuidesIndex.md +27 -0
  12. data/docs/GettingStarted.md +521 -0
  13. data/docs/old/ChangeLog +211 -0
  14. data/docs/old/DEFERRABLES +246 -0
  15. data/docs/old/EPOLL +141 -0
  16. data/docs/old/INSTALL +13 -0
  17. data/docs/old/KEYBOARD +42 -0
  18. data/docs/old/LEGAL +25 -0
  19. data/docs/old/LIGHTWEIGHT_CONCURRENCY +130 -0
  20. data/docs/old/PURE_RUBY +75 -0
  21. data/docs/old/RELEASE_NOTES +94 -0
  22. data/docs/old/SMTP +4 -0
  23. data/docs/old/SPAWNED_PROCESSES +148 -0
  24. data/docs/old/TODO +8 -0
  25. data/eventmachine.gemspec +37 -0
  26. data/examples/guides/getting_started/01_eventmachine_echo_server.rb +18 -0
  27. data/examples/guides/getting_started/02_eventmachine_echo_server_that_recognizes_exit_command.rb +22 -0
  28. data/examples/guides/getting_started/03_simple_chat_server.rb +149 -0
  29. data/examples/guides/getting_started/04_simple_chat_server_step_one.rb +27 -0
  30. data/examples/guides/getting_started/05_simple_chat_server_step_two.rb +43 -0
  31. data/examples/guides/getting_started/06_simple_chat_server_step_three.rb +98 -0
  32. data/examples/guides/getting_started/07_simple_chat_server_step_four.rb +121 -0
  33. data/examples/guides/getting_started/08_simple_chat_server_step_five.rb +141 -0
  34. data/examples/old/ex_channel.rb +43 -0
  35. data/examples/old/ex_queue.rb +2 -0
  36. data/examples/old/ex_tick_loop_array.rb +15 -0
  37. data/examples/old/ex_tick_loop_counter.rb +32 -0
  38. data/examples/old/helper.rb +2 -0
  39. data/ext/binder.cpp +124 -0
  40. data/ext/binder.h +46 -0
  41. data/ext/cmain.cpp +887 -0
  42. data/ext/ed.cpp +1992 -0
  43. data/ext/ed.h +424 -0
  44. data/ext/em.cpp +2352 -0
  45. data/ext/em.h +253 -0
  46. data/ext/eventmachine.h +128 -0
  47. data/ext/extconf.rb +179 -0
  48. data/ext/fastfilereader/extconf.rb +103 -0
  49. data/ext/fastfilereader/mapper.cpp +214 -0
  50. data/ext/fastfilereader/mapper.h +59 -0
  51. data/ext/fastfilereader/rubymain.cpp +127 -0
  52. data/ext/kb.cpp +79 -0
  53. data/ext/page.cpp +107 -0
  54. data/ext/page.h +51 -0
  55. data/ext/pipe.cpp +347 -0
  56. data/ext/project.h +161 -0
  57. data/ext/rubymain.cpp +1318 -0
  58. data/ext/ssl.cpp +476 -0
  59. data/ext/ssl.h +95 -0
  60. data/java/.classpath +6 -0
  61. data/java/.gitignore +1 -0
  62. data/java/.project +17 -0
  63. data/java/src/com/rubyeventmachine/DatagramPacket.java +13 -0
  64. data/java/src/com/rubyeventmachine/EmReactor.java +531 -0
  65. data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
  66. data/java/src/com/rubyeventmachine/EventCallback.java +7 -0
  67. data/java/src/com/rubyeventmachine/EventCode.java +26 -0
  68. data/java/src/com/rubyeventmachine/EventableChannel.java +130 -0
  69. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +179 -0
  70. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +405 -0
  71. data/java/src/com/rubyeventmachine/SslBox.java +311 -0
  72. data/lib/em/buftok.rb +110 -0
  73. data/lib/em/callback.rb +58 -0
  74. data/lib/em/channel.rb +64 -0
  75. data/lib/em/completion.rb +304 -0
  76. data/lib/em/connection.rb +716 -0
  77. data/lib/em/deferrable.rb +210 -0
  78. data/lib/em/deferrable/pool.rb +2 -0
  79. data/lib/em/file_watch.rb +73 -0
  80. data/lib/em/future.rb +61 -0
  81. data/lib/em/iterator.rb +231 -0
  82. data/lib/em/messages.rb +66 -0
  83. data/lib/em/pool.rb +151 -0
  84. data/lib/em/process_watch.rb +45 -0
  85. data/lib/em/processes.rb +123 -0
  86. data/lib/em/protocols.rb +37 -0
  87. data/lib/em/protocols/header_and_content.rb +138 -0
  88. data/lib/em/protocols/httpclient.rb +279 -0
  89. data/lib/em/protocols/httpclient2.rb +600 -0
  90. data/lib/em/protocols/line_and_text.rb +125 -0
  91. data/lib/em/protocols/line_protocol.rb +29 -0
  92. data/lib/em/protocols/linetext2.rb +161 -0
  93. data/lib/em/protocols/memcache.rb +331 -0
  94. data/lib/em/protocols/object_protocol.rb +46 -0
  95. data/lib/em/protocols/postgres3.rb +246 -0
  96. data/lib/em/protocols/saslauth.rb +175 -0
  97. data/lib/em/protocols/smtpclient.rb +365 -0
  98. data/lib/em/protocols/smtpserver.rb +643 -0
  99. data/lib/em/protocols/socks4.rb +66 -0
  100. data/lib/em/protocols/stomp.rb +205 -0
  101. data/lib/em/protocols/tcptest.rb +54 -0
  102. data/lib/em/pure_ruby.rb +1017 -0
  103. data/lib/em/queue.rb +71 -0
  104. data/lib/em/resolver.rb +209 -0
  105. data/lib/em/spawnable.rb +84 -0
  106. data/lib/em/streamer.rb +118 -0
  107. data/lib/em/threaded_resource.rb +90 -0
  108. data/lib/em/tick_loop.rb +85 -0
  109. data/lib/em/timers.rb +61 -0
  110. data/lib/em/version.rb +3 -0
  111. data/lib/eventmachine.rb +1553 -0
  112. data/lib/fastfilereaderext.rb +2 -0
  113. data/lib/jeventmachine.rb +321 -0
  114. data/lib/rubyeventmachine.rb +2 -0
  115. data/rakelib/cpp.rake_example +77 -0
  116. data/rakelib/package.rake +98 -0
  117. data/rakelib/test.rake +8 -0
  118. data/tests/client.crt +31 -0
  119. data/tests/client.key +51 -0
  120. data/tests/em_test_helper.rb +64 -0
  121. data/tests/server.crt +36 -0
  122. data/tests/server.key +51 -0
  123. data/tests/test_attach.rb +150 -0
  124. data/tests/test_basic.rb +294 -0
  125. data/tests/test_channel.rb +62 -0
  126. data/tests/test_completion.rb +177 -0
  127. data/tests/test_connection_count.rb +53 -0
  128. data/tests/test_defer.rb +18 -0
  129. data/tests/test_deferrable.rb +35 -0
  130. data/tests/test_epoll.rb +145 -0
  131. data/tests/test_error_handler.rb +38 -0
  132. data/tests/test_exc.rb +28 -0
  133. data/tests/test_file_watch.rb +65 -0
  134. data/tests/test_futures.rb +170 -0
  135. data/tests/test_get_sock_opt.rb +37 -0
  136. data/tests/test_handler_check.rb +35 -0
  137. data/tests/test_hc.rb +155 -0
  138. data/tests/test_httpclient.rb +190 -0
  139. data/tests/test_httpclient2.rb +133 -0
  140. data/tests/test_idle_connection.rb +25 -0
  141. data/tests/test_inactivity_timeout.rb +54 -0
  142. data/tests/test_iterator.rb +97 -0
  143. data/tests/test_kb.rb +34 -0
  144. data/tests/test_line_protocol.rb +33 -0
  145. data/tests/test_ltp.rb +138 -0
  146. data/tests/test_ltp2.rb +288 -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 +102 -0
  150. data/tests/test_pending_connect_timeout.rb +52 -0
  151. data/tests/test_pool.rb +194 -0
  152. data/tests/test_process_watch.rb +48 -0
  153. data/tests/test_processes.rb +128 -0
  154. data/tests/test_proxy_connection.rb +180 -0
  155. data/tests/test_pure.rb +88 -0
  156. data/tests/test_queue.rb +50 -0
  157. data/tests/test_resolver.rb +55 -0
  158. data/tests/test_running.rb +14 -0
  159. data/tests/test_sasl.rb +47 -0
  160. data/tests/test_send_file.rb +217 -0
  161. data/tests/test_servers.rb +33 -0
  162. data/tests/test_set_sock_opt.rb +37 -0
  163. data/tests/test_shutdown_hooks.rb +23 -0
  164. data/tests/test_smtpclient.rb +55 -0
  165. data/tests/test_smtpserver.rb +57 -0
  166. data/tests/test_spawn.rb +293 -0
  167. data/tests/test_ssl_args.rb +78 -0
  168. data/tests/test_ssl_echo_data.rb +60 -0
  169. data/tests/test_ssl_methods.rb +56 -0
  170. data/tests/test_ssl_verify.rb +82 -0
  171. data/tests/test_stomp.rb +37 -0
  172. data/tests/test_system.rb +42 -0
  173. data/tests/test_threaded_resource.rb +53 -0
  174. data/tests/test_tick_loop.rb +59 -0
  175. data/tests/test_timers.rb +123 -0
  176. data/tests/test_ud.rb +8 -0
  177. data/tests/test_unbind_reason.rb +48 -0
  178. metadata +300 -0
@@ -0,0 +1,2 @@
1
+ $:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
2
+ require 'eventmachine'
data/ext/binder.cpp ADDED
@@ -0,0 +1,124 @@
1
+ /*****************************************************************************
2
+
3
+ $Id$
4
+
5
+ File: binder.cpp
6
+ Date: 07Apr06
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
+ #define DEV_URANDOM "/dev/urandom"
23
+
24
+
25
+ map<unsigned long, Bindable_t*> Bindable_t::BindingBag;
26
+
27
+
28
+ /********************************
29
+ STATIC Bindable_t::CreateBinding
30
+ ********************************/
31
+
32
+ unsigned long Bindable_t::CreateBinding()
33
+ {
34
+ static unsigned long num = 0;
35
+ while(BindingBag[++num]) {}
36
+ return num;
37
+ }
38
+
39
+ #if 0
40
+ string Bindable_t::CreateBinding()
41
+ {
42
+ static int index = 0;
43
+ static string seed;
44
+
45
+ if ((index >= 1000000) || (seed.length() == 0)) {
46
+ #ifdef OS_UNIX
47
+ int fd = open (DEV_URANDOM, O_RDONLY);
48
+ if (fd < 0)
49
+ throw std::runtime_error ("No entropy device");
50
+
51
+ unsigned char u[16];
52
+ size_t r = read (fd, u, sizeof(u));
53
+ if (r < sizeof(u))
54
+ throw std::runtime_error ("Unable to read entropy device");
55
+
56
+ unsigned char *u1 = (unsigned char*)u;
57
+ char u2 [sizeof(u) * 2 + 1];
58
+
59
+ for (size_t i=0; i < sizeof(u); i++)
60
+ sprintf (u2 + (i * 2), "%02x", u1[i]);
61
+
62
+ seed = string (u2);
63
+ #endif
64
+
65
+
66
+ #ifdef OS_WIN32
67
+ UUID uuid;
68
+ UuidCreate (&uuid);
69
+ unsigned char *uuidstring = NULL;
70
+ UuidToString (&uuid, &uuidstring);
71
+ if (!uuidstring)
72
+ throw std::runtime_error ("Unable to read uuid");
73
+ seed = string ((const char*)uuidstring);
74
+
75
+ RpcStringFree (&uuidstring);
76
+ #endif
77
+
78
+ index = 0;
79
+
80
+
81
+ }
82
+
83
+ stringstream ss;
84
+ ss << seed << (++index);
85
+ return ss.str();
86
+ }
87
+ #endif
88
+
89
+ /*****************************
90
+ STATIC: Bindable_t::GetObject
91
+ *****************************/
92
+
93
+ Bindable_t *Bindable_t::GetObject (const unsigned long binding)
94
+ {
95
+ map<unsigned long, Bindable_t*>::const_iterator i = BindingBag.find (binding);
96
+ if (i != BindingBag.end())
97
+ return i->second;
98
+ else
99
+ return NULL;
100
+ }
101
+
102
+
103
+ /**********************
104
+ Bindable_t::Bindable_t
105
+ **********************/
106
+
107
+ Bindable_t::Bindable_t()
108
+ {
109
+ Binding = Bindable_t::CreateBinding();
110
+ BindingBag [Binding] = this;
111
+ }
112
+
113
+
114
+
115
+ /***********************
116
+ Bindable_t::~Bindable_t
117
+ ***********************/
118
+
119
+ Bindable_t::~Bindable_t()
120
+ {
121
+ BindingBag.erase (Binding);
122
+ }
123
+
124
+
data/ext/binder.h ADDED
@@ -0,0 +1,46 @@
1
+ /*****************************************************************************
2
+
3
+ $Id$
4
+
5
+ File: binder.h
6
+ Date: 07Apr06
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
+ #ifndef __ObjectBindings__H_
21
+ #define __ObjectBindings__H_
22
+
23
+
24
+ class Bindable_t
25
+ {
26
+ public:
27
+ static unsigned long CreateBinding();
28
+ static Bindable_t *GetObject (const unsigned long);
29
+ static map<unsigned long, Bindable_t*> BindingBag;
30
+
31
+ public:
32
+ Bindable_t();
33
+ virtual ~Bindable_t();
34
+
35
+ const unsigned long GetBinding() {return Binding;}
36
+
37
+ private:
38
+ unsigned long Binding;
39
+ };
40
+
41
+
42
+
43
+
44
+
45
+ #endif // __ObjectBindings__H_
46
+
data/ext/cmain.cpp ADDED
@@ -0,0 +1,887 @@
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
+ #undef fstat
29
+ #endif
30
+
31
+ static EventMachine_t *EventMachine;
32
+ static int bUseEpoll = 0;
33
+ static int bUseKqueue = 0;
34
+
35
+ extern "C" void ensure_eventmachine (const char *caller = "unknown caller")
36
+ {
37
+ if (!EventMachine) {
38
+ const int err_size = 128;
39
+ char err_string[err_size];
40
+ snprintf (err_string, err_size, "eventmachine not initialized: %s", caller);
41
+ #ifdef BUILD_FOR_RUBY
42
+ rb_raise(rb_eRuntimeError, "%s", err_string);
43
+ #else
44
+ throw std::runtime_error (err_string);
45
+ #endif
46
+ }
47
+ }
48
+
49
+ /***********************
50
+ evma_initialize_library
51
+ ***********************/
52
+
53
+ extern "C" void evma_initialize_library (EMCallback cb)
54
+ {
55
+ if (EventMachine)
56
+ #ifdef BUILD_FOR_RUBY
57
+ rb_raise(rb_eRuntimeError, "eventmachine already initialized: evma_initialize_library");
58
+ #else
59
+ throw std::runtime_error ("eventmachine already initialized: evma_initialize_library");
60
+ #endif
61
+ EventMachine = new EventMachine_t (cb);
62
+ if (bUseEpoll)
63
+ EventMachine->_UseEpoll();
64
+ if (bUseKqueue)
65
+ EventMachine->_UseKqueue();
66
+ }
67
+
68
+
69
+ /********************
70
+ evma_release_library
71
+ ********************/
72
+
73
+ extern "C" void evma_release_library()
74
+ {
75
+ ensure_eventmachine("evma_release_library");
76
+ delete EventMachine;
77
+ EventMachine = NULL;
78
+ }
79
+
80
+
81
+ /****************
82
+ evma_run_machine
83
+ ****************/
84
+
85
+ extern "C" void evma_run_machine()
86
+ {
87
+ ensure_eventmachine("evma_run_machine");
88
+ EventMachine->Run();
89
+ }
90
+
91
+
92
+ /**************************
93
+ evma_install_oneshot_timer
94
+ **************************/
95
+
96
+ extern "C" const unsigned long evma_install_oneshot_timer (int seconds)
97
+ {
98
+ ensure_eventmachine("evma_install_oneshot_timer");
99
+ return EventMachine->InstallOneshotTimer (seconds);
100
+ }
101
+
102
+
103
+ /**********************
104
+ evma_connect_to_server
105
+ **********************/
106
+
107
+ extern "C" const unsigned long evma_connect_to_server (const char *bind_addr, int bind_port, const char *server, int port)
108
+ {
109
+ ensure_eventmachine("evma_connect_to_server");
110
+ return EventMachine->ConnectToServer (bind_addr, bind_port, server, port);
111
+ }
112
+
113
+ /***************************
114
+ evma_connect_to_unix_server
115
+ ***************************/
116
+
117
+ extern "C" const unsigned long evma_connect_to_unix_server (const char *server)
118
+ {
119
+ ensure_eventmachine("evma_connect_to_unix_server");
120
+ return EventMachine->ConnectToUnixServer (server);
121
+ }
122
+
123
+ /**************
124
+ evma_attach_fd
125
+ **************/
126
+
127
+ extern "C" const unsigned long evma_attach_fd (int file_descriptor, int watch_mode)
128
+ {
129
+ ensure_eventmachine("evma_attach_fd");
130
+ return EventMachine->AttachFD (file_descriptor, watch_mode ? true : false);
131
+ }
132
+
133
+ /**************
134
+ evma_detach_fd
135
+ **************/
136
+
137
+ extern "C" int evma_detach_fd (const unsigned long binding)
138
+ {
139
+ ensure_eventmachine("evma_detach_fd");
140
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
141
+ if (ed)
142
+ return EventMachine->DetachFD (ed);
143
+ else
144
+ #ifdef BUILD_FOR_RUBY
145
+ rb_raise(rb_eRuntimeError, "invalid binding to detach");
146
+ #else
147
+ throw std::runtime_error ("invalid binding to detach");
148
+ #endif
149
+ return -1;
150
+ }
151
+
152
+ /************************
153
+ evma_get_file_descriptor
154
+ ************************/
155
+
156
+ extern "C" int evma_get_file_descriptor (const unsigned long binding)
157
+ {
158
+ ensure_eventmachine("evma_get_file_descriptor");
159
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
160
+ if (ed)
161
+ return ed->GetSocket();
162
+ else
163
+ #ifdef BUILD_FOR_RUBY
164
+ rb_raise(rb_eRuntimeError, "invalid binding to get_fd");
165
+ #else
166
+ throw std::runtime_error ("invalid binding to get_fd");
167
+ #endif
168
+ return -1;
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
+ EventableDescriptor *cd = dynamic_cast <EventableDescriptor*> (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
+ EventableDescriptor *cd = dynamic_cast <EventableDescriptor*> (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
+ EventableDescriptor *cd = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
250
+ if (cd)
251
+ return cd->IsPaused() ? 1 : 0;
252
+
253
+ return 0;
254
+ }
255
+
256
+ /************************
257
+ evma_num_close_scheduled
258
+ ************************/
259
+
260
+ extern "C" int evma_num_close_scheduled ()
261
+ {
262
+ ensure_eventmachine("evma_num_close_scheduled");
263
+ return EventMachine->NumCloseScheduled;
264
+ }
265
+
266
+ /**********************
267
+ evma_create_tcp_server
268
+ **********************/
269
+
270
+ extern "C" const unsigned long evma_create_tcp_server (const char *address, int port)
271
+ {
272
+ ensure_eventmachine("evma_create_tcp_server");
273
+ return EventMachine->CreateTcpServer (address, port);
274
+ }
275
+
276
+ /******************************
277
+ evma_create_unix_domain_server
278
+ ******************************/
279
+
280
+ extern "C" const unsigned long evma_create_unix_domain_server (const char *filename)
281
+ {
282
+ ensure_eventmachine("evma_create_unix_domain_server");
283
+ return EventMachine->CreateUnixDomainServer (filename);
284
+ }
285
+
286
+ /***********************
287
+ evma_attach_sd
288
+ ************************/
289
+
290
+ extern "C" const unsigned long evma_attach_sd (int sd)
291
+ {
292
+ ensure_eventmachine("evma_attach_sd");
293
+ return EventMachine->AttachSD (sd);
294
+ }
295
+
296
+ /*************************
297
+ evma_open_datagram_socket
298
+ *************************/
299
+
300
+ extern "C" const unsigned long evma_open_datagram_socket (const char *address, int port)
301
+ {
302
+ ensure_eventmachine("evma_open_datagram_socket");
303
+ return EventMachine->OpenDatagramSocket (address, port);
304
+ }
305
+
306
+ /******************
307
+ evma_open_keyboard
308
+ ******************/
309
+
310
+ extern "C" const unsigned long evma_open_keyboard()
311
+ {
312
+ ensure_eventmachine("evma_open_keyboard");
313
+ return EventMachine->OpenKeyboard();
314
+ }
315
+
316
+ /*******************
317
+ evma_watch_filename
318
+ *******************/
319
+
320
+ extern "C" const unsigned long evma_watch_filename (const char *fname)
321
+ {
322
+ ensure_eventmachine("evma_watch_filename");
323
+ return EventMachine->WatchFile(fname);
324
+ }
325
+
326
+ /*********************
327
+ evma_unwatch_filename
328
+ *********************/
329
+
330
+ extern "C" void evma_unwatch_filename (const unsigned long sig)
331
+ {
332
+ ensure_eventmachine("evma_unwatch_file");
333
+ EventMachine->UnwatchFile(sig);
334
+ }
335
+
336
+ /**************
337
+ evma_watch_pid
338
+ **************/
339
+
340
+ extern "C" const unsigned long evma_watch_pid (int pid)
341
+ {
342
+ ensure_eventmachine("evma_watch_pid");
343
+ return EventMachine->WatchPid(pid);
344
+ }
345
+
346
+ /****************
347
+ evma_unwatch_pid
348
+ ****************/
349
+
350
+ extern "C" void evma_unwatch_pid (const unsigned long sig)
351
+ {
352
+ ensure_eventmachine("evma_unwatch_pid");
353
+ EventMachine->UnwatchPid(sig);
354
+ }
355
+
356
+ /****************************
357
+ evma_send_data_to_connection
358
+ ****************************/
359
+
360
+ extern "C" int evma_send_data_to_connection (const unsigned long binding, const char *data, int data_length)
361
+ {
362
+ ensure_eventmachine("evma_send_data_to_connection");
363
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
364
+ if (ed)
365
+ return ed->SendOutboundData(data, data_length);
366
+ return -1;
367
+ }
368
+
369
+ /******************
370
+ evma_send_datagram
371
+ ******************/
372
+
373
+ extern "C" int evma_send_datagram (const unsigned long binding, const char *data, int data_length, const char *address, int port)
374
+ {
375
+ ensure_eventmachine("evma_send_datagram");
376
+ DatagramDescriptor *dd = dynamic_cast <DatagramDescriptor*> (Bindable_t::GetObject (binding));
377
+ if (dd)
378
+ return dd->SendOutboundDatagram(data, data_length, address, port);
379
+ return -1;
380
+ }
381
+
382
+
383
+ /*********************
384
+ evma_close_connection
385
+ *********************/
386
+
387
+ extern "C" void evma_close_connection (const unsigned long binding, int after_writing)
388
+ {
389
+ ensure_eventmachine("evma_close_connection");
390
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
391
+ if (ed)
392
+ ed->ScheduleClose (after_writing ? true : false);
393
+ }
394
+
395
+ /***********************************
396
+ evma_report_connection_error_status
397
+ ***********************************/
398
+
399
+ extern "C" int evma_report_connection_error_status (const unsigned long binding)
400
+ {
401
+ ensure_eventmachine("evma_report_connection_error_status");
402
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
403
+ if (ed)
404
+ return ed->ReportErrorStatus();
405
+ return -1;
406
+ }
407
+
408
+ /********************
409
+ evma_stop_tcp_server
410
+ ********************/
411
+
412
+ extern "C" void evma_stop_tcp_server (const unsigned long binding)
413
+ {
414
+ ensure_eventmachine("evma_stop_tcp_server");
415
+ AcceptorDescriptor::StopAcceptor (binding);
416
+ }
417
+
418
+
419
+ /*****************
420
+ evma_stop_machine
421
+ *****************/
422
+
423
+ extern "C" void evma_stop_machine()
424
+ {
425
+ ensure_eventmachine("evma_stop_machine");
426
+ EventMachine->ScheduleHalt();
427
+ }
428
+
429
+
430
+ /**************
431
+ evma_start_tls
432
+ **************/
433
+
434
+ extern "C" void evma_start_tls (const unsigned long binding)
435
+ {
436
+ ensure_eventmachine("evma_start_tls");
437
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
438
+ if (ed)
439
+ ed->StartTls();
440
+ }
441
+
442
+ /******************
443
+ evma_set_tls_parms
444
+ ******************/
445
+
446
+ extern "C" void evma_set_tls_parms (const unsigned long binding, const char *privatekey_filename, const char *certchain_filename, int verify_peer, int use_tls, const char *cipherlist)
447
+ {
448
+ ensure_eventmachine("evma_set_tls_parms");
449
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
450
+ if (ed)
451
+ ed->SetTlsParms (privatekey_filename, certchain_filename, (verify_peer == 1 ? true : false), (use_tls == 1 ? true : false), cipherlist);
452
+ }
453
+
454
+ /******************
455
+ evma_get_peer_cert
456
+ ******************/
457
+
458
+ #ifdef WITH_SSL
459
+ extern "C" X509 *evma_get_peer_cert (const unsigned long binding)
460
+ {
461
+ ensure_eventmachine("evma_get_peer_cert");
462
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
463
+ if (ed)
464
+ return ed->GetPeerCert();
465
+ return NULL;
466
+ }
467
+ #endif
468
+
469
+ /********************
470
+ evma_accept_ssl_peer
471
+ ********************/
472
+
473
+ #ifdef WITH_SSL
474
+ extern "C" void evma_accept_ssl_peer (const unsigned long binding)
475
+ {
476
+ ensure_eventmachine("evma_accept_ssl_peer");
477
+ ConnectionDescriptor *cd = dynamic_cast <ConnectionDescriptor*> (Bindable_t::GetObject (binding));
478
+ if (cd)
479
+ cd->AcceptSslPeer();
480
+ }
481
+ #endif
482
+
483
+ /*****************
484
+ evma_get_peername
485
+ *****************/
486
+
487
+ extern "C" int evma_get_peername (const unsigned long binding, struct sockaddr *sa, socklen_t *len)
488
+ {
489
+ ensure_eventmachine("evma_get_peername");
490
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
491
+ if (ed) {
492
+ return ed->GetPeername (sa, len) ? 1 : 0;
493
+ }
494
+ else
495
+ return 0;
496
+ }
497
+
498
+ /*****************
499
+ evma_get_sockname
500
+ *****************/
501
+
502
+ extern "C" int evma_get_sockname (const unsigned long binding, struct sockaddr *sa, socklen_t *len)
503
+ {
504
+ ensure_eventmachine("evma_get_sockname");
505
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
506
+ if (ed) {
507
+ return ed->GetSockname (sa, len) ? 1 : 0;
508
+ }
509
+ else
510
+ return 0;
511
+ }
512
+
513
+ /***********************
514
+ evma_get_subprocess_pid
515
+ ***********************/
516
+
517
+ extern "C" int evma_get_subprocess_pid (const unsigned long binding, pid_t *pid)
518
+ {
519
+ ensure_eventmachine("evma_get_subprocess_pid");
520
+ #ifdef OS_UNIX
521
+ PipeDescriptor *pd = dynamic_cast <PipeDescriptor*> (Bindable_t::GetObject (binding));
522
+ if (pd) {
523
+ return pd->GetSubprocessPid (pid) ? 1 : 0;
524
+ }
525
+ else if (pid && EventMachine->SubprocessPid) {
526
+ *pid = EventMachine->SubprocessPid;
527
+ return 1;
528
+ }
529
+ else
530
+ return 0;
531
+ #else
532
+ return 0;
533
+ #endif
534
+ }
535
+
536
+ /**************************
537
+ evma_get_subprocess_status
538
+ **************************/
539
+
540
+ extern "C" int evma_get_subprocess_status (const unsigned long binding, int *status)
541
+ {
542
+ ensure_eventmachine("evma_get_subprocess_status");
543
+ if (status) {
544
+ *status = EventMachine->SubprocessExitStatus;
545
+ return 1;
546
+ }
547
+ else
548
+ return 0;
549
+ }
550
+
551
+ /*************************
552
+ evma_get_connection_count
553
+ *************************/
554
+
555
+ extern "C" int evma_get_connection_count()
556
+ {
557
+ ensure_eventmachine("evma_get_connection_count");
558
+ return EventMachine->GetConnectionCount();
559
+ }
560
+
561
+ /*********************
562
+ evma_signal_loopbreak
563
+ *********************/
564
+
565
+ extern "C" void evma_signal_loopbreak()
566
+ {
567
+ ensure_eventmachine("evma_signal_loopbreak");
568
+ EventMachine->SignalLoopBreaker();
569
+ }
570
+
571
+
572
+
573
+ /********************************
574
+ evma_get_comm_inactivity_timeout
575
+ ********************************/
576
+
577
+ extern "C" float evma_get_comm_inactivity_timeout (const unsigned long binding)
578
+ {
579
+ ensure_eventmachine("evma_get_comm_inactivity_timeout");
580
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
581
+ if (ed) {
582
+ return ((float)ed->GetCommInactivityTimeout() / 1000);
583
+ }
584
+ else
585
+ return 0.0; //Perhaps this should be an exception. Access to an unknown binding.
586
+ }
587
+
588
+ /********************************
589
+ evma_set_comm_inactivity_timeout
590
+ ********************************/
591
+
592
+ extern "C" int evma_set_comm_inactivity_timeout (const unsigned long binding, float value)
593
+ {
594
+ ensure_eventmachine("evma_set_comm_inactivity_timeout");
595
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
596
+ if (ed) {
597
+ return ed->SetCommInactivityTimeout ((uint64_t)(value * 1000));
598
+ }
599
+ else
600
+ return 0; //Perhaps this should be an exception. Access to an unknown binding.
601
+ }
602
+
603
+
604
+ /********************************
605
+ evma_get_pending_connect_timeout
606
+ ********************************/
607
+
608
+ extern "C" float evma_get_pending_connect_timeout (const unsigned long binding)
609
+ {
610
+ ensure_eventmachine("evma_get_pending_connect_timeout");
611
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
612
+ if (ed) {
613
+ return ((float)ed->GetPendingConnectTimeout() / 1000);
614
+ }
615
+ else
616
+ return 0.0;
617
+ }
618
+
619
+
620
+ /********************************
621
+ evma_set_pending_connect_timeout
622
+ ********************************/
623
+
624
+ extern "C" int evma_set_pending_connect_timeout (const unsigned long binding, float value)
625
+ {
626
+ ensure_eventmachine("evma_set_pending_connect_timeout");
627
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
628
+ if (ed) {
629
+ return ed->SetPendingConnectTimeout ((uint64_t)(value * 1000));
630
+ }
631
+ else
632
+ return 0;
633
+ }
634
+
635
+
636
+ /**********************
637
+ evma_set_timer_quantum
638
+ **********************/
639
+
640
+ extern "C" void evma_set_timer_quantum (int interval)
641
+ {
642
+ ensure_eventmachine("evma_set_timer_quantum");
643
+ EventMachine->SetTimerQuantum (interval);
644
+ }
645
+
646
+
647
+ /************************
648
+ evma_get_max_timer_count
649
+ ************************/
650
+
651
+ extern "C" int evma_get_max_timer_count()
652
+ {
653
+ return EventMachine_t::GetMaxTimerCount();
654
+ }
655
+
656
+
657
+ /************************
658
+ evma_set_max_timer_count
659
+ ************************/
660
+
661
+ extern "C" void evma_set_max_timer_count (int ct)
662
+ {
663
+ // This may only be called if the reactor is not running.
664
+
665
+ if (EventMachine)
666
+ #ifdef BUILD_FOR_RUBY
667
+ rb_raise(rb_eRuntimeError, "eventmachine already initialized: evma_set_max_timer_count");
668
+ #else
669
+ throw std::runtime_error ("eventmachine already initialized: evma_set_max_timer_count");
670
+ #endif
671
+ EventMachine_t::SetMaxTimerCount (ct);
672
+ }
673
+
674
+ /******************
675
+ evma_setuid_string
676
+ ******************/
677
+
678
+ extern "C" void evma_setuid_string (const char *username)
679
+ {
680
+ // We do NOT need to be running an EM instance because this method is static.
681
+ EventMachine_t::SetuidString (username);
682
+ }
683
+
684
+
685
+ /**********
686
+ evma_popen
687
+ **********/
688
+
689
+ extern "C" const unsigned long evma_popen (char * const*cmd_strings)
690
+ {
691
+ ensure_eventmachine("evma_popen");
692
+ return EventMachine->Socketpair (cmd_strings);
693
+ }
694
+
695
+
696
+ /***************************
697
+ evma_get_outbound_data_size
698
+ ***************************/
699
+
700
+ extern "C" int evma_get_outbound_data_size (const unsigned long binding)
701
+ {
702
+ ensure_eventmachine("evma_get_outbound_data_size");
703
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
704
+ return ed ? ed->GetOutboundDataSize() : 0;
705
+ }
706
+
707
+
708
+ /**************
709
+ evma_set_epoll
710
+ **************/
711
+
712
+ extern "C" void evma_set_epoll (int use)
713
+ {
714
+ bUseEpoll = !!use;
715
+ }
716
+
717
+ /***************
718
+ evma_set_kqueue
719
+ ***************/
720
+
721
+ extern "C" void evma_set_kqueue (int use)
722
+ {
723
+ bUseKqueue = !!use;
724
+ }
725
+
726
+
727
+ /**********************
728
+ evma_set_rlimit_nofile
729
+ **********************/
730
+
731
+ extern "C" int evma_set_rlimit_nofile (int nofiles)
732
+ {
733
+ return EventMachine_t::SetRlimitNofile (nofiles);
734
+ }
735
+
736
+
737
+ /*********************************
738
+ evma_send_file_data_to_connection
739
+ *********************************/
740
+
741
+ extern "C" int evma_send_file_data_to_connection (const unsigned long binding, const char *filename)
742
+ {
743
+ /* This is a sugaring over send_data_to_connection that reads a file into a
744
+ * locally-allocated buffer, and sends the file data to the remote peer.
745
+ * Return the number of bytes written to the caller.
746
+ * TODO, needs to impose a limit on the file size. This is intended only for
747
+ * small files. (I don't know, maybe 8K or less.) For larger files, use interleaved
748
+ * I/O to avoid slowing the rest of the system down.
749
+ * TODO: we should return a code rather than barf, in case of file-not-found.
750
+ * TODO, does this compile on Windows?
751
+ * TODO, given that we want this to work only with small files, how about allocating
752
+ * the buffer on the stack rather than the heap?
753
+ *
754
+ * Modified 25Jul07. This now returns -1 on file-too-large; 0 for success, and a positive
755
+ * errno in case of other errors.
756
+ *
757
+ * Contributed by Kirk Haines.
758
+ */
759
+
760
+ char data[32*1024];
761
+ int r;
762
+
763
+ ensure_eventmachine("evma_send_file_data_to_connection");
764
+
765
+ int Fd = open (filename, O_RDONLY);
766
+
767
+ if (Fd < 0)
768
+ return errno;
769
+ // From here on, all early returns MUST close Fd.
770
+
771
+ struct stat st;
772
+ if (fstat (Fd, &st)) {
773
+ int e = errno;
774
+ close (Fd);
775
+ return e;
776
+ }
777
+
778
+ off_t filesize = st.st_size;
779
+ if (filesize <= 0) {
780
+ close (Fd);
781
+ return 0;
782
+ }
783
+ else if (filesize > (off_t) sizeof(data)) {
784
+ close (Fd);
785
+ return -1;
786
+ }
787
+
788
+
789
+ r = read (Fd, data, filesize);
790
+ if (r != filesize) {
791
+ int e = errno;
792
+ close (Fd);
793
+ return e;
794
+ }
795
+ evma_send_data_to_connection (binding, data, r);
796
+ close (Fd);
797
+
798
+ return 0;
799
+ }
800
+
801
+
802
+ /****************
803
+ evma_start_proxy
804
+ *****************/
805
+
806
+ extern "C" void evma_start_proxy (const unsigned long from, const unsigned long to, const unsigned long bufsize, const unsigned long length)
807
+ {
808
+ ensure_eventmachine("evma_start_proxy");
809
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (from));
810
+ if (ed)
811
+ ed->StartProxy(to, bufsize, length);
812
+ }
813
+
814
+
815
+ /***************
816
+ evma_stop_proxy
817
+ ****************/
818
+
819
+ extern "C" void evma_stop_proxy (const unsigned long from)
820
+ {
821
+ ensure_eventmachine("evma_stop_proxy");
822
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (from));
823
+ if (ed)
824
+ ed->StopProxy();
825
+ }
826
+
827
+ /******************
828
+ evma_proxied_bytes
829
+ *******************/
830
+
831
+ extern "C" unsigned long evma_proxied_bytes (const unsigned long from)
832
+ {
833
+ ensure_eventmachine("evma_proxied_bytes");
834
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (from));
835
+ if (ed)
836
+ return ed->GetProxiedBytes();
837
+ else
838
+ return 0;
839
+ }
840
+
841
+
842
+ /***************************
843
+ evma_get_last_activity_time
844
+ ****************************/
845
+
846
+ extern "C" uint64_t evma_get_last_activity_time(const unsigned long from)
847
+ {
848
+ ensure_eventmachine("evma_get_last_activity_time");
849
+ EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (from));
850
+ if (ed)
851
+ return ed->GetLastActivity();
852
+ else
853
+ return 0;
854
+ }
855
+
856
+
857
+ /***************************
858
+ evma_get_heartbeat_interval
859
+ ****************************/
860
+
861
+ extern "C" float evma_get_heartbeat_interval()
862
+ {
863
+ ensure_eventmachine("evma_get_heartbeat_interval");
864
+ return EventMachine->GetHeartbeatInterval();
865
+ }
866
+
867
+
868
+ /***************************
869
+ evma_set_heartbeat_interval
870
+ ****************************/
871
+
872
+ extern "C" int evma_set_heartbeat_interval(float interval)
873
+ {
874
+ ensure_eventmachine("evma_set_heartbeat_interval");
875
+ return EventMachine->SetHeartbeatInterval(interval);
876
+ }
877
+
878
+
879
+ /**************************
880
+ evma_get_current_loop_time
881
+ ***************************/
882
+
883
+ extern "C" uint64_t evma_get_current_loop_time()
884
+ {
885
+ ensure_eventmachine("evma_get_current_loop_time");
886
+ return EventMachine->GetCurrentLoopTime();
887
+ }