sensu-em 2.0.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.travis.yml +12 -0
- data/.yardopts +7 -0
- data/CHANGELOG.md +33 -0
- data/GNU +281 -0
- data/Gemfile +2 -0
- data/LICENSE +60 -0
- data/README.md +109 -0
- data/Rakefile +20 -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/eventmachine.gemspec +38 -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 +887 -0
- data/ext/ed.cpp +1988 -0
- data/ext/ed.h +422 -0
- data/ext/em.cpp +2352 -0
- data/ext/em.h +253 -0
- data/ext/eventmachine.h +128 -0
- data/ext/extconf.rb +179 -0
- data/ext/fastfilereader/extconf.rb +103 -0
- data/ext/fastfilereader/mapper.cpp +214 -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 +347 -0
- data/ext/project.h +161 -0
- data/ext/rubymain.cpp +1318 -0
- data/ext/ssl.cpp +468 -0
- data/ext/ssl.h +94 -0
- data/java/.classpath +6 -0
- data/java/.gitignore +1 -0
- data/java/.project +17 -0
- data/java/src/com/rubyeventmachine/DatagramPacket.java +13 -0
- data/java/src/com/rubyeventmachine/EmReactor.java +529 -0
- data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
- data/java/src/com/rubyeventmachine/EventCallback.java +7 -0
- data/java/src/com/rubyeventmachine/EventCode.java +26 -0
- data/java/src/com/rubyeventmachine/EventableChannel.java +130 -0
- data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +180 -0
- data/java/src/com/rubyeventmachine/EventableSocketChannel.java +405 -0
- data/java/src/com/rubyeventmachine/SslBox.java +310 -0
- data/lib/em/buftok.rb +110 -0
- data/lib/em/callback.rb +58 -0
- data/lib/em/channel.rb +64 -0
- data/lib/em/completion.rb +304 -0
- data/lib/em/connection.rb +712 -0
- data/lib/em/deferrable/pool.rb +2 -0
- data/lib/em/deferrable.rb +210 -0
- data/lib/em/file_watch.rb +73 -0
- data/lib/em/future.rb +61 -0
- data/lib/em/iterator.rb +231 -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/header_and_content.rb +138 -0
- data/lib/em/protocols/httpclient.rb +279 -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 +161 -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 +365 -0
- data/lib/em/protocols/smtpserver.rb +643 -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/protocols.rb +37 -0
- data/lib/em/pure_ruby.rb +1017 -0
- data/lib/em/queue.rb +71 -0
- data/lib/em/resolver.rb +209 -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 +1553 -0
- data/lib/jeventmachine.rb +321 -0
- data/lib/rubyeventmachine.jar +0 -0
- data/rakelib/cpp.rake_example +77 -0
- data/rakelib/package.rake +98 -0
- data/rakelib/test.rake +8 -0
- data/tests/client.crt +31 -0
- data/tests/client.key +51 -0
- data/tests/em_test_helper.rb +64 -0
- data/tests/server.crt +36 -0
- data/tests/server.key +51 -0
- data/tests/test_attach.rb +150 -0
- data/tests/test_basic.rb +294 -0
- data/tests/test_channel.rb +62 -0
- data/tests/test_completion.rb +177 -0
- data/tests/test_connection_count.rb +53 -0
- data/tests/test_defer.rb +18 -0
- data/tests/test_deferrable.rb +35 -0
- data/tests/test_epoll.rb +145 -0
- data/tests/test_error_handler.rb +38 -0
- data/tests/test_exc.rb +28 -0
- data/tests/test_file_watch.rb +65 -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 +190 -0
- data/tests/test_httpclient2.rb +133 -0
- data/tests/test_idle_connection.rb +25 -0
- data/tests/test_inactivity_timeout.rb +54 -0
- data/tests/test_iterator.rb +97 -0
- data/tests/test_kb.rb +34 -0
- data/tests/test_line_protocol.rb +33 -0
- data/tests/test_ltp.rb +138 -0
- data/tests/test_ltp2.rb +288 -0
- data/tests/test_next_tick.rb +104 -0
- data/tests/test_object_protocol.rb +36 -0
- data/tests/test_pause.rb +102 -0
- data/tests/test_pending_connect_timeout.rb +52 -0
- data/tests/test_pool.rb +194 -0
- data/tests/test_process_watch.rb +48 -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 +50 -0
- data/tests/test_resolver.rb +55 -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 +37 -0
- data/tests/test_shutdown_hooks.rb +23 -0
- data/tests/test_smtpclient.rb +55 -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_echo_data.rb +60 -0
- data/tests/test_ssl_methods.rb +56 -0
- data/tests/test_ssl_verify.rb +82 -0
- data/tests/test_stomp.rb +37 -0
- data/tests/test_system.rb +42 -0
- data/tests/test_threaded_resource.rb +53 -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 +48 -0
- metadata +297 -0
data/ext/pipe.cpp
ADDED
@@ -0,0 +1,347 @@
|
|
1
|
+
/*****************************************************************************
|
2
|
+
|
3
|
+
$Id$
|
4
|
+
|
5
|
+
File: pipe.cpp
|
6
|
+
Date: 30May07
|
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
|
+
#ifdef OS_UNIX
|
24
|
+
// THIS ENTIRE FILE IS ONLY COMPILED ON UNIX-LIKE SYSTEMS.
|
25
|
+
|
26
|
+
/******************************
|
27
|
+
PipeDescriptor::PipeDescriptor
|
28
|
+
******************************/
|
29
|
+
|
30
|
+
PipeDescriptor::PipeDescriptor (int fd, pid_t subpid, EventMachine_t *parent_em):
|
31
|
+
EventableDescriptor (fd, parent_em),
|
32
|
+
bReadAttemptedAfterClose (false),
|
33
|
+
OutboundDataSize (0),
|
34
|
+
SubprocessPid (subpid)
|
35
|
+
{
|
36
|
+
#ifdef HAVE_EPOLL
|
37
|
+
EpollEvent.events = EPOLLIN;
|
38
|
+
#endif
|
39
|
+
#ifdef HAVE_KQUEUE
|
40
|
+
MyEventMachine->ArmKqueueReader (this);
|
41
|
+
#endif
|
42
|
+
}
|
43
|
+
|
44
|
+
|
45
|
+
/*******************************
|
46
|
+
PipeDescriptor::~PipeDescriptor
|
47
|
+
*******************************/
|
48
|
+
|
49
|
+
PipeDescriptor::~PipeDescriptor()
|
50
|
+
{
|
51
|
+
// Run down any stranded outbound data.
|
52
|
+
for (size_t i=0; i < OutboundPages.size(); i++)
|
53
|
+
OutboundPages[i].Free();
|
54
|
+
|
55
|
+
/* As a virtual destructor, we come here before the base-class
|
56
|
+
* destructor that closes our file-descriptor.
|
57
|
+
* We have to make sure the subprocess goes down (if it's not
|
58
|
+
* already down) and we have to reap the zombie.
|
59
|
+
*
|
60
|
+
* This implementation is PROVISIONAL and will surely be improved.
|
61
|
+
* The intention here is that we never block, hence the highly
|
62
|
+
* undesirable sleeps. But if we can't reap the subprocess even
|
63
|
+
* after sending it SIGKILL, then something is wrong and we
|
64
|
+
* throw a fatal exception, which is also not something we should
|
65
|
+
* be doing.
|
66
|
+
*
|
67
|
+
* Eventually the right thing to do will be to have the reactor
|
68
|
+
* core respond to SIGCHLD by chaining a handler on top of the
|
69
|
+
* one Ruby may have installed, and dealing with a list of dead
|
70
|
+
* children that are pending cleanup.
|
71
|
+
*
|
72
|
+
* Since we want to have a signal processor integrated into the
|
73
|
+
* client-visible API, let's wait until that is done before cleaning
|
74
|
+
* this up.
|
75
|
+
*
|
76
|
+
* Added a very ugly hack to support passing the subprocess's exit
|
77
|
+
* status to the user. It only makes logical sense for user code to access
|
78
|
+
* the subprocess exit status in the unbind callback. But unbind is called
|
79
|
+
* back during the EventableDescriptor destructor. So by that time there's
|
80
|
+
* no way to call back this object through an object binding, because it's
|
81
|
+
* already been cleaned up. We might have added a parameter to the unbind
|
82
|
+
* callback, but that would probably break a huge amount of existing code.
|
83
|
+
* So the hack-solution is to define an instance variable in the EventMachine
|
84
|
+
* object and stick the exit status in there, where it can easily be accessed
|
85
|
+
* with an accessor visible to user code.
|
86
|
+
* User code should ONLY access the exit status from within the unbind callback.
|
87
|
+
* Otherwise there's no guarantee it'll be valid.
|
88
|
+
* This hack won't make it impossible to run multiple EventMachines in a single
|
89
|
+
* process, but it will make it impossible to reliably nest unbind calls
|
90
|
+
* within other unbind calls. (Not sure if that's even possible.)
|
91
|
+
*/
|
92
|
+
|
93
|
+
assert (MyEventMachine);
|
94
|
+
|
95
|
+
/* Another hack to make the SubprocessPid available to get_subprocess_status */
|
96
|
+
MyEventMachine->SubprocessPid = SubprocessPid;
|
97
|
+
|
98
|
+
/* 01Mar09: Updated to use a small nanosleep in a loop. When nanosleep is interrupted by SIGCHLD,
|
99
|
+
* it resumes the system call after processing the signal (resulting in unnecessary latency).
|
100
|
+
* Calling nanosleep in a loop avoids this problem.
|
101
|
+
*/
|
102
|
+
struct timespec req = {0, 50000000}; // 0.05s
|
103
|
+
int n;
|
104
|
+
|
105
|
+
// wait 0.5s for the process to die
|
106
|
+
for (n=0; n<10; n++) {
|
107
|
+
if (waitpid (SubprocessPid, &(MyEventMachine->SubprocessExitStatus), WNOHANG) != 0) return;
|
108
|
+
nanosleep (&req, NULL);
|
109
|
+
}
|
110
|
+
|
111
|
+
// send SIGTERM and wait another 1s
|
112
|
+
kill (SubprocessPid, SIGTERM);
|
113
|
+
for (n=0; n<20; n++) {
|
114
|
+
nanosleep (&req, NULL);
|
115
|
+
if (waitpid (SubprocessPid, &(MyEventMachine->SubprocessExitStatus), WNOHANG) != 0) return;
|
116
|
+
}
|
117
|
+
|
118
|
+
// send SIGKILL and wait another 5s
|
119
|
+
kill (SubprocessPid, SIGKILL);
|
120
|
+
for (n=0; n<100; n++) {
|
121
|
+
nanosleep (&req, NULL);
|
122
|
+
if (waitpid (SubprocessPid, &(MyEventMachine->SubprocessExitStatus), WNOHANG) != 0) return;
|
123
|
+
}
|
124
|
+
|
125
|
+
// still not dead, give up!
|
126
|
+
throw std::runtime_error ("unable to reap subprocess");
|
127
|
+
}
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
/********************
|
132
|
+
PipeDescriptor::Read
|
133
|
+
********************/
|
134
|
+
|
135
|
+
void PipeDescriptor::Read()
|
136
|
+
{
|
137
|
+
int sd = GetSocket();
|
138
|
+
if (sd == INVALID_SOCKET) {
|
139
|
+
assert (!bReadAttemptedAfterClose);
|
140
|
+
bReadAttemptedAfterClose = true;
|
141
|
+
return;
|
142
|
+
}
|
143
|
+
|
144
|
+
LastActivity = MyEventMachine->GetCurrentLoopTime();
|
145
|
+
|
146
|
+
int total_bytes_read = 0;
|
147
|
+
char readbuffer [16 * 1024];
|
148
|
+
|
149
|
+
for (int i=0; i < 10; i++) {
|
150
|
+
// Don't read just one buffer and then move on. This is faster
|
151
|
+
// if there is a lot of incoming.
|
152
|
+
// But don't read indefinitely. Give other sockets a chance to run.
|
153
|
+
// NOTICE, we're reading one less than the buffer size.
|
154
|
+
// That's so we can put a guard byte at the end of what we send
|
155
|
+
// to user code.
|
156
|
+
// Use read instead of recv, which on Linux gives a "socket operation
|
157
|
+
// on nonsocket" error.
|
158
|
+
|
159
|
+
|
160
|
+
int r = read (sd, readbuffer, sizeof(readbuffer) - 1);
|
161
|
+
//cerr << "<R:" << r << ">";
|
162
|
+
|
163
|
+
if (r > 0) {
|
164
|
+
total_bytes_read += r;
|
165
|
+
|
166
|
+
// Add a null-terminator at the the end of the buffer
|
167
|
+
// that we will send to the callback.
|
168
|
+
// DO NOT EVER CHANGE THIS. We want to explicitly allow users
|
169
|
+
// to be able to depend on this behavior, so they will have
|
170
|
+
// the option to do some things faster. Additionally it's
|
171
|
+
// a security guard against buffer overflows.
|
172
|
+
readbuffer [r] = 0;
|
173
|
+
_GenericInboundDispatch(readbuffer, r);
|
174
|
+
}
|
175
|
+
else if (r == 0) {
|
176
|
+
break;
|
177
|
+
}
|
178
|
+
else {
|
179
|
+
// Basically a would-block, meaning we've read everything there is to read.
|
180
|
+
break;
|
181
|
+
}
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
|
186
|
+
if (total_bytes_read == 0) {
|
187
|
+
// If we read no data on a socket that selected readable,
|
188
|
+
// it generally means the other end closed the connection gracefully.
|
189
|
+
ScheduleClose (false);
|
190
|
+
//bCloseNow = true;
|
191
|
+
}
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
/*********************
|
196
|
+
PipeDescriptor::Write
|
197
|
+
*********************/
|
198
|
+
|
199
|
+
void PipeDescriptor::Write()
|
200
|
+
{
|
201
|
+
int sd = GetSocket();
|
202
|
+
assert (sd != INVALID_SOCKET);
|
203
|
+
|
204
|
+
LastActivity = MyEventMachine->GetCurrentLoopTime();
|
205
|
+
char output_buffer [16 * 1024];
|
206
|
+
size_t nbytes = 0;
|
207
|
+
|
208
|
+
while ((OutboundPages.size() > 0) && (nbytes < sizeof(output_buffer))) {
|
209
|
+
OutboundPage *op = &(OutboundPages[0]);
|
210
|
+
if ((nbytes + op->Length - op->Offset) < sizeof (output_buffer)) {
|
211
|
+
memcpy (output_buffer + nbytes, op->Buffer + op->Offset, op->Length - op->Offset);
|
212
|
+
nbytes += (op->Length - op->Offset);
|
213
|
+
op->Free();
|
214
|
+
OutboundPages.pop_front();
|
215
|
+
}
|
216
|
+
else {
|
217
|
+
int len = sizeof(output_buffer) - nbytes;
|
218
|
+
memcpy (output_buffer + nbytes, op->Buffer + op->Offset, len);
|
219
|
+
op->Offset += len;
|
220
|
+
nbytes += len;
|
221
|
+
}
|
222
|
+
}
|
223
|
+
|
224
|
+
// We should never have gotten here if there were no data to write,
|
225
|
+
// so assert that as a sanity check.
|
226
|
+
// Don't bother to make sure nbytes is less than output_buffer because
|
227
|
+
// if it were we probably would have crashed already.
|
228
|
+
assert (nbytes > 0);
|
229
|
+
|
230
|
+
assert (GetSocket() != INVALID_SOCKET);
|
231
|
+
int bytes_written = write (GetSocket(), output_buffer, nbytes);
|
232
|
+
|
233
|
+
if (bytes_written > 0) {
|
234
|
+
OutboundDataSize -= bytes_written;
|
235
|
+
if ((size_t)bytes_written < nbytes) {
|
236
|
+
int len = nbytes - bytes_written;
|
237
|
+
char *buffer = (char*) malloc (len + 1);
|
238
|
+
if (!buffer)
|
239
|
+
throw std::runtime_error ("bad alloc throwing back data");
|
240
|
+
memcpy (buffer, output_buffer + bytes_written, len);
|
241
|
+
buffer [len] = 0;
|
242
|
+
OutboundPages.push_front (OutboundPage (buffer, len));
|
243
|
+
}
|
244
|
+
#ifdef HAVE_EPOLL
|
245
|
+
EpollEvent.events = (EPOLLIN | (SelectForWrite() ? EPOLLOUT : 0));
|
246
|
+
assert (MyEventMachine);
|
247
|
+
MyEventMachine->Modify (this);
|
248
|
+
#endif
|
249
|
+
}
|
250
|
+
else {
|
251
|
+
#ifdef OS_UNIX
|
252
|
+
if ((errno != EINPROGRESS) && (errno != EWOULDBLOCK) && (errno != EINTR))
|
253
|
+
#endif
|
254
|
+
#ifdef OS_WIN32
|
255
|
+
if ((errno != WSAEINPROGRESS) && (errno != WSAEWOULDBLOCK))
|
256
|
+
#endif
|
257
|
+
Close();
|
258
|
+
}
|
259
|
+
}
|
260
|
+
|
261
|
+
|
262
|
+
/*************************
|
263
|
+
PipeDescriptor::Heartbeat
|
264
|
+
*************************/
|
265
|
+
|
266
|
+
void PipeDescriptor::Heartbeat()
|
267
|
+
{
|
268
|
+
// If an inactivity timeout is defined, then check for it.
|
269
|
+
if (InactivityTimeout && ((MyEventMachine->GetCurrentLoopTime() - LastActivity) >= InactivityTimeout))
|
270
|
+
ScheduleClose (false);
|
271
|
+
//bCloseNow = true;
|
272
|
+
}
|
273
|
+
|
274
|
+
|
275
|
+
/*****************************
|
276
|
+
PipeDescriptor::SelectForRead
|
277
|
+
*****************************/
|
278
|
+
|
279
|
+
bool PipeDescriptor::SelectForRead()
|
280
|
+
{
|
281
|
+
/* Pipe descriptors, being local by definition, don't have
|
282
|
+
* a pending state, so this is simpler than for the
|
283
|
+
* ConnectionDescriptor object.
|
284
|
+
*/
|
285
|
+
return bPaused ? false : true;
|
286
|
+
}
|
287
|
+
|
288
|
+
/******************************
|
289
|
+
PipeDescriptor::SelectForWrite
|
290
|
+
******************************/
|
291
|
+
|
292
|
+
bool PipeDescriptor::SelectForWrite()
|
293
|
+
{
|
294
|
+
/* Pipe descriptors, being local by definition, don't have
|
295
|
+
* a pending state, so this is simpler than for the
|
296
|
+
* ConnectionDescriptor object.
|
297
|
+
*/
|
298
|
+
return (GetOutboundDataSize() > 0) && !bPaused ? true : false;
|
299
|
+
}
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
|
304
|
+
/********************************
|
305
|
+
PipeDescriptor::SendOutboundData
|
306
|
+
********************************/
|
307
|
+
|
308
|
+
int PipeDescriptor::SendOutboundData (const char *data, int length)
|
309
|
+
{
|
310
|
+
//if (bCloseNow || bCloseAfterWriting)
|
311
|
+
if (IsCloseScheduled())
|
312
|
+
return 0;
|
313
|
+
|
314
|
+
if (!data && (length > 0))
|
315
|
+
throw std::runtime_error ("bad outbound data");
|
316
|
+
char *buffer = (char *) malloc (length + 1);
|
317
|
+
if (!buffer)
|
318
|
+
throw std::runtime_error ("no allocation for outbound data");
|
319
|
+
memcpy (buffer, data, length);
|
320
|
+
buffer [length] = 0;
|
321
|
+
OutboundPages.push_back (OutboundPage (buffer, length));
|
322
|
+
OutboundDataSize += length;
|
323
|
+
#ifdef HAVE_EPOLL
|
324
|
+
EpollEvent.events = (EPOLLIN | EPOLLOUT);
|
325
|
+
assert (MyEventMachine);
|
326
|
+
MyEventMachine->Modify (this);
|
327
|
+
#endif
|
328
|
+
return length;
|
329
|
+
}
|
330
|
+
|
331
|
+
/********************************
|
332
|
+
PipeDescriptor::GetSubprocessPid
|
333
|
+
********************************/
|
334
|
+
|
335
|
+
bool PipeDescriptor::GetSubprocessPid (pid_t *pid)
|
336
|
+
{
|
337
|
+
bool ok = false;
|
338
|
+
if (pid && (SubprocessPid > 0)) {
|
339
|
+
*pid = SubprocessPid;
|
340
|
+
ok = true;
|
341
|
+
}
|
342
|
+
return ok;
|
343
|
+
}
|
344
|
+
|
345
|
+
|
346
|
+
#endif // OS_UNIX
|
347
|
+
|
data/ext/project.h
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
/*****************************************************************************
|
2
|
+
|
3
|
+
$Id$
|
4
|
+
|
5
|
+
File: project.h
|
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
|
+
|
21
|
+
#ifndef __Project__H_
|
22
|
+
#define __Project__H_
|
23
|
+
|
24
|
+
|
25
|
+
#ifdef OS_WIN32
|
26
|
+
#pragma warning(disable:4786)
|
27
|
+
#endif
|
28
|
+
|
29
|
+
#include <iostream>
|
30
|
+
#include <map>
|
31
|
+
#include <set>
|
32
|
+
#include <vector>
|
33
|
+
#include <deque>
|
34
|
+
#include <string>
|
35
|
+
#include <sstream>
|
36
|
+
#include <stdexcept>
|
37
|
+
|
38
|
+
|
39
|
+
#ifdef OS_UNIX
|
40
|
+
#include <signal.h>
|
41
|
+
#include <netdb.h>
|
42
|
+
#include <time.h>
|
43
|
+
#include <sys/time.h>
|
44
|
+
#include <sys/types.h>
|
45
|
+
#include <sys/stat.h>
|
46
|
+
#include <sys/socket.h>
|
47
|
+
#include <sys/un.h>
|
48
|
+
#include <sys/resource.h>
|
49
|
+
#include <sys/wait.h>
|
50
|
+
#include <assert.h>
|
51
|
+
#include <unistd.h>
|
52
|
+
#include <fcntl.h>
|
53
|
+
#include <errno.h>
|
54
|
+
#include <netinet/in.h>
|
55
|
+
#include <netinet/tcp.h>
|
56
|
+
#include <arpa/inet.h>
|
57
|
+
#include <pwd.h>
|
58
|
+
#include <string.h>
|
59
|
+
typedef int SOCKET;
|
60
|
+
#define INVALID_SOCKET -1
|
61
|
+
#define SOCKET_ERROR -1
|
62
|
+
#ifdef OS_SOLARIS8
|
63
|
+
#include <strings.h>
|
64
|
+
#include <sys/un.h>
|
65
|
+
#ifndef AF_LOCAL
|
66
|
+
#define AF_LOCAL AF_UNIX
|
67
|
+
#endif
|
68
|
+
// INADDR_NONE is undefined on Solaris < 8. Thanks to Brett Eisenberg and Tim Pease.
|
69
|
+
#ifndef INADDR_NONE
|
70
|
+
#define INADDR_NONE ((unsigned long)-1)
|
71
|
+
#endif
|
72
|
+
#endif /* OS_SOLARIS8 */
|
73
|
+
|
74
|
+
#ifdef _AIX
|
75
|
+
#include <strings.h>
|
76
|
+
#ifndef AF_LOCAL
|
77
|
+
#define AF_LOCAL AF_UNIX
|
78
|
+
#endif
|
79
|
+
#endif /* _AIX */
|
80
|
+
|
81
|
+
#endif /* OS_UNIX */
|
82
|
+
|
83
|
+
#ifdef OS_WIN32
|
84
|
+
// 21Sep09: windows limits select() to 64 sockets by default, we increase it to 1024 here (before including winsock2.h)
|
85
|
+
// 18Jun12: fd_setsize must be changed in the ruby binary (not in this extension). redefining it also causes segvs, see eventmachine/eventmachine#333
|
86
|
+
//#define FD_SETSIZE 1024
|
87
|
+
|
88
|
+
#define WIN32_LEAN_AND_MEAN
|
89
|
+
#include <windows.h>
|
90
|
+
#include <winsock2.h>
|
91
|
+
#include <ws2tcpip.h>
|
92
|
+
#include <rpc.h>
|
93
|
+
#include <fcntl.h>
|
94
|
+
#include <assert.h>
|
95
|
+
|
96
|
+
#define close closesocket
|
97
|
+
|
98
|
+
typedef int socklen_t;
|
99
|
+
#ifndef _PID_T_
|
100
|
+
#define _PID_T_
|
101
|
+
typedef int pid_t;
|
102
|
+
#endif /* _PID_T_ */
|
103
|
+
#endif /* OS_WIN32 */
|
104
|
+
|
105
|
+
#if !defined(_MSC_VER) || _MSC_VER > 1500
|
106
|
+
#include <stdint.h>
|
107
|
+
#endif
|
108
|
+
|
109
|
+
using namespace std;
|
110
|
+
|
111
|
+
#ifdef WITH_SSL
|
112
|
+
#include <openssl/ssl.h>
|
113
|
+
#include <openssl/err.h>
|
114
|
+
#endif
|
115
|
+
|
116
|
+
#ifdef HAVE_EPOLL
|
117
|
+
#include <sys/epoll.h>
|
118
|
+
#endif
|
119
|
+
|
120
|
+
#ifdef HAVE_KQUEUE
|
121
|
+
#include <sys/event.h>
|
122
|
+
#include <sys/queue.h>
|
123
|
+
#endif
|
124
|
+
|
125
|
+
#ifdef HAVE_INOTIFY
|
126
|
+
#include <sys/inotify.h>
|
127
|
+
#endif
|
128
|
+
|
129
|
+
#ifdef HAVE_OLD_INOTIFY
|
130
|
+
#include <sys/syscall.h>
|
131
|
+
#include <linux/inotify.h>
|
132
|
+
static inline int inotify_init (void) { return syscall (__NR_inotify_init); }
|
133
|
+
static inline int inotify_add_watch (int fd, const char *name, __u32 mask) { return syscall (__NR_inotify_add_watch, fd, name, mask); }
|
134
|
+
static inline int inotify_rm_watch (int fd, __u32 wd) { return syscall (__NR_inotify_rm_watch, fd, wd); }
|
135
|
+
#define HAVE_INOTIFY 1
|
136
|
+
#endif
|
137
|
+
|
138
|
+
#ifdef HAVE_INOTIFY
|
139
|
+
#define INOTIFY_EVENT_SIZE (sizeof(struct inotify_event))
|
140
|
+
#endif
|
141
|
+
|
142
|
+
#ifdef HAVE_WRITEV
|
143
|
+
#include <sys/uio.h>
|
144
|
+
#endif
|
145
|
+
|
146
|
+
#if __cplusplus
|
147
|
+
extern "C" {
|
148
|
+
#endif
|
149
|
+
typedef void (*EMCallback)(const unsigned long, int, const char*, const unsigned long);
|
150
|
+
#if __cplusplus
|
151
|
+
}
|
152
|
+
#endif
|
153
|
+
|
154
|
+
#include "binder.h"
|
155
|
+
#include "em.h"
|
156
|
+
#include "ed.h"
|
157
|
+
#include "page.h"
|
158
|
+
#include "ssl.h"
|
159
|
+
#include "eventmachine.h"
|
160
|
+
|
161
|
+
#endif // __Project__H_
|