libc-eventmachine 0.12.5.42
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +195 -0
- data/docs/COPYING +60 -0
- data/docs/ChangeLog +211 -0
- data/docs/DEFERRABLES +138 -0
- data/docs/EPOLL +141 -0
- data/docs/GNU +281 -0
- data/docs/INSTALL +15 -0
- data/docs/KEYBOARD +38 -0
- data/docs/LEGAL +25 -0
- data/docs/LIGHTWEIGHT_CONCURRENCY +72 -0
- data/docs/PURE_RUBY +77 -0
- data/docs/README +74 -0
- data/docs/RELEASE_NOTES +96 -0
- data/docs/SMTP +9 -0
- data/docs/SPAWNED_PROCESSES +93 -0
- data/docs/TODO +10 -0
- data/ext/binder.cpp +126 -0
- data/ext/binder.h +48 -0
- data/ext/cmain.cpp +582 -0
- data/ext/cplusplus.cpp +177 -0
- data/ext/ed.cpp +1522 -0
- data/ext/ed.h +380 -0
- data/ext/em.cpp +1947 -0
- data/ext/em.h +186 -0
- data/ext/emwin.cpp +300 -0
- data/ext/emwin.h +94 -0
- data/ext/epoll.cpp +26 -0
- data/ext/epoll.h +25 -0
- data/ext/eventmachine.h +98 -0
- data/ext/eventmachine_cpp.h +96 -0
- data/ext/extconf.rb +129 -0
- data/ext/fastfilereader/extconf.rb +77 -0
- data/ext/fastfilereader/mapper.cpp +214 -0
- data/ext/fastfilereader/mapper.h +59 -0
- data/ext/fastfilereader/rubymain.cpp +127 -0
- data/ext/files.cpp +94 -0
- data/ext/files.h +65 -0
- data/ext/kb.cpp +82 -0
- data/ext/page.cpp +107 -0
- data/ext/page.h +51 -0
- data/ext/pipe.cpp +351 -0
- data/ext/project.h +119 -0
- data/ext/rubymain.cpp +858 -0
- data/ext/sigs.cpp +89 -0
- data/ext/sigs.h +32 -0
- data/ext/ssl.cpp +423 -0
- data/ext/ssl.h +90 -0
- 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 +208 -0
- data/lib/em/eventable.rb +39 -0
- data/lib/em/future.rb +62 -0
- data/lib/em/messages.rb +66 -0
- data/lib/em/processes.rb +68 -0
- data/lib/em/spawnable.rb +88 -0
- data/lib/em/streamer.rb +112 -0
- data/lib/eventmachine.rb +1920 -0
- data/lib/eventmachine_version.rb +31 -0
- data/lib/evma/callback.rb +32 -0
- data/lib/evma/container.rb +75 -0
- data/lib/evma/factory.rb +77 -0
- data/lib/evma/protocol.rb +87 -0
- data/lib/evma/reactor.rb +48 -0
- data/lib/evma.rb +32 -0
- data/lib/jeventmachine.rb +140 -0
- data/lib/pr_eventmachine.rb +1017 -0
- data/lib/protocols/buftok.rb +127 -0
- data/lib/protocols/header_and_content.rb +129 -0
- data/lib/protocols/httpcli2.rb +803 -0
- data/lib/protocols/httpclient.rb +270 -0
- data/lib/protocols/line_and_text.rb +126 -0
- data/lib/protocols/linetext2.rb +161 -0
- data/lib/protocols/memcache.rb +293 -0
- data/lib/protocols/postgres.rb +261 -0
- data/lib/protocols/saslauth.rb +179 -0
- data/lib/protocols/smtpclient.rb +308 -0
- data/lib/protocols/smtpserver.rb +556 -0
- data/lib/protocols/stomp.rb +153 -0
- data/lib/protocols/tcptest.rb +57 -0
- data/tasks/cpp.rake +77 -0
- data/tasks/project.rake +78 -0
- data/tasks/tests.rake +193 -0
- data/tests/test_attach.rb +83 -0
- data/tests/test_basic.rb +231 -0
- data/tests/test_bind.rb +73 -0
- data/tests/test_connection_count.rb +35 -0
- data/tests/test_defer.rb +47 -0
- data/tests/test_epoll.rb +163 -0
- data/tests/test_error_handler.rb +32 -0
- data/tests/test_errors.rb +82 -0
- data/tests/test_eventables.rb +77 -0
- data/tests/test_exc.rb +58 -0
- data/tests/test_futures.rb +214 -0
- data/tests/test_handler_check.rb +37 -0
- data/tests/test_hc.rb +218 -0
- data/tests/test_httpclient.rb +215 -0
- data/tests/test_httpclient2.rb +155 -0
- data/tests/test_kb.rb +61 -0
- data/tests/test_ltp.rb +188 -0
- data/tests/test_ltp2.rb +320 -0
- data/tests/test_next_tick.rb +109 -0
- data/tests/test_processes.rb +56 -0
- data/tests/test_pure.rb +129 -0
- data/tests/test_running.rb +47 -0
- data/tests/test_sasl.rb +74 -0
- data/tests/test_send_file.rb +243 -0
- data/tests/test_servers.rb +80 -0
- data/tests/test_smtpclient.rb +83 -0
- data/tests/test_smtpserver.rb +93 -0
- data/tests/test_spawn.rb +329 -0
- data/tests/test_ssl_args.rb +68 -0
- data/tests/test_ssl_methods.rb +50 -0
- data/tests/test_timers.rb +148 -0
- data/tests/test_ud.rb +43 -0
- data/tests/testem.rb +31 -0
- metadata +230 -0
data/ext/cmain.cpp
ADDED
@@ -0,0 +1,582 @@
|
|
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
|
+
|
23
|
+
static EventMachine_t *EventMachine;
|
24
|
+
static int bUseEpoll = 0;
|
25
|
+
static int bUseKqueue = 0;
|
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
|
+
}
|
40
|
+
|
41
|
+
/***********************
|
42
|
+
evma_initialize_library
|
43
|
+
***********************/
|
44
|
+
|
45
|
+
extern "C" void evma_initialize_library (void(*cb)(const char*, int, const char*, int))
|
46
|
+
{
|
47
|
+
// Probably a bad idea to mess with the signal mask of a process
|
48
|
+
// we're just being linked into.
|
49
|
+
//InstallSignalHandlers();
|
50
|
+
if (EventMachine)
|
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
|
56
|
+
EventMachine = new EventMachine_t (cb);
|
57
|
+
if (bUseEpoll)
|
58
|
+
EventMachine->_UseEpoll();
|
59
|
+
if (bUseKqueue)
|
60
|
+
EventMachine->_UseKqueue();
|
61
|
+
}
|
62
|
+
|
63
|
+
|
64
|
+
/********************
|
65
|
+
evma_release_library
|
66
|
+
********************/
|
67
|
+
|
68
|
+
extern "C" void evma_release_library()
|
69
|
+
{
|
70
|
+
ensure_eventmachine("evma_release_library");
|
71
|
+
delete EventMachine;
|
72
|
+
EventMachine = NULL;
|
73
|
+
}
|
74
|
+
|
75
|
+
|
76
|
+
/****************
|
77
|
+
evma_run_machine
|
78
|
+
****************/
|
79
|
+
|
80
|
+
extern "C" void evma_run_machine()
|
81
|
+
{
|
82
|
+
ensure_eventmachine("evma_run_machine");
|
83
|
+
EventMachine->Run();
|
84
|
+
}
|
85
|
+
|
86
|
+
|
87
|
+
/**************************
|
88
|
+
evma_install_oneshot_timer
|
89
|
+
**************************/
|
90
|
+
|
91
|
+
extern "C" const char *evma_install_oneshot_timer (int seconds)
|
92
|
+
{
|
93
|
+
ensure_eventmachine("evma_install_oneshot_timer");
|
94
|
+
return EventMachine->InstallOneshotTimer (seconds);
|
95
|
+
}
|
96
|
+
|
97
|
+
|
98
|
+
/**********************
|
99
|
+
evma_connect_to_server
|
100
|
+
**********************/
|
101
|
+
|
102
|
+
extern "C" const char *evma_connect_to_server (const char *server, int port, const char * bind_host)
|
103
|
+
{
|
104
|
+
ensure_eventmachine("evma_connect_to_server");
|
105
|
+
return EventMachine->ConnectToServer (server, port, bind_host);
|
106
|
+
}
|
107
|
+
|
108
|
+
/***************************
|
109
|
+
evma_connect_to_unix_server
|
110
|
+
***************************/
|
111
|
+
|
112
|
+
extern "C" const char *evma_connect_to_unix_server (const char *server)
|
113
|
+
{
|
114
|
+
ensure_eventmachine("evma_connect_to_unix_server");
|
115
|
+
return EventMachine->ConnectToUnixServer (server);
|
116
|
+
}
|
117
|
+
|
118
|
+
/**************
|
119
|
+
evma_attach_fd
|
120
|
+
**************/
|
121
|
+
|
122
|
+
extern "C" const char *evma_attach_fd (int file_descriptor, int notify_readable, int notify_writable)
|
123
|
+
{
|
124
|
+
ensure_eventmachine("evma_attach_fd");
|
125
|
+
return EventMachine->AttachFD (file_descriptor, (notify_readable ? true : false), (notify_writable ? true : false));
|
126
|
+
}
|
127
|
+
|
128
|
+
/**************
|
129
|
+
evma_detach_fd
|
130
|
+
**************/
|
131
|
+
|
132
|
+
extern "C" int evma_detach_fd (const char *binding)
|
133
|
+
{
|
134
|
+
ensure_eventmachine("evma_dettach_fd");
|
135
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
136
|
+
if (ed)
|
137
|
+
return EventMachine->DetachFD (ed);
|
138
|
+
else
|
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
|
144
|
+
}
|
145
|
+
|
146
|
+
/**********************
|
147
|
+
evma_create_tcp_server
|
148
|
+
**********************/
|
149
|
+
|
150
|
+
extern "C" const char *evma_create_tcp_server (const char *address, int port)
|
151
|
+
{
|
152
|
+
ensure_eventmachine("evma_create_tcp_server");
|
153
|
+
return EventMachine->CreateTcpServer (address, port);
|
154
|
+
}
|
155
|
+
|
156
|
+
/******************************
|
157
|
+
evma_create_unix_domain_server
|
158
|
+
******************************/
|
159
|
+
|
160
|
+
extern "C" const char *evma_create_unix_domain_server (const char *filename)
|
161
|
+
{
|
162
|
+
ensure_eventmachine("evma_create_unix_domain_server");
|
163
|
+
return EventMachine->CreateUnixDomainServer (filename);
|
164
|
+
}
|
165
|
+
|
166
|
+
/*************************
|
167
|
+
evma_open_datagram_socket
|
168
|
+
*************************/
|
169
|
+
|
170
|
+
extern "C" const char *evma_open_datagram_socket (const char *address, int port)
|
171
|
+
{
|
172
|
+
ensure_eventmachine("evma_open_datagram_socket");
|
173
|
+
return EventMachine->OpenDatagramSocket (address, port);
|
174
|
+
}
|
175
|
+
|
176
|
+
/******************
|
177
|
+
evma_open_keyboard
|
178
|
+
******************/
|
179
|
+
|
180
|
+
extern "C" const char *evma_open_keyboard()
|
181
|
+
{
|
182
|
+
ensure_eventmachine("evma_open_keyboard");
|
183
|
+
return EventMachine->OpenKeyboard();
|
184
|
+
}
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
/****************************
|
189
|
+
evma_send_data_to_connection
|
190
|
+
****************************/
|
191
|
+
|
192
|
+
extern "C" int evma_send_data_to_connection (const char *binding, const char *data, int data_length)
|
193
|
+
{
|
194
|
+
ensure_eventmachine("evma_send_data_to_connection");
|
195
|
+
return ConnectionDescriptor::SendDataToConnection (binding, data, data_length);
|
196
|
+
}
|
197
|
+
|
198
|
+
/******************
|
199
|
+
evma_send_datagram
|
200
|
+
******************/
|
201
|
+
|
202
|
+
extern "C" int evma_send_datagram (const char *binding, const char *data, int data_length, const char *address, int port)
|
203
|
+
{
|
204
|
+
ensure_eventmachine("evma_send_datagram");
|
205
|
+
return DatagramDescriptor::SendDatagram (binding, data, data_length, address, port);
|
206
|
+
}
|
207
|
+
|
208
|
+
|
209
|
+
/*********************
|
210
|
+
evma_close_connection
|
211
|
+
*********************/
|
212
|
+
|
213
|
+
extern "C" void evma_close_connection (const char *binding, int after_writing)
|
214
|
+
{
|
215
|
+
ensure_eventmachine("evma_close_connection");
|
216
|
+
ConnectionDescriptor::CloseConnection (binding, (after_writing ? true : false));
|
217
|
+
}
|
218
|
+
|
219
|
+
/***********************************
|
220
|
+
evma_report_connection_error_status
|
221
|
+
***********************************/
|
222
|
+
|
223
|
+
extern "C" int evma_report_connection_error_status (const char *binding)
|
224
|
+
{
|
225
|
+
ensure_eventmachine("evma_report_connection_error_status");
|
226
|
+
return ConnectionDescriptor::ReportErrorStatus (binding);
|
227
|
+
}
|
228
|
+
|
229
|
+
/********************
|
230
|
+
evma_stop_tcp_server
|
231
|
+
********************/
|
232
|
+
|
233
|
+
extern "C" void evma_stop_tcp_server (const char *binding)
|
234
|
+
{
|
235
|
+
ensure_eventmachine("evma_stop_tcp_server");
|
236
|
+
AcceptorDescriptor::StopAcceptor (binding);
|
237
|
+
}
|
238
|
+
|
239
|
+
|
240
|
+
/*****************
|
241
|
+
evma_stop_machine
|
242
|
+
*****************/
|
243
|
+
|
244
|
+
extern "C" void evma_stop_machine()
|
245
|
+
{
|
246
|
+
ensure_eventmachine("evma_stop_machine");
|
247
|
+
EventMachine->ScheduleHalt();
|
248
|
+
}
|
249
|
+
|
250
|
+
|
251
|
+
/**************
|
252
|
+
evma_start_tls
|
253
|
+
**************/
|
254
|
+
|
255
|
+
extern "C" void evma_start_tls (const char *binding)
|
256
|
+
{
|
257
|
+
ensure_eventmachine("evma_start_tls");
|
258
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
259
|
+
if (ed)
|
260
|
+
ed->StartTls();
|
261
|
+
}
|
262
|
+
|
263
|
+
/******************
|
264
|
+
evma_set_tls_parms
|
265
|
+
******************/
|
266
|
+
|
267
|
+
extern "C" void evma_set_tls_parms (const char *binding, const char *privatekey_filename, const char *certchain_filename)
|
268
|
+
{
|
269
|
+
ensure_eventmachine("evma_set_tls_parms");
|
270
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
271
|
+
if (ed)
|
272
|
+
ed->SetTlsParms (privatekey_filename, certchain_filename);
|
273
|
+
}
|
274
|
+
|
275
|
+
/**************
|
276
|
+
evma_get_peer_cert
|
277
|
+
**************/
|
278
|
+
|
279
|
+
#ifdef WITH_SSL
|
280
|
+
extern "C" X509 *evma_get_peer_cert (const char *binding)
|
281
|
+
{
|
282
|
+
ensure_eventmachine("evma_get_peer_cert");
|
283
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
284
|
+
if (ed)
|
285
|
+
return ed->GetPeerCert();
|
286
|
+
return NULL;
|
287
|
+
}
|
288
|
+
#endif
|
289
|
+
|
290
|
+
/*****************
|
291
|
+
evma_get_peername
|
292
|
+
*****************/
|
293
|
+
|
294
|
+
extern "C" int evma_get_peername (const char *binding, struct sockaddr *sa)
|
295
|
+
{
|
296
|
+
ensure_eventmachine("evma_get_peername");
|
297
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
298
|
+
if (ed) {
|
299
|
+
return ed->GetPeername (sa) ? 1 : 0;
|
300
|
+
}
|
301
|
+
else
|
302
|
+
return 0;
|
303
|
+
}
|
304
|
+
|
305
|
+
/*****************
|
306
|
+
evma_get_sockname
|
307
|
+
*****************/
|
308
|
+
|
309
|
+
extern "C" int evma_get_sockname (const char *binding, struct sockaddr *sa)
|
310
|
+
{
|
311
|
+
ensure_eventmachine("evma_get_sockname");
|
312
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
313
|
+
if (ed) {
|
314
|
+
return ed->GetSockname (sa) ? 1 : 0;
|
315
|
+
}
|
316
|
+
else
|
317
|
+
return 0;
|
318
|
+
}
|
319
|
+
|
320
|
+
/***********************
|
321
|
+
evma_get_subprocess_pid
|
322
|
+
***********************/
|
323
|
+
|
324
|
+
extern "C" int evma_get_subprocess_pid (const char *binding, pid_t *pid)
|
325
|
+
{
|
326
|
+
ensure_eventmachine("evma_get_subprocess_pid");
|
327
|
+
PipeDescriptor *pd = dynamic_cast <PipeDescriptor*> (Bindable_t::GetObject (binding));
|
328
|
+
if (pd) {
|
329
|
+
return pd->GetSubprocessPid (pid) ? 1 : 0;
|
330
|
+
}
|
331
|
+
else if (pid && EventMachine->SubprocessPid) {
|
332
|
+
*pid = EventMachine->SubprocessPid;
|
333
|
+
return 1;
|
334
|
+
}
|
335
|
+
else
|
336
|
+
return 0;
|
337
|
+
}
|
338
|
+
|
339
|
+
/**************************
|
340
|
+
evma_get_subprocess_status
|
341
|
+
**************************/
|
342
|
+
|
343
|
+
extern "C" int evma_get_subprocess_status (const char *binding, int *status)
|
344
|
+
{
|
345
|
+
ensure_eventmachine("evma_get_subprocess_status");
|
346
|
+
if (status) {
|
347
|
+
*status = EventMachine->SubprocessExitStatus;
|
348
|
+
return 1;
|
349
|
+
}
|
350
|
+
else
|
351
|
+
return 0;
|
352
|
+
}
|
353
|
+
|
354
|
+
/*************************
|
355
|
+
evma_get_connection_count
|
356
|
+
*************************/
|
357
|
+
|
358
|
+
extern "C" int evma_get_connection_count()
|
359
|
+
{
|
360
|
+
ensure_eventmachine("evma_get_connection_count");
|
361
|
+
return EventMachine->GetConnectionCount();
|
362
|
+
}
|
363
|
+
|
364
|
+
/*********************
|
365
|
+
evma_signal_loopbreak
|
366
|
+
*********************/
|
367
|
+
|
368
|
+
extern "C" void evma_signal_loopbreak()
|
369
|
+
{
|
370
|
+
ensure_eventmachine("evma_signal_loopbreak");
|
371
|
+
EventMachine->SignalLoopBreaker();
|
372
|
+
}
|
373
|
+
|
374
|
+
|
375
|
+
|
376
|
+
/****************
|
377
|
+
evma__write_file
|
378
|
+
****************/
|
379
|
+
|
380
|
+
extern "C" const char *evma__write_file (const char *filename)
|
381
|
+
{
|
382
|
+
ensure_eventmachine("evma__write_file");
|
383
|
+
return EventMachine->_OpenFileForWriting (filename);
|
384
|
+
}
|
385
|
+
|
386
|
+
|
387
|
+
/********************************
|
388
|
+
evma_get_comm_inactivity_timeout
|
389
|
+
********************************/
|
390
|
+
|
391
|
+
extern "C" int evma_get_comm_inactivity_timeout (const char *binding, int *value)
|
392
|
+
{
|
393
|
+
ensure_eventmachine("evma_get_comm_inactivity_timeout");
|
394
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
395
|
+
if (ed) {
|
396
|
+
return ed->GetCommInactivityTimeout (value);
|
397
|
+
}
|
398
|
+
else
|
399
|
+
return 0; //Perhaps this should be an exception. Access to an unknown binding.
|
400
|
+
}
|
401
|
+
|
402
|
+
/********************************
|
403
|
+
evma_set_comm_inactivity_timeout
|
404
|
+
********************************/
|
405
|
+
|
406
|
+
extern "C" int evma_set_comm_inactivity_timeout (const char *binding, int *value)
|
407
|
+
{
|
408
|
+
ensure_eventmachine("evma_set_comm_inactivity_timeout");
|
409
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
410
|
+
if (ed) {
|
411
|
+
return ed->SetCommInactivityTimeout (value);
|
412
|
+
}
|
413
|
+
else
|
414
|
+
return 0; //Perhaps this should be an exception. Access to an unknown binding.
|
415
|
+
}
|
416
|
+
|
417
|
+
|
418
|
+
/**********************
|
419
|
+
evma_set_timer_quantum
|
420
|
+
**********************/
|
421
|
+
|
422
|
+
extern "C" void evma_set_timer_quantum (int interval)
|
423
|
+
{
|
424
|
+
ensure_eventmachine("evma_set_timer_quantum");
|
425
|
+
EventMachine->SetTimerQuantum (interval);
|
426
|
+
}
|
427
|
+
|
428
|
+
|
429
|
+
/************************
|
430
|
+
evma_get_max_timer_count
|
431
|
+
************************/
|
432
|
+
|
433
|
+
extern "C" int evma_get_max_timer_count()
|
434
|
+
{
|
435
|
+
return EventMachine_t::GetMaxTimerCount();
|
436
|
+
}
|
437
|
+
|
438
|
+
|
439
|
+
/************************
|
440
|
+
evma_set_max_timer_count
|
441
|
+
************************/
|
442
|
+
|
443
|
+
extern "C" void evma_set_max_timer_count (int ct)
|
444
|
+
{
|
445
|
+
// This may only be called if the reactor is not running.
|
446
|
+
|
447
|
+
if (EventMachine)
|
448
|
+
#ifdef BUILD_FOR_RUBY
|
449
|
+
rb_raise(rb_eRuntimeError, "eventmachine already initialized: evma_set_max_timer_count");
|
450
|
+
#else
|
451
|
+
throw std::runtime_error ("eventmachine already initialized: evma_set_max_timer_count");
|
452
|
+
#endif
|
453
|
+
EventMachine_t::SetMaxTimerCount (ct);
|
454
|
+
}
|
455
|
+
|
456
|
+
/******************
|
457
|
+
evma_setuid_string
|
458
|
+
******************/
|
459
|
+
|
460
|
+
extern "C" void evma_setuid_string (const char *username)
|
461
|
+
{
|
462
|
+
// We do NOT need to be running an EM instance because this method is static.
|
463
|
+
EventMachine_t::SetuidString (username);
|
464
|
+
}
|
465
|
+
|
466
|
+
|
467
|
+
/**********
|
468
|
+
evma_popen
|
469
|
+
**********/
|
470
|
+
|
471
|
+
extern "C" const char *evma_popen (char * const*cmd_strings)
|
472
|
+
{
|
473
|
+
ensure_eventmachine("evma_popen");
|
474
|
+
return EventMachine->Socketpair (cmd_strings);
|
475
|
+
}
|
476
|
+
|
477
|
+
|
478
|
+
/***************************
|
479
|
+
evma_get_outbound_data_size
|
480
|
+
***************************/
|
481
|
+
|
482
|
+
extern "C" int evma_get_outbound_data_size (const char *binding)
|
483
|
+
{
|
484
|
+
ensure_eventmachine("evma_get_outbound_data_size");
|
485
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
486
|
+
return ed ? ed->GetOutboundDataSize() : 0;
|
487
|
+
}
|
488
|
+
|
489
|
+
|
490
|
+
/***********
|
491
|
+
evma__epoll
|
492
|
+
***********/
|
493
|
+
|
494
|
+
extern "C" void evma__epoll()
|
495
|
+
{
|
496
|
+
bUseEpoll = 1;
|
497
|
+
}
|
498
|
+
|
499
|
+
/************
|
500
|
+
evma__kqueue
|
501
|
+
************/
|
502
|
+
|
503
|
+
extern "C" void evma__kqueue()
|
504
|
+
{
|
505
|
+
bUseKqueue = 1;
|
506
|
+
}
|
507
|
+
|
508
|
+
|
509
|
+
/**********************
|
510
|
+
evma_set_rlimit_nofile
|
511
|
+
**********************/
|
512
|
+
|
513
|
+
extern "C" int evma_set_rlimit_nofile (int nofiles)
|
514
|
+
{
|
515
|
+
return EventMachine_t::SetRlimitNofile (nofiles);
|
516
|
+
}
|
517
|
+
|
518
|
+
|
519
|
+
/*********************************
|
520
|
+
evma_send_file_data_to_connection
|
521
|
+
*********************************/
|
522
|
+
|
523
|
+
extern "C" int evma_send_file_data_to_connection (const char *binding, const char *filename)
|
524
|
+
{
|
525
|
+
/* This is a sugaring over send_data_to_connection that reads a file into a
|
526
|
+
* locally-allocated buffer, and sends the file data to the remote peer.
|
527
|
+
* Return the number of bytes written to the caller.
|
528
|
+
* TODO, needs to impose a limit on the file size. This is intended only for
|
529
|
+
* small files. (I don't know, maybe 8K or less.) For larger files, use interleaved
|
530
|
+
* I/O to avoid slowing the rest of the system down.
|
531
|
+
* TODO: we should return a code rather than barf, in case of file-not-found.
|
532
|
+
* TODO, does this compile on Windows?
|
533
|
+
* TODO, given that we want this to work only with small files, how about allocating
|
534
|
+
* the buffer on the stack rather than the heap?
|
535
|
+
*
|
536
|
+
* Modified 25Jul07. This now returns -1 on file-too-large; 0 for success, and a positive
|
537
|
+
* errno in case of other errors.
|
538
|
+
*
|
539
|
+
/* Contributed by Kirk Haines.
|
540
|
+
*/
|
541
|
+
|
542
|
+
char data[32*1024];
|
543
|
+
int r;
|
544
|
+
|
545
|
+
ensure_eventmachine("evma_send_file_data_to_connection");
|
546
|
+
|
547
|
+
int Fd = open (filename, O_RDONLY);
|
548
|
+
|
549
|
+
if (Fd < 0)
|
550
|
+
return errno;
|
551
|
+
// From here on, all early returns MUST close Fd.
|
552
|
+
|
553
|
+
struct stat st;
|
554
|
+
if (fstat (Fd, &st)) {
|
555
|
+
int e = errno;
|
556
|
+
close (Fd);
|
557
|
+
return e;
|
558
|
+
}
|
559
|
+
|
560
|
+
int filesize = st.st_size;
|
561
|
+
if (filesize <= 0) {
|
562
|
+
close (Fd);
|
563
|
+
return 0;
|
564
|
+
}
|
565
|
+
else if (filesize > sizeof(data)) {
|
566
|
+
close (Fd);
|
567
|
+
return -1;
|
568
|
+
}
|
569
|
+
|
570
|
+
|
571
|
+
r = read (Fd, data, filesize);
|
572
|
+
if (r != filesize) {
|
573
|
+
int e = errno;
|
574
|
+
close (Fd);
|
575
|
+
return e;
|
576
|
+
}
|
577
|
+
evma_send_data_to_connection (binding, data, r);
|
578
|
+
close (Fd);
|
579
|
+
|
580
|
+
return 0;
|
581
|
+
}
|
582
|
+
|