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