eventmachine 0.12.2 → 0.12.4
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.
- data/Rakefile +191 -0
- data/{COPYING → docs/COPYING} +0 -0
- data/docs/ChangeLog +183 -0
- data/{DEFERRABLES → docs/DEFERRABLES} +1 -1
- data/{EPOLL → docs/EPOLL} +0 -0
- data/{GNU → docs/GNU} +0 -0
- data/docs/INSTALL +15 -0
- data/{KEYBOARD → docs/KEYBOARD} +0 -0
- data/{LEGAL → docs/LEGAL} +0 -0
- data/{LIGHTWEIGHT_CONCURRENCY → docs/LIGHTWEIGHT_CONCURRENCY} +1 -1
- data/{PURE_RUBY → docs/PURE_RUBY} +1 -1
- data/{README → docs/README} +1 -1
- data/{RELEASE_NOTES → docs/RELEASE_NOTES} +1 -1
- data/{SMTP → docs/SMTP} +1 -1
- data/{SPAWNED_PROCESSES → docs/SPAWNED_PROCESSES} +1 -1
- data/{TODO → docs/TODO} +1 -1
- data/ext/binder.cpp +1 -1
- data/ext/binder.h +1 -1
- data/ext/cmain.cpp +65 -74
- data/ext/cplusplus.cpp +1 -1
- data/ext/ed.cpp +41 -25
- data/ext/ed.h +10 -3
- data/ext/em.cpp +39 -12
- data/ext/em.h +13 -1
- data/ext/emwin.cpp +1 -1
- data/ext/emwin.h +1 -1
- data/ext/epoll.cpp +1 -1
- data/ext/epoll.h +1 -1
- data/ext/eventmachine.h +1 -1
- data/ext/eventmachine_cpp.h +1 -1
- data/ext/extconf.rb +86 -139
- data/ext/fastfilereader/extconf.rb +161 -0
- data/ext/fastfilereader/mapper.cpp +202 -0
- data/ext/fastfilereader/mapper.h +59 -0
- data/ext/fastfilereader/rubymain.cpp +127 -0
- data/ext/files.cpp +1 -1
- data/ext/files.h +1 -1
- data/ext/kb.cpp +1 -1
- data/ext/page.cpp +1 -1
- data/ext/page.h +1 -1
- data/ext/pipe.cpp +14 -7
- data/ext/project.h +1 -1
- data/ext/rubymain.cpp +56 -2
- data/ext/sigs.cpp +1 -1
- data/ext/sigs.h +1 -1
- data/ext/ssl.cpp +1 -1
- data/ext/ssl.h +1 -1
- data/java/src/com/rubyeventmachine/Application.java +196 -0
- data/java/src/com/rubyeventmachine/Connection.java +74 -0
- data/java/src/com/rubyeventmachine/ConnectionFactory.java +37 -0
- data/java/src/com/rubyeventmachine/DefaultConnectionFactory.java +46 -0
- data/java/src/com/rubyeventmachine/EmReactor.java +408 -0
- data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
- data/java/src/com/rubyeventmachine/EventableChannel.java +57 -0
- data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +171 -0
- data/java/src/com/rubyeventmachine/EventableSocketChannel.java +244 -0
- data/java/src/com/rubyeventmachine/PeriodicTimer.java +38 -0
- data/java/src/com/rubyeventmachine/Timer.java +54 -0
- data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +108 -0
- data/java/src/com/rubyeventmachine/tests/ConnectTest.java +124 -0
- data/java/src/com/rubyeventmachine/tests/EMTest.java +80 -0
- data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +53 -0
- data/java/src/com/rubyeventmachine/tests/TestServers.java +74 -0
- data/java/src/com/rubyeventmachine/tests/TestTimers.java +89 -0
- data/lib/em/deferrable.rb +1 -1
- data/lib/em/eventable.rb +1 -1
- data/lib/em/future.rb +1 -1
- data/lib/em/messages.rb +1 -1
- data/lib/em/processes.rb +1 -1
- data/lib/em/spawnable.rb +1 -1
- data/lib/em/streamer.rb +1 -1
- data/lib/eventmachine.rb +138 -116
- data/lib/eventmachine_version.rb +2 -2
- data/lib/evma.rb +1 -1
- data/lib/evma/callback.rb +1 -1
- data/lib/evma/container.rb +1 -1
- data/lib/evma/factory.rb +1 -1
- data/lib/evma/protocol.rb +1 -1
- data/lib/evma/reactor.rb +1 -1
- data/lib/jeventmachine.rb +7 -2
- data/lib/pr_eventmachine.rb +2 -2
- data/lib/protocols/buftok.rb +1 -1
- data/lib/protocols/header_and_content.rb +1 -1
- data/lib/protocols/httpcli2.rb +16 -6
- data/lib/protocols/httpclient.rb +7 -1
- data/lib/protocols/line_and_text.rb +6 -2
- data/lib/protocols/linetext2.rb +12 -14
- data/lib/protocols/postgres.rb +1 -1
- data/lib/protocols/saslauth.rb +1 -1
- data/lib/protocols/smtpclient.rb +1 -1
- data/lib/protocols/smtpserver.rb +36 -23
- data/lib/protocols/stomp.rb +24 -1
- data/lib/protocols/tcptest.rb +1 -1
- data/tasks/cpp.rake +77 -0
- data/tasks/project.rake +78 -0
- data/tasks/tests.rake +192 -0
- data/tests/test_attach.rb +1 -1
- data/tests/test_basic.rb +65 -12
- data/tests/test_defer.rb +13 -29
- data/tests/test_epoll.rb +16 -21
- data/tests/test_errors.rb +1 -1
- data/tests/test_eventables.rb +4 -5
- data/tests/test_exc.rb +1 -1
- data/tests/test_futures.rb +1 -1
- data/tests/test_hc.rb +185 -236
- data/tests/test_httpclient.rb +1 -1
- data/tests/test_httpclient2.rb +28 -6
- data/tests/test_kb.rb +2 -2
- data/tests/test_ltp.rb +139 -141
- data/tests/test_ltp2.rb +1 -1
- data/tests/test_next_tick.rb +1 -1
- data/tests/test_processes.rb +1 -1
- data/tests/test_pure.rb +3 -2
- data/tests/test_running.rb +1 -1
- data/tests/test_sasl.rb +1 -1
- data/tests/test_send_file.rb +56 -51
- data/tests/test_servers.rb +26 -36
- data/tests/test_smtpclient.rb +46 -44
- data/tests/test_smtpserver.rb +1 -1
- data/tests/test_spawn.rb +1 -1
- data/tests/test_ssl_args.rb +68 -0
- data/tests/test_timers.rb +15 -9
- data/tests/test_ud.rb +1 -1
- data/tests/testem.rb +30 -4
- metadata +69 -34
data/{TODO → docs/TODO}
RENAMED
data/ext/binder.cpp
CHANGED
data/ext/binder.h
CHANGED
data/ext/cmain.cpp
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/*****************************************************************************
|
|
2
2
|
|
|
3
|
-
$Id
|
|
3
|
+
$Id$
|
|
4
4
|
|
|
5
|
-
File:
|
|
6
|
-
Date:
|
|
5
|
+
File: cmain.cpp
|
|
6
|
+
Date: 06Apr06
|
|
7
7
|
|
|
8
8
|
Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
|
|
9
9
|
Gmail: blackhedd
|
|
@@ -24,6 +24,19 @@ static EventMachine_t *EventMachine;
|
|
|
24
24
|
static int bUseEpoll = 0;
|
|
25
25
|
static int bUseKqueue = 0;
|
|
26
26
|
|
|
27
|
+
extern "C" void ensure_eventmachine (const char *caller = "unknown caller")
|
|
28
|
+
{
|
|
29
|
+
if (!EventMachine) {
|
|
30
|
+
const int err_size = 128;
|
|
31
|
+
char err_string[err_size];
|
|
32
|
+
snprintf (err_string, err_size, "eventmachine not initialized: %s", caller);
|
|
33
|
+
#ifdef BUILD_FOR_RUBY
|
|
34
|
+
rb_raise(rb_eRuntimeError, err_string);
|
|
35
|
+
#else
|
|
36
|
+
throw std::runtime_error (err_string);
|
|
37
|
+
#endif
|
|
38
|
+
}
|
|
39
|
+
}
|
|
27
40
|
|
|
28
41
|
/***********************
|
|
29
42
|
evma_initialize_library
|
|
@@ -35,7 +48,11 @@ extern "C" void evma_initialize_library (void(*cb)(const char*, int, const char*
|
|
|
35
48
|
// we're just being linked into.
|
|
36
49
|
//InstallSignalHandlers();
|
|
37
50
|
if (EventMachine)
|
|
38
|
-
|
|
51
|
+
#ifdef BUILD_FOR_RUBY
|
|
52
|
+
rb_raise(rb_eRuntimeError, "eventmachine already initialized: evma_initialize_library");
|
|
53
|
+
#else
|
|
54
|
+
throw std::runtime_error ("eventmachine already initialized: evma_initialize_library");
|
|
55
|
+
#endif
|
|
39
56
|
EventMachine = new EventMachine_t (cb);
|
|
40
57
|
if (bUseEpoll)
|
|
41
58
|
EventMachine->_UseEpoll();
|
|
@@ -50,8 +67,7 @@ evma_release_library
|
|
|
50
67
|
|
|
51
68
|
extern "C" void evma_release_library()
|
|
52
69
|
{
|
|
53
|
-
|
|
54
|
-
throw std::runtime_error ("not initialized");
|
|
70
|
+
ensure_eventmachine("evma_release_library");
|
|
55
71
|
delete EventMachine;
|
|
56
72
|
EventMachine = NULL;
|
|
57
73
|
}
|
|
@@ -63,8 +79,7 @@ evma_run_machine
|
|
|
63
79
|
|
|
64
80
|
extern "C" void evma_run_machine()
|
|
65
81
|
{
|
|
66
|
-
|
|
67
|
-
throw std::runtime_error ("not initialized");
|
|
82
|
+
ensure_eventmachine("evma_run_machine");
|
|
68
83
|
EventMachine->Run();
|
|
69
84
|
}
|
|
70
85
|
|
|
@@ -75,8 +90,7 @@ evma_install_oneshot_timer
|
|
|
75
90
|
|
|
76
91
|
extern "C" const char *evma_install_oneshot_timer (int seconds)
|
|
77
92
|
{
|
|
78
|
-
|
|
79
|
-
throw std::runtime_error ("not initialized");
|
|
93
|
+
ensure_eventmachine("evma_install_oneshot_timer");
|
|
80
94
|
return EventMachine->InstallOneshotTimer (seconds);
|
|
81
95
|
}
|
|
82
96
|
|
|
@@ -87,8 +101,7 @@ evma_connect_to_server
|
|
|
87
101
|
|
|
88
102
|
extern "C" const char *evma_connect_to_server (const char *server, int port)
|
|
89
103
|
{
|
|
90
|
-
|
|
91
|
-
throw std::runtime_error ("not initialized");
|
|
104
|
+
ensure_eventmachine("evma_connect_to_server");
|
|
92
105
|
return EventMachine->ConnectToServer (server, port);
|
|
93
106
|
}
|
|
94
107
|
|
|
@@ -98,8 +111,7 @@ evma_connect_to_unix_server
|
|
|
98
111
|
|
|
99
112
|
extern "C" const char *evma_connect_to_unix_server (const char *server)
|
|
100
113
|
{
|
|
101
|
-
|
|
102
|
-
throw std::runtime_error ("not initialized");
|
|
114
|
+
ensure_eventmachine("evma_connect_to_unix_server");
|
|
103
115
|
return EventMachine->ConnectToUnixServer (server);
|
|
104
116
|
}
|
|
105
117
|
|
|
@@ -109,8 +121,7 @@ evma_attach_fd
|
|
|
109
121
|
|
|
110
122
|
extern "C" const char *evma_attach_fd (int file_descriptor, int notify_readable, int notify_writable)
|
|
111
123
|
{
|
|
112
|
-
|
|
113
|
-
throw std::runtime_error ("not initialized");
|
|
124
|
+
ensure_eventmachine("evma_attach_fd");
|
|
114
125
|
return EventMachine->AttachFD (file_descriptor, (notify_readable ? true : false), (notify_writable ? true : false));
|
|
115
126
|
}
|
|
116
127
|
|
|
@@ -120,14 +131,16 @@ evma_detach_fd
|
|
|
120
131
|
|
|
121
132
|
extern "C" int evma_detach_fd (const char *binding)
|
|
122
133
|
{
|
|
123
|
-
|
|
124
|
-
throw std::runtime_error ("not initialized");
|
|
125
|
-
|
|
134
|
+
ensure_eventmachine("evma_dettach_fd");
|
|
126
135
|
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
|
127
136
|
if (ed)
|
|
128
137
|
return EventMachine->DetachFD (ed);
|
|
129
138
|
else
|
|
130
|
-
|
|
139
|
+
#ifdef BUILD_FOR_RUBY
|
|
140
|
+
rb_raise(rb_eRuntimeError, "invalid binding to detach");
|
|
141
|
+
#else
|
|
142
|
+
throw std::runtime_error ("invalid binding to detach");
|
|
143
|
+
#endif
|
|
131
144
|
}
|
|
132
145
|
|
|
133
146
|
/**********************
|
|
@@ -136,8 +149,7 @@ evma_create_tcp_server
|
|
|
136
149
|
|
|
137
150
|
extern "C" const char *evma_create_tcp_server (const char *address, int port)
|
|
138
151
|
{
|
|
139
|
-
|
|
140
|
-
throw std::runtime_error ("not initialized");
|
|
152
|
+
ensure_eventmachine("evma_create_tcp_server");
|
|
141
153
|
return EventMachine->CreateTcpServer (address, port);
|
|
142
154
|
}
|
|
143
155
|
|
|
@@ -147,8 +159,7 @@ evma_create_unix_domain_server
|
|
|
147
159
|
|
|
148
160
|
extern "C" const char *evma_create_unix_domain_server (const char *filename)
|
|
149
161
|
{
|
|
150
|
-
|
|
151
|
-
throw std::runtime_error ("not initialized");
|
|
162
|
+
ensure_eventmachine("evma_create_unix_domain_server");
|
|
152
163
|
return EventMachine->CreateUnixDomainServer (filename);
|
|
153
164
|
}
|
|
154
165
|
|
|
@@ -158,8 +169,7 @@ evma_open_datagram_socket
|
|
|
158
169
|
|
|
159
170
|
extern "C" const char *evma_open_datagram_socket (const char *address, int port)
|
|
160
171
|
{
|
|
161
|
-
|
|
162
|
-
throw std::runtime_error ("not initialized");
|
|
172
|
+
ensure_eventmachine("evma_open_datagram_socket");
|
|
163
173
|
return EventMachine->OpenDatagramSocket (address, port);
|
|
164
174
|
}
|
|
165
175
|
|
|
@@ -169,8 +179,7 @@ evma_open_keyboard
|
|
|
169
179
|
|
|
170
180
|
extern "C" const char *evma_open_keyboard()
|
|
171
181
|
{
|
|
172
|
-
|
|
173
|
-
throw std::runtime_error ("not initialized");
|
|
182
|
+
ensure_eventmachine("evma_open_keyboard");
|
|
174
183
|
return EventMachine->OpenKeyboard();
|
|
175
184
|
}
|
|
176
185
|
|
|
@@ -182,8 +191,7 @@ evma_send_data_to_connection
|
|
|
182
191
|
|
|
183
192
|
extern "C" int evma_send_data_to_connection (const char *binding, const char *data, int data_length)
|
|
184
193
|
{
|
|
185
|
-
|
|
186
|
-
throw std::runtime_error ("not initialized");
|
|
194
|
+
ensure_eventmachine("evma_send_data_to_connection");
|
|
187
195
|
return ConnectionDescriptor::SendDataToConnection (binding, data, data_length);
|
|
188
196
|
}
|
|
189
197
|
|
|
@@ -193,8 +201,7 @@ evma_send_datagram
|
|
|
193
201
|
|
|
194
202
|
extern "C" int evma_send_datagram (const char *binding, const char *data, int data_length, const char *address, int port)
|
|
195
203
|
{
|
|
196
|
-
|
|
197
|
-
throw std::runtime_error ("not initialized");
|
|
204
|
+
ensure_eventmachine("evma_send_datagram");
|
|
198
205
|
return DatagramDescriptor::SendDatagram (binding, data, data_length, address, port);
|
|
199
206
|
}
|
|
200
207
|
|
|
@@ -205,8 +212,7 @@ evma_close_connection
|
|
|
205
212
|
|
|
206
213
|
extern "C" void evma_close_connection (const char *binding, int after_writing)
|
|
207
214
|
{
|
|
208
|
-
|
|
209
|
-
throw std::runtime_error ("not initialized");
|
|
215
|
+
ensure_eventmachine("evma_close_connection");
|
|
210
216
|
ConnectionDescriptor::CloseConnection (binding, (after_writing ? true : false));
|
|
211
217
|
}
|
|
212
218
|
|
|
@@ -216,8 +222,7 @@ evma_report_connection_error_status
|
|
|
216
222
|
|
|
217
223
|
extern "C" int evma_report_connection_error_status (const char *binding)
|
|
218
224
|
{
|
|
219
|
-
|
|
220
|
-
throw std::runtime_error ("not initialized");
|
|
225
|
+
ensure_eventmachine("evma_report_connection_error_status");
|
|
221
226
|
return ConnectionDescriptor::ReportErrorStatus (binding);
|
|
222
227
|
}
|
|
223
228
|
|
|
@@ -227,8 +232,7 @@ evma_stop_tcp_server
|
|
|
227
232
|
|
|
228
233
|
extern "C" void evma_stop_tcp_server (const char *binding)
|
|
229
234
|
{
|
|
230
|
-
|
|
231
|
-
throw std::runtime_error ("not initialized");
|
|
235
|
+
ensure_eventmachine("evma_stop_tcp_server");
|
|
232
236
|
AcceptorDescriptor::StopAcceptor (binding);
|
|
233
237
|
}
|
|
234
238
|
|
|
@@ -239,8 +243,7 @@ evma_stop_machine
|
|
|
239
243
|
|
|
240
244
|
extern "C" void evma_stop_machine()
|
|
241
245
|
{
|
|
242
|
-
|
|
243
|
-
throw std::runtime_error ("not initialized");
|
|
246
|
+
ensure_eventmachine("evma_stop_machine");
|
|
244
247
|
EventMachine->ScheduleHalt();
|
|
245
248
|
}
|
|
246
249
|
|
|
@@ -251,8 +254,7 @@ evma_start_tls
|
|
|
251
254
|
|
|
252
255
|
extern "C" void evma_start_tls (const char *binding)
|
|
253
256
|
{
|
|
254
|
-
|
|
255
|
-
throw std::runtime_error ("not initialized");
|
|
257
|
+
ensure_eventmachine("evma_start_tls");
|
|
256
258
|
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
|
257
259
|
if (ed)
|
|
258
260
|
ed->StartTls();
|
|
@@ -264,8 +266,7 @@ evma_set_tls_parms
|
|
|
264
266
|
|
|
265
267
|
extern "C" void evma_set_tls_parms (const char *binding, const char *privatekey_filename, const char *certchain_filename)
|
|
266
268
|
{
|
|
267
|
-
|
|
268
|
-
throw std::runtime_error ("not initialized");
|
|
269
|
+
ensure_eventmachine("evma_set_tls_parms");
|
|
269
270
|
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
|
270
271
|
if (ed)
|
|
271
272
|
ed->SetTlsParms (privatekey_filename, certchain_filename);
|
|
@@ -278,8 +279,7 @@ evma_get_peername
|
|
|
278
279
|
|
|
279
280
|
extern "C" int evma_get_peername (const char *binding, struct sockaddr *sa)
|
|
280
281
|
{
|
|
281
|
-
|
|
282
|
-
throw std::runtime_error ("not initialized");
|
|
282
|
+
ensure_eventmachine("evma_get_peername");
|
|
283
283
|
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
|
284
284
|
if (ed) {
|
|
285
285
|
return ed->GetPeername (sa) ? 1 : 0;
|
|
@@ -294,8 +294,7 @@ evma_get_sockname
|
|
|
294
294
|
|
|
295
295
|
extern "C" int evma_get_sockname (const char *binding, struct sockaddr *sa)
|
|
296
296
|
{
|
|
297
|
-
|
|
298
|
-
throw std::runtime_error ("not initialized");
|
|
297
|
+
ensure_eventmachine("evma_get_sockname");
|
|
299
298
|
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
|
300
299
|
if (ed) {
|
|
301
300
|
return ed->GetSockname (sa) ? 1 : 0;
|
|
@@ -310,8 +309,7 @@ evma_get_subprocess_pid
|
|
|
310
309
|
|
|
311
310
|
extern "C" int evma_get_subprocess_pid (const char *binding, pid_t *pid)
|
|
312
311
|
{
|
|
313
|
-
|
|
314
|
-
throw std::runtime_error ("not initialized");
|
|
312
|
+
ensure_eventmachine("evma_get_subprocess_pid");
|
|
315
313
|
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
|
316
314
|
if (ed) {
|
|
317
315
|
return ed->GetSubprocessPid (pid) ? 1 : 0;
|
|
@@ -326,8 +324,7 @@ evma_get_subprocess_status
|
|
|
326
324
|
|
|
327
325
|
extern "C" int evma_get_subprocess_status (const char *binding, int *status)
|
|
328
326
|
{
|
|
329
|
-
|
|
330
|
-
throw std::runtime_error ("not initialized");
|
|
327
|
+
ensure_eventmachine("evma_get_subprocess_status");
|
|
331
328
|
if (status) {
|
|
332
329
|
*status = EventMachine->SubprocessExitStatus;
|
|
333
330
|
return 1;
|
|
@@ -343,8 +340,7 @@ evma_signal_loopbreak
|
|
|
343
340
|
|
|
344
341
|
extern "C" void evma_signal_loopbreak()
|
|
345
342
|
{
|
|
346
|
-
|
|
347
|
-
throw std::runtime_error ("not initialized");
|
|
343
|
+
ensure_eventmachine("evma_signal_loopbreak");
|
|
348
344
|
EventMachine->SignalLoopBreaker();
|
|
349
345
|
}
|
|
350
346
|
|
|
@@ -356,8 +352,7 @@ evma__write_file
|
|
|
356
352
|
|
|
357
353
|
extern "C" const char *evma__write_file (const char *filename)
|
|
358
354
|
{
|
|
359
|
-
|
|
360
|
-
throw std::runtime_error ("not initialized");
|
|
355
|
+
ensure_eventmachine("evma__write_file");
|
|
361
356
|
return EventMachine->_OpenFileForWriting (filename);
|
|
362
357
|
}
|
|
363
358
|
|
|
@@ -368,8 +363,7 @@ evma_get_comm_inactivity_timeout
|
|
|
368
363
|
|
|
369
364
|
extern "C" int evma_get_comm_inactivity_timeout (const char *binding, int *value)
|
|
370
365
|
{
|
|
371
|
-
|
|
372
|
-
throw std::runtime_error ("not initialized");
|
|
366
|
+
ensure_eventmachine("evma_get_comm_inactivity_timeout");
|
|
373
367
|
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
|
374
368
|
if (ed) {
|
|
375
369
|
return ed->GetCommInactivityTimeout (value);
|
|
@@ -384,8 +378,7 @@ evma_set_comm_inactivity_timeout
|
|
|
384
378
|
|
|
385
379
|
extern "C" int evma_set_comm_inactivity_timeout (const char *binding, int *value)
|
|
386
380
|
{
|
|
387
|
-
|
|
388
|
-
throw std::runtime_error ("not initialized");
|
|
381
|
+
ensure_eventmachine("evma_set_comm_inactivity_timeout");
|
|
389
382
|
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
|
390
383
|
if (ed) {
|
|
391
384
|
return ed->SetCommInactivityTimeout (value);
|
|
@@ -401,8 +394,7 @@ evma_set_timer_quantum
|
|
|
401
394
|
|
|
402
395
|
extern "C" void evma_set_timer_quantum (int interval)
|
|
403
396
|
{
|
|
404
|
-
|
|
405
|
-
throw std::runtime_error ("not initialized");
|
|
397
|
+
ensure_eventmachine("evma_set_timer_quantum");
|
|
406
398
|
EventMachine->SetTimerQuantum (interval);
|
|
407
399
|
}
|
|
408
400
|
|
|
@@ -413,8 +405,13 @@ evma_set_max_timer_count
|
|
|
413
405
|
extern "C" void evma_set_max_timer_count (int ct)
|
|
414
406
|
{
|
|
415
407
|
// This may only be called if the reactor is not running.
|
|
408
|
+
|
|
416
409
|
if (EventMachine)
|
|
417
|
-
|
|
410
|
+
#ifdef BUILD_FOR_RUBY
|
|
411
|
+
rb_raise(rb_eRuntimeError, "eventmachine already initialized: evma_set_max_timer_count");
|
|
412
|
+
#else
|
|
413
|
+
throw std::runtime_error ("eventmachine already initialized: evma_set_max_timer_count");
|
|
414
|
+
#endif
|
|
418
415
|
EventMachine_t::SetMaxTimerCount (ct);
|
|
419
416
|
}
|
|
420
417
|
|
|
@@ -424,8 +421,8 @@ evma_setuid_string
|
|
|
424
421
|
|
|
425
422
|
extern "C" void evma_setuid_string (const char *username)
|
|
426
423
|
{
|
|
427
|
-
|
|
428
|
-
|
|
424
|
+
// We do NOT need to be running an EM instance because this method is static.
|
|
425
|
+
EventMachine_t::SetuidString (username);
|
|
429
426
|
}
|
|
430
427
|
|
|
431
428
|
|
|
@@ -435,8 +432,7 @@ evma_popen
|
|
|
435
432
|
|
|
436
433
|
extern "C" const char *evma_popen (char * const*cmd_strings)
|
|
437
434
|
{
|
|
438
|
-
|
|
439
|
-
throw std::runtime_error ("not initialized");
|
|
435
|
+
ensure_eventmachine("evma_popen");
|
|
440
436
|
return EventMachine->Socketpair (cmd_strings);
|
|
441
437
|
}
|
|
442
438
|
|
|
@@ -447,8 +443,7 @@ evma_get_outbound_data_size
|
|
|
447
443
|
|
|
448
444
|
extern "C" int evma_get_outbound_data_size (const char *binding)
|
|
449
445
|
{
|
|
450
|
-
|
|
451
|
-
throw std::runtime_error ("not initialized");
|
|
446
|
+
ensure_eventmachine("evma_get_outbound_data_size");
|
|
452
447
|
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
|
453
448
|
return ed ? ed->GetOutboundDataSize() : 0;
|
|
454
449
|
}
|
|
@@ -509,8 +504,7 @@ extern "C" int evma_send_file_data_to_connection (const char *binding, const cha
|
|
|
509
504
|
char data[32*1024];
|
|
510
505
|
int r;
|
|
511
506
|
|
|
512
|
-
|
|
513
|
-
throw std::runtime_error("not initialized");
|
|
507
|
+
ensure_eventmachine("evma_send_file_data_to_connection");
|
|
514
508
|
|
|
515
509
|
int Fd = open (filename, O_RDONLY);
|
|
516
510
|
|
|
@@ -548,6 +542,3 @@ extern "C" int evma_send_file_data_to_connection (const char *binding, const cha
|
|
|
548
542
|
return 0;
|
|
549
543
|
}
|
|
550
544
|
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
data/ext/cplusplus.cpp
CHANGED
data/ext/ed.cpp
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*****************************************************************************
|
|
2
2
|
|
|
3
|
-
$Id
|
|
3
|
+
$Id$
|
|
4
4
|
|
|
5
5
|
File: ed.cpp
|
|
6
6
|
Date: 06Apr06
|
|
@@ -189,9 +189,7 @@ ConnectionDescriptor::ConnectionDescriptor (int sd, EventMachine_t *em):
|
|
|
189
189
|
#ifdef HAVE_EPOLL
|
|
190
190
|
EpollEvent.events = EPOLLOUT;
|
|
191
191
|
#endif
|
|
192
|
-
|
|
193
|
-
MyEventMachine->ArmKqueueWriter (this);
|
|
194
|
-
#endif
|
|
192
|
+
// 22Jan09: Moved ArmKqueueWriter into SetConnectPending() to fix assertion failure in _WriteOutboundData()
|
|
195
193
|
}
|
|
196
194
|
|
|
197
195
|
|
|
@@ -263,6 +261,17 @@ int ConnectionDescriptor::ReportErrorStatus (const char *binding)
|
|
|
263
261
|
return -1;
|
|
264
262
|
}
|
|
265
263
|
|
|
264
|
+
/***************************************
|
|
265
|
+
ConnectionDescriptor::SetConnectPending
|
|
266
|
+
****************************************/
|
|
267
|
+
|
|
268
|
+
void ConnectionDescriptor::SetConnectPending(bool f)
|
|
269
|
+
{
|
|
270
|
+
bConnectPending = f;
|
|
271
|
+
#ifdef HAVE_KQUEUE
|
|
272
|
+
MyEventMachine->ArmKqueueWriter (this);
|
|
273
|
+
#endif
|
|
274
|
+
}
|
|
266
275
|
|
|
267
276
|
|
|
268
277
|
/**************************************
|
|
@@ -624,29 +633,36 @@ void ConnectionDescriptor::_WriteOutboundData()
|
|
|
624
633
|
assert (GetSocket() != INVALID_SOCKET);
|
|
625
634
|
int bytes_written = send (GetSocket(), output_buffer, nbytes, 0);
|
|
626
635
|
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
if (!buffer)
|
|
633
|
-
throw std::runtime_error ("bad alloc throwing back data");
|
|
634
|
-
memcpy (buffer, output_buffer + bytes_written, len);
|
|
635
|
-
buffer [len] = 0;
|
|
636
|
-
OutboundPages.push_front (OutboundPage (buffer, len));
|
|
637
|
-
}
|
|
636
|
+
bool err = false;
|
|
637
|
+
if (bytes_written < 0) {
|
|
638
|
+
err = true;
|
|
639
|
+
bytes_written = 0;
|
|
640
|
+
}
|
|
638
641
|
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
642
|
+
assert (bytes_written >= 0);
|
|
643
|
+
OutboundDataSize -= bytes_written;
|
|
644
|
+
if ((size_t)bytes_written < nbytes) {
|
|
645
|
+
int len = nbytes - bytes_written;
|
|
646
|
+
char *buffer = (char*) malloc (len + 1);
|
|
647
|
+
if (!buffer)
|
|
648
|
+
throw std::runtime_error ("bad alloc throwing back data");
|
|
649
|
+
memcpy (buffer, output_buffer + bytes_written, len);
|
|
650
|
+
buffer [len] = 0;
|
|
651
|
+
OutboundPages.push_front (OutboundPage (buffer, len));
|
|
648
652
|
}
|
|
649
|
-
|
|
653
|
+
|
|
654
|
+
#ifdef HAVE_EPOLL
|
|
655
|
+
EpollEvent.events = (EPOLLIN | (SelectForWrite() ? EPOLLOUT : 0));
|
|
656
|
+
assert (MyEventMachine);
|
|
657
|
+
MyEventMachine->Modify (this);
|
|
658
|
+
#endif
|
|
659
|
+
#ifdef HAVE_KQUEUE
|
|
660
|
+
if (SelectForWrite())
|
|
661
|
+
MyEventMachine->ArmKqueueWriter (this);
|
|
662
|
+
#endif
|
|
663
|
+
|
|
664
|
+
|
|
665
|
+
if (err) {
|
|
650
666
|
#ifdef OS_UNIX
|
|
651
667
|
if ((errno != EINPROGRESS) && (errno != EWOULDBLOCK) && (errno != EINTR))
|
|
652
668
|
#endif
|