eventmachine 0.12.6-x86-mswin32-60 → 0.12.8-x86-mswin32-60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/{docs/README → README} +21 -13
- data/Rakefile +14 -4
- data/docs/DEFERRABLES +0 -5
- data/docs/INSTALL +2 -4
- data/docs/LEGAL +1 -1
- data/docs/LIGHTWEIGHT_CONCURRENCY +0 -2
- data/docs/PURE_RUBY +0 -2
- data/docs/RELEASE_NOTES +0 -2
- data/docs/SMTP +0 -7
- data/docs/SPAWNED_PROCESSES +0 -4
- data/docs/TODO +0 -2
- data/eventmachine.gemspec +41 -32
- data/examples/ex_channel.rb +43 -0
- data/examples/ex_queue.rb +2 -0
- data/examples/helper.rb +2 -0
- data/ext/cmain.cpp +685 -586
- data/ext/cplusplus.cpp +15 -6
- data/ext/ed.cpp +1732 -1522
- data/ext/ed.h +407 -380
- data/ext/em.cpp +2263 -1937
- data/ext/em.h +223 -186
- data/ext/eventmachine.h +111 -98
- data/ext/eventmachine_cpp.h +1 -0
- data/ext/extconf.rb +4 -0
- data/ext/kb.cpp +81 -82
- data/ext/pipe.cpp +349 -351
- data/ext/project.h +21 -0
- data/ext/rubymain.cpp +1047 -847
- data/ext/ssl.cpp +38 -1
- data/ext/ssl.h +5 -1
- data/java/src/com/rubyeventmachine/Application.java +7 -3
- data/java/src/com/rubyeventmachine/EmReactor.java +16 -1
- data/java/src/com/rubyeventmachine/tests/ConnectTest.java +25 -3
- data/lib/{protocols → em}/buftok.rb +16 -5
- data/lib/em/callback.rb +26 -0
- data/lib/em/channel.rb +57 -0
- data/lib/em/connection.rb +505 -0
- data/lib/em/deferrable.rb +144 -165
- data/lib/em/file_watch.rb +54 -0
- data/lib/em/future.rb +24 -25
- data/lib/em/messages.rb +1 -1
- data/lib/em/process_watch.rb +44 -0
- data/lib/em/processes.rb +119 -113
- data/lib/em/protocols.rb +35 -0
- data/lib/em/protocols/header_and_content.rb +138 -0
- data/lib/em/protocols/httpclient.rb +263 -0
- data/lib/em/protocols/httpclient2.rb +582 -0
- data/lib/{protocols → em/protocols}/line_and_text.rb +2 -2
- data/lib/em/protocols/linetext2.rb +160 -0
- data/lib/{protocols → em/protocols}/memcache.rb +37 -7
- data/lib/em/protocols/object_protocol.rb +39 -0
- data/lib/em/protocols/postgres3.rb +247 -0
- data/lib/em/protocols/saslauth.rb +175 -0
- data/lib/em/protocols/smtpclient.rb +331 -0
- data/lib/em/protocols/smtpserver.rb +547 -0
- data/lib/em/protocols/stomp.rb +200 -0
- data/lib/{protocols → em/protocols}/tcptest.rb +21 -25
- data/lib/em/queue.rb +61 -0
- data/lib/em/spawnable.rb +53 -56
- data/lib/em/streamer.rb +92 -74
- data/lib/em/timers.rb +55 -0
- data/lib/em/version.rb +3 -0
- data/lib/eventmachine.rb +1636 -1926
- data/lib/evma.rb +1 -1
- data/lib/jeventmachine.rb +106 -101
- data/lib/pr_eventmachine.rb +47 -36
- data/tasks/project.rake +2 -1
- data/tests/client.crt +31 -0
- data/tests/client.key +51 -0
- data/tests/test_attach.rb +18 -0
- data/tests/test_basic.rb +285 -231
- data/tests/test_channel.rb +63 -0
- data/tests/test_connection_count.rb +2 -2
- data/tests/test_epoll.rb +162 -163
- data/tests/test_errors.rb +36 -36
- data/tests/test_exc.rb +22 -25
- data/tests/test_file_watch.rb +49 -0
- data/tests/test_futures.rb +77 -93
- data/tests/test_hc.rb +2 -2
- data/tests/test_httpclient.rb +55 -52
- data/tests/test_httpclient2.rb +153 -155
- data/tests/test_inactivity_timeout.rb +30 -0
- data/tests/test_kb.rb +8 -9
- data/tests/test_ltp2.rb +274 -277
- data/tests/test_next_tick.rb +135 -109
- data/tests/test_object_protocol.rb +37 -0
- data/tests/test_process_watch.rb +48 -0
- data/tests/test_processes.rb +128 -95
- data/tests/test_proxy_connection.rb +92 -0
- data/tests/test_pure.rb +1 -5
- data/tests/test_queue.rb +44 -0
- data/tests/test_running.rb +9 -14
- data/tests/test_sasl.rb +32 -34
- data/tests/test_send_file.rb +175 -176
- data/tests/test_servers.rb +37 -41
- data/tests/test_smtpserver.rb +47 -55
- data/tests/test_spawn.rb +284 -291
- data/tests/test_ssl_args.rb +1 -1
- data/tests/test_ssl_methods.rb +1 -1
- data/tests/test_ssl_verify.rb +82 -0
- data/tests/test_timers.rb +81 -88
- data/tests/test_ud.rb +0 -7
- data/tests/testem.rb +1 -1
- metadata +52 -36
- data/lib/em/eventable.rb +0 -39
- data/lib/eventmachine_version.rb +0 -31
- data/lib/protocols/header_and_content.rb +0 -129
- data/lib/protocols/httpcli2.rb +0 -803
- data/lib/protocols/httpclient.rb +0 -270
- data/lib/protocols/linetext2.rb +0 -161
- data/lib/protocols/postgres.rb +0 -261
- data/lib/protocols/saslauth.rb +0 -179
- data/lib/protocols/smtpclient.rb +0 -308
- data/lib/protocols/smtpserver.rb +0 -556
- data/lib/protocols/stomp.rb +0 -153
- data/tests/test_eventables.rb +0 -77
data/ext/cplusplus.cpp
CHANGED
@@ -33,7 +33,7 @@ EM::Run
|
|
33
33
|
|
34
34
|
void EM::Run (void (*start_func)())
|
35
35
|
{
|
36
|
-
|
36
|
+
evma_set_epoll (1);
|
37
37
|
evma_initialize_library (EM::Callback);
|
38
38
|
if (start_func)
|
39
39
|
AddTimer (0, start_func);
|
@@ -115,13 +115,13 @@ void EM::Connection::Close (bool afterWriting)
|
|
115
115
|
}
|
116
116
|
|
117
117
|
|
118
|
-
|
119
|
-
EM::Connection::
|
120
|
-
|
118
|
+
/***************************
|
119
|
+
EM::Connection::BindConnect
|
120
|
+
***************************/
|
121
121
|
|
122
|
-
void EM::Connection::
|
122
|
+
void EM::Connection::BindConnect (const char *bind_addr, int bind_port, const char *host, int port)
|
123
123
|
{
|
124
|
-
Signature = evma_connect_to_server (host, port);
|
124
|
+
Signature = evma_connect_to_server (bind_addr, bind_port, host, port);
|
125
125
|
#ifdef OS_SOLARIS8
|
126
126
|
Eventables.insert( std::map<std::string,EM::Eventable*>::value_type (Signature, this));
|
127
127
|
#else
|
@@ -129,6 +129,15 @@ void EM::Connection::Connect (const char *host, int port)
|
|
129
129
|
#endif
|
130
130
|
}
|
131
131
|
|
132
|
+
/***********************
|
133
|
+
EM::Connection::Connect
|
134
|
+
***********************/
|
135
|
+
|
136
|
+
void EM::Connection::Connect (const char *host, int port)
|
137
|
+
{
|
138
|
+
this->BindConnect(NULL, 0, host, port);
|
139
|
+
}
|
140
|
+
|
132
141
|
/*******************
|
133
142
|
EM::Acceptor::Start
|
134
143
|
*******************/
|
data/ext/ed.cpp
CHANGED
@@ -1,1522 +1,1732 @@
|
|
1
|
-
/*****************************************************************************
|
2
|
-
|
3
|
-
$Id$
|
4
|
-
|
5
|
-
File: ed.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
|
-
|
24
|
-
/********************
|
25
|
-
SetSocketNonblocking
|
26
|
-
********************/
|
27
|
-
|
28
|
-
bool SetSocketNonblocking (SOCKET sd)
|
29
|
-
{
|
30
|
-
#ifdef OS_UNIX
|
31
|
-
int val = fcntl (sd, F_GETFL, 0);
|
32
|
-
return (fcntl (sd, F_SETFL, val | O_NONBLOCK) != SOCKET_ERROR) ? true : false;
|
33
|
-
#endif
|
34
|
-
|
35
|
-
#ifdef OS_WIN32
|
36
|
-
unsigned long one = 1;
|
37
|
-
return (ioctlsocket (sd, FIONBIO, &one) == 0) ? true : false;
|
38
|
-
#endif
|
39
|
-
}
|
40
|
-
|
41
|
-
|
42
|
-
/****************************************
|
43
|
-
EventableDescriptor::EventableDescriptor
|
44
|
-
****************************************/
|
45
|
-
|
46
|
-
EventableDescriptor::EventableDescriptor (int sd, EventMachine_t *em):
|
47
|
-
bCloseNow (false),
|
48
|
-
bCloseAfterWriting (false),
|
49
|
-
MySocket (sd),
|
50
|
-
EventCallback (NULL),
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
*
|
59
|
-
*
|
60
|
-
*
|
61
|
-
*
|
62
|
-
*
|
63
|
-
*
|
64
|
-
*
|
65
|
-
*
|
66
|
-
* the
|
67
|
-
*
|
68
|
-
*
|
69
|
-
*
|
70
|
-
*
|
71
|
-
*
|
72
|
-
*
|
73
|
-
*
|
74
|
-
*
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
Close();
|
99
|
-
}
|
100
|
-
|
101
|
-
|
102
|
-
/*************************************
|
103
|
-
EventableDescriptor::SetEventCallback
|
104
|
-
*************************************/
|
105
|
-
|
106
|
-
void EventableDescriptor::SetEventCallback (void(*cb)(const char*, int, const char*, int))
|
107
|
-
{
|
108
|
-
EventCallback = cb;
|
109
|
-
}
|
110
|
-
|
111
|
-
|
112
|
-
/**************************
|
113
|
-
EventableDescriptor::Close
|
114
|
-
**************************/
|
115
|
-
|
116
|
-
void EventableDescriptor::Close()
|
117
|
-
{
|
118
|
-
// Close the socket right now. Intended for emergencies.
|
119
|
-
if (MySocket != INVALID_SOCKET) {
|
120
|
-
shutdown (MySocket, 1);
|
121
|
-
closesocket (MySocket);
|
122
|
-
MySocket = INVALID_SOCKET;
|
123
|
-
}
|
124
|
-
}
|
125
|
-
|
126
|
-
|
127
|
-
/*********************************
|
128
|
-
EventableDescriptor::ShouldDelete
|
129
|
-
*********************************/
|
130
|
-
|
131
|
-
bool EventableDescriptor::ShouldDelete()
|
132
|
-
{
|
133
|
-
/* For use by a socket manager, which needs to know if this object
|
134
|
-
* should be removed from scheduling events and deleted.
|
135
|
-
* Has an immediate close been scheduled, or are we already closed?
|
136
|
-
* If either of these are the case, return true. In theory, the manager will
|
137
|
-
* then delete us, which in turn will make sure the socket is closed.
|
138
|
-
* Note, if bCloseAfterWriting is true, we check a virtual method to see
|
139
|
-
* if there is outbound data to write, and only request a close if there is none.
|
140
|
-
*/
|
141
|
-
|
142
|
-
return ((MySocket == INVALID_SOCKET) || bCloseNow || (bCloseAfterWriting && (GetOutboundDataSize() <= 0)));
|
143
|
-
}
|
144
|
-
|
145
|
-
|
146
|
-
/**********************************
|
147
|
-
EventableDescriptor::ScheduleClose
|
148
|
-
**********************************/
|
149
|
-
|
150
|
-
void EventableDescriptor::ScheduleClose (bool after_writing)
|
151
|
-
{
|
152
|
-
// KEEP THIS SYNCHRONIZED WITH ::IsCloseScheduled.
|
153
|
-
if (after_writing)
|
154
|
-
bCloseAfterWriting = true;
|
155
|
-
else
|
156
|
-
bCloseNow = true;
|
157
|
-
}
|
158
|
-
|
159
|
-
|
160
|
-
/*************************************
|
161
|
-
EventableDescriptor::IsCloseScheduled
|
162
|
-
*************************************/
|
163
|
-
|
164
|
-
bool EventableDescriptor::IsCloseScheduled()
|
165
|
-
{
|
166
|
-
// KEEP THIS SYNCHRONIZED WITH ::ScheduleClose.
|
167
|
-
return (bCloseNow || bCloseAfterWriting);
|
168
|
-
}
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
#endif
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
*
|
412
|
-
*
|
413
|
-
*
|
414
|
-
*
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
if (
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
if (
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
}
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
if (
|
664
|
-
int
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
}
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
}
|
832
|
-
|
833
|
-
|
834
|
-
#
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
#
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
}
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
{
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1136
|
-
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
//
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1227
|
-
|
1228
|
-
|
1229
|
-
|
1230
|
-
|
1231
|
-
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
1255
|
-
DatagramDescriptor::
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1264
|
-
*
|
1265
|
-
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
1273
|
-
|
1274
|
-
|
1275
|
-
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1285
|
-
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1293
|
-
|
1294
|
-
|
1295
|
-
|
1296
|
-
|
1297
|
-
|
1298
|
-
|
1299
|
-
|
1300
|
-
|
1301
|
-
|
1302
|
-
|
1303
|
-
|
1304
|
-
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1324
|
-
|
1325
|
-
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1329
|
-
|
1330
|
-
|
1331
|
-
|
1332
|
-
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1336
|
-
|
1337
|
-
|
1338
|
-
|
1339
|
-
|
1340
|
-
|
1341
|
-
|
1342
|
-
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1348
|
-
|
1349
|
-
|
1350
|
-
|
1351
|
-
|
1352
|
-
|
1353
|
-
|
1354
|
-
|
1355
|
-
|
1356
|
-
|
1357
|
-
|
1358
|
-
|
1359
|
-
|
1360
|
-
|
1361
|
-
|
1362
|
-
|
1363
|
-
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
|
1381
|
-
|
1382
|
-
|
1383
|
-
|
1384
|
-
|
1385
|
-
|
1386
|
-
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
1403
|
-
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1411
|
-
|
1412
|
-
|
1413
|
-
|
1414
|
-
//
|
1415
|
-
|
1416
|
-
|
1417
|
-
|
1418
|
-
|
1419
|
-
|
1420
|
-
|
1421
|
-
|
1422
|
-
|
1423
|
-
|
1424
|
-
|
1425
|
-
|
1426
|
-
|
1427
|
-
|
1428
|
-
|
1429
|
-
|
1430
|
-
|
1431
|
-
|
1432
|
-
|
1433
|
-
|
1434
|
-
|
1435
|
-
|
1436
|
-
|
1437
|
-
|
1438
|
-
|
1439
|
-
|
1440
|
-
|
1441
|
-
|
1442
|
-
|
1443
|
-
|
1444
|
-
|
1445
|
-
|
1446
|
-
|
1447
|
-
|
1448
|
-
|
1449
|
-
|
1450
|
-
|
1451
|
-
|
1452
|
-
|
1453
|
-
|
1454
|
-
|
1455
|
-
|
1456
|
-
|
1457
|
-
|
1458
|
-
|
1459
|
-
|
1460
|
-
|
1461
|
-
|
1462
|
-
|
1463
|
-
|
1464
|
-
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1469
|
-
if (
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
1474
|
-
|
1475
|
-
|
1476
|
-
|
1477
|
-
|
1478
|
-
|
1479
|
-
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1485
|
-
|
1486
|
-
|
1487
|
-
|
1488
|
-
|
1489
|
-
|
1490
|
-
|
1491
|
-
|
1492
|
-
|
1493
|
-
|
1494
|
-
|
1495
|
-
|
1496
|
-
|
1497
|
-
DatagramDescriptor::
|
1498
|
-
|
1499
|
-
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
|
1506
|
-
|
1507
|
-
|
1508
|
-
|
1509
|
-
|
1510
|
-
|
1511
|
-
|
1512
|
-
|
1513
|
-
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1518
|
-
|
1519
|
-
|
1520
|
-
|
1521
|
-
|
1522
|
-
|
1
|
+
/*****************************************************************************
|
2
|
+
|
3
|
+
$Id$
|
4
|
+
|
5
|
+
File: ed.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
|
+
|
24
|
+
/********************
|
25
|
+
SetSocketNonblocking
|
26
|
+
********************/
|
27
|
+
|
28
|
+
bool SetSocketNonblocking (SOCKET sd)
|
29
|
+
{
|
30
|
+
#ifdef OS_UNIX
|
31
|
+
int val = fcntl (sd, F_GETFL, 0);
|
32
|
+
return (fcntl (sd, F_SETFL, val | O_NONBLOCK) != SOCKET_ERROR) ? true : false;
|
33
|
+
#endif
|
34
|
+
|
35
|
+
#ifdef OS_WIN32
|
36
|
+
unsigned long one = 1;
|
37
|
+
return (ioctlsocket (sd, FIONBIO, &one) == 0) ? true : false;
|
38
|
+
#endif
|
39
|
+
}
|
40
|
+
|
41
|
+
|
42
|
+
/****************************************
|
43
|
+
EventableDescriptor::EventableDescriptor
|
44
|
+
****************************************/
|
45
|
+
|
46
|
+
EventableDescriptor::EventableDescriptor (int sd, EventMachine_t *em):
|
47
|
+
bCloseNow (false),
|
48
|
+
bCloseAfterWriting (false),
|
49
|
+
MySocket (sd),
|
50
|
+
EventCallback (NULL),
|
51
|
+
bCallbackUnbind (true),
|
52
|
+
UnbindReasonCode (0),
|
53
|
+
ProxyTarget(NULL),
|
54
|
+
MyEventMachine (em)
|
55
|
+
{
|
56
|
+
/* There are three ways to close a socket, all of which should
|
57
|
+
* automatically signal to the event machine that this object
|
58
|
+
* should be removed from the polling scheduler.
|
59
|
+
* First is a hard close, intended for bad errors or possible
|
60
|
+
* security violations. It immediately closes the connection
|
61
|
+
* and puts this object into an error state.
|
62
|
+
* Second is to set bCloseNow, which will cause the event machine
|
63
|
+
* to delete this object (and thus close the connection in our
|
64
|
+
* destructor) the next chance it gets. bCloseNow also inhibits
|
65
|
+
* the writing of new data on the socket (but not necessarily
|
66
|
+
* the reading of new data).
|
67
|
+
* The third way is to set bCloseAfterWriting, which inhibits
|
68
|
+
* the writing of new data and converts to bCloseNow as soon
|
69
|
+
* as everything in the outbound queue has been written.
|
70
|
+
* bCloseAfterWriting is really for use only by protocol handlers
|
71
|
+
* (for example, HTTP writes an HTML page and then closes the
|
72
|
+
* connection). All of the error states we generate internally
|
73
|
+
* cause an immediate close to be scheduled, which may have the
|
74
|
+
* effect of discarding outbound data.
|
75
|
+
*/
|
76
|
+
|
77
|
+
if (sd == INVALID_SOCKET)
|
78
|
+
throw std::runtime_error ("bad eventable descriptor");
|
79
|
+
if (MyEventMachine == NULL)
|
80
|
+
throw std::runtime_error ("bad em in eventable descriptor");
|
81
|
+
CreatedAt = gCurrentLoopTime;
|
82
|
+
|
83
|
+
#ifdef HAVE_EPOLL
|
84
|
+
EpollEvent.data.ptr = this;
|
85
|
+
#endif
|
86
|
+
}
|
87
|
+
|
88
|
+
|
89
|
+
/*****************************************
|
90
|
+
EventableDescriptor::~EventableDescriptor
|
91
|
+
*****************************************/
|
92
|
+
|
93
|
+
EventableDescriptor::~EventableDescriptor()
|
94
|
+
{
|
95
|
+
if (EventCallback && bCallbackUnbind)
|
96
|
+
(*EventCallback)(GetBinding().c_str(), EM_CONNECTION_UNBOUND, NULL, UnbindReasonCode);
|
97
|
+
StopProxy();
|
98
|
+
Close();
|
99
|
+
}
|
100
|
+
|
101
|
+
|
102
|
+
/*************************************
|
103
|
+
EventableDescriptor::SetEventCallback
|
104
|
+
*************************************/
|
105
|
+
|
106
|
+
void EventableDescriptor::SetEventCallback (void(*cb)(const char*, int, const char*, int))
|
107
|
+
{
|
108
|
+
EventCallback = cb;
|
109
|
+
}
|
110
|
+
|
111
|
+
|
112
|
+
/**************************
|
113
|
+
EventableDescriptor::Close
|
114
|
+
**************************/
|
115
|
+
|
116
|
+
void EventableDescriptor::Close()
|
117
|
+
{
|
118
|
+
// Close the socket right now. Intended for emergencies.
|
119
|
+
if (MySocket != INVALID_SOCKET) {
|
120
|
+
shutdown (MySocket, 1);
|
121
|
+
closesocket (MySocket);
|
122
|
+
MySocket = INVALID_SOCKET;
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
|
127
|
+
/*********************************
|
128
|
+
EventableDescriptor::ShouldDelete
|
129
|
+
*********************************/
|
130
|
+
|
131
|
+
bool EventableDescriptor::ShouldDelete()
|
132
|
+
{
|
133
|
+
/* For use by a socket manager, which needs to know if this object
|
134
|
+
* should be removed from scheduling events and deleted.
|
135
|
+
* Has an immediate close been scheduled, or are we already closed?
|
136
|
+
* If either of these are the case, return true. In theory, the manager will
|
137
|
+
* then delete us, which in turn will make sure the socket is closed.
|
138
|
+
* Note, if bCloseAfterWriting is true, we check a virtual method to see
|
139
|
+
* if there is outbound data to write, and only request a close if there is none.
|
140
|
+
*/
|
141
|
+
|
142
|
+
return ((MySocket == INVALID_SOCKET) || bCloseNow || (bCloseAfterWriting && (GetOutboundDataSize() <= 0)));
|
143
|
+
}
|
144
|
+
|
145
|
+
|
146
|
+
/**********************************
|
147
|
+
EventableDescriptor::ScheduleClose
|
148
|
+
**********************************/
|
149
|
+
|
150
|
+
void EventableDescriptor::ScheduleClose (bool after_writing)
|
151
|
+
{
|
152
|
+
// KEEP THIS SYNCHRONIZED WITH ::IsCloseScheduled.
|
153
|
+
if (after_writing)
|
154
|
+
bCloseAfterWriting = true;
|
155
|
+
else
|
156
|
+
bCloseNow = true;
|
157
|
+
}
|
158
|
+
|
159
|
+
|
160
|
+
/*************************************
|
161
|
+
EventableDescriptor::IsCloseScheduled
|
162
|
+
*************************************/
|
163
|
+
|
164
|
+
bool EventableDescriptor::IsCloseScheduled()
|
165
|
+
{
|
166
|
+
// KEEP THIS SYNCHRONIZED WITH ::ScheduleClose.
|
167
|
+
return (bCloseNow || bCloseAfterWriting);
|
168
|
+
}
|
169
|
+
|
170
|
+
|
171
|
+
/*******************************
|
172
|
+
EventableDescriptor::StartProxy
|
173
|
+
*******************************/
|
174
|
+
|
175
|
+
void EventableDescriptor::StartProxy(const char *to)
|
176
|
+
{
|
177
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (to));
|
178
|
+
if (ed) {
|
179
|
+
StopProxy();
|
180
|
+
ProxyTarget = strdup(to);
|
181
|
+
return;
|
182
|
+
}
|
183
|
+
throw std::runtime_error ("Tried to proxy to an invalid descriptor");
|
184
|
+
}
|
185
|
+
|
186
|
+
|
187
|
+
/******************************
|
188
|
+
EventableDescriptor::StopProxy
|
189
|
+
******************************/
|
190
|
+
|
191
|
+
void EventableDescriptor::StopProxy()
|
192
|
+
{
|
193
|
+
if (ProxyTarget) {
|
194
|
+
free(ProxyTarget);
|
195
|
+
ProxyTarget = NULL;
|
196
|
+
}
|
197
|
+
}
|
198
|
+
|
199
|
+
|
200
|
+
/********************************************
|
201
|
+
EventableDescriptor::_GenericInboundDispatch
|
202
|
+
********************************************/
|
203
|
+
|
204
|
+
void EventableDescriptor::_GenericInboundDispatch(const char *buf, int size)
|
205
|
+
{
|
206
|
+
assert(EventCallback);
|
207
|
+
|
208
|
+
if (!ProxyTarget)
|
209
|
+
(*EventCallback)(GetBinding().c_str(), EM_CONNECTION_READ, buf, size);
|
210
|
+
else if (ConnectionDescriptor::SendDataToConnection(ProxyTarget, buf, size) == -1) {
|
211
|
+
(*EventCallback)(GetBinding().c_str(), EM_PROXY_TARGET_UNBOUND, NULL, 0);
|
212
|
+
StopProxy();
|
213
|
+
}
|
214
|
+
}
|
215
|
+
|
216
|
+
|
217
|
+
/******************************************
|
218
|
+
ConnectionDescriptor::ConnectionDescriptor
|
219
|
+
******************************************/
|
220
|
+
|
221
|
+
ConnectionDescriptor::ConnectionDescriptor (int sd, EventMachine_t *em):
|
222
|
+
EventableDescriptor (sd, em),
|
223
|
+
bConnectPending (false),
|
224
|
+
bNotifyReadable (false),
|
225
|
+
bNotifyWritable (false),
|
226
|
+
bReadAttemptedAfterClose (false),
|
227
|
+
bWriteAttemptedAfterClose (false),
|
228
|
+
OutboundDataSize (0),
|
229
|
+
#ifdef WITH_SSL
|
230
|
+
SslBox (NULL),
|
231
|
+
bHandshakeSignaled (false),
|
232
|
+
bSslVerifyPeer (false),
|
233
|
+
bSslPeerAccepted(false),
|
234
|
+
#endif
|
235
|
+
#ifdef HAVE_KQUEUE
|
236
|
+
bGotExtraKqueueEvent(false),
|
237
|
+
#endif
|
238
|
+
bIsServer (false),
|
239
|
+
LastIo (gCurrentLoopTime),
|
240
|
+
InactivityTimeout (0)
|
241
|
+
{
|
242
|
+
// 22Jan09: Moved ArmKqueueWriter into SetConnectPending() to fix assertion failure in _WriteOutboundData()
|
243
|
+
// 5May09: Moved EPOLLOUT into SetConnectPending() so it doesn't happen for attached read pipes
|
244
|
+
}
|
245
|
+
|
246
|
+
|
247
|
+
/*******************************************
|
248
|
+
ConnectionDescriptor::~ConnectionDescriptor
|
249
|
+
*******************************************/
|
250
|
+
|
251
|
+
ConnectionDescriptor::~ConnectionDescriptor()
|
252
|
+
{
|
253
|
+
// Run down any stranded outbound data.
|
254
|
+
for (size_t i=0; i < OutboundPages.size(); i++)
|
255
|
+
OutboundPages[i].Free();
|
256
|
+
|
257
|
+
#ifdef WITH_SSL
|
258
|
+
if (SslBox)
|
259
|
+
delete SslBox;
|
260
|
+
#endif
|
261
|
+
}
|
262
|
+
|
263
|
+
|
264
|
+
/**************************************************
|
265
|
+
STATIC: ConnectionDescriptor::SendDataToConnection
|
266
|
+
**************************************************/
|
267
|
+
|
268
|
+
int ConnectionDescriptor::SendDataToConnection (const char *binding, const char *data, int data_length)
|
269
|
+
{
|
270
|
+
// TODO: This is something of a hack, or at least it's a static method of the wrong class.
|
271
|
+
// TODO: Poor polymorphism here. We should be calling one virtual method
|
272
|
+
// instead of hacking out the runtime information of the target object.
|
273
|
+
ConnectionDescriptor *cd = dynamic_cast <ConnectionDescriptor*> (Bindable_t::GetObject (binding));
|
274
|
+
if (cd)
|
275
|
+
return cd->SendOutboundData (data, data_length);
|
276
|
+
DatagramDescriptor *ds = dynamic_cast <DatagramDescriptor*> (Bindable_t::GetObject (binding));
|
277
|
+
if (ds)
|
278
|
+
return ds->SendOutboundData (data, data_length);
|
279
|
+
#ifdef OS_UNIX
|
280
|
+
PipeDescriptor *ps = dynamic_cast <PipeDescriptor*> (Bindable_t::GetObject (binding));
|
281
|
+
if (ps)
|
282
|
+
return ps->SendOutboundData (data, data_length);
|
283
|
+
#endif
|
284
|
+
return -1;
|
285
|
+
}
|
286
|
+
|
287
|
+
|
288
|
+
/*********************************************
|
289
|
+
STATIC: ConnectionDescriptor::CloseConnection
|
290
|
+
*********************************************/
|
291
|
+
|
292
|
+
void ConnectionDescriptor::CloseConnection (const char *binding, bool after_writing)
|
293
|
+
{
|
294
|
+
// TODO: This is something of a hack, or at least it's a static method of the wrong class.
|
295
|
+
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
|
296
|
+
if (ed)
|
297
|
+
ed->ScheduleClose (after_writing);
|
298
|
+
}
|
299
|
+
|
300
|
+
/***********************************************
|
301
|
+
STATIC: ConnectionDescriptor::ReportErrorStatus
|
302
|
+
***********************************************/
|
303
|
+
|
304
|
+
int ConnectionDescriptor::ReportErrorStatus (const char *binding)
|
305
|
+
{
|
306
|
+
// TODO: This is something of a hack, or at least it's a static method of the wrong class.
|
307
|
+
// TODO: Poor polymorphism here. We should be calling one virtual method
|
308
|
+
// instead of hacking out the runtime information of the target object.
|
309
|
+
ConnectionDescriptor *cd = dynamic_cast <ConnectionDescriptor*> (Bindable_t::GetObject (binding));
|
310
|
+
if (cd)
|
311
|
+
return cd->_ReportErrorStatus();
|
312
|
+
return -1;
|
313
|
+
}
|
314
|
+
|
315
|
+
/***************************************
|
316
|
+
ConnectionDescriptor::SetConnectPending
|
317
|
+
****************************************/
|
318
|
+
|
319
|
+
void ConnectionDescriptor::SetConnectPending(bool f)
|
320
|
+
{
|
321
|
+
bConnectPending = f;
|
322
|
+
|
323
|
+
if (bConnectPending) { // not yet connected, select for writability
|
324
|
+
#ifdef HAVE_EPOLL
|
325
|
+
EpollEvent.events = EPOLLOUT;
|
326
|
+
#endif
|
327
|
+
#ifdef HAVE_KQUEUE
|
328
|
+
MyEventMachine->ArmKqueueWriter (this);
|
329
|
+
#endif
|
330
|
+
} else { // connected, wait for incoming data and write out any pending outgoing data
|
331
|
+
#ifdef HAVE_EPOLL
|
332
|
+
EpollEvent.events = EPOLLIN | (SelectForWrite() ? EPOLLOUT : 0);
|
333
|
+
#endif
|
334
|
+
#ifdef HAVE_KQUEUE
|
335
|
+
MyEventMachine->ArmKqueueReader (this);
|
336
|
+
if (SelectForWrite())
|
337
|
+
MyEventMachine->ArmKqueueWriter (this);
|
338
|
+
#endif
|
339
|
+
}
|
340
|
+
}
|
341
|
+
|
342
|
+
|
343
|
+
/***************************************
|
344
|
+
ConnectionDescriptor::SetNotifyReadable
|
345
|
+
****************************************/
|
346
|
+
|
347
|
+
void ConnectionDescriptor::SetNotifyReadable(bool readable)
|
348
|
+
{
|
349
|
+
bNotifyReadable = readable;
|
350
|
+
if (bNotifyReadable) {
|
351
|
+
#ifdef HAVE_EPOLL
|
352
|
+
EpollEvent.events |= EPOLLIN;
|
353
|
+
#endif
|
354
|
+
#ifdef HAVE_KQUEUE
|
355
|
+
MyEventMachine->ArmKqueueReader (this);
|
356
|
+
#endif
|
357
|
+
}
|
358
|
+
}
|
359
|
+
|
360
|
+
|
361
|
+
/***************************************
|
362
|
+
ConnectionDescriptor::SetNotifyWritable
|
363
|
+
****************************************/
|
364
|
+
|
365
|
+
void ConnectionDescriptor::SetNotifyWritable(bool writable)
|
366
|
+
{
|
367
|
+
bNotifyWritable = writable;
|
368
|
+
if (bNotifyWritable) {
|
369
|
+
#ifdef HAVE_EPOLL
|
370
|
+
EpollEvent.events |= EPOLLOUT;
|
371
|
+
#endif
|
372
|
+
#ifdef HAVE_KQUEUE
|
373
|
+
MyEventMachine->ArmKqueueWriter (this);
|
374
|
+
#endif
|
375
|
+
}
|
376
|
+
}
|
377
|
+
|
378
|
+
|
379
|
+
/**************************************
|
380
|
+
ConnectionDescriptor::SendOutboundData
|
381
|
+
**************************************/
|
382
|
+
|
383
|
+
int ConnectionDescriptor::SendOutboundData (const char *data, int length)
|
384
|
+
{
|
385
|
+
#ifdef WITH_SSL
|
386
|
+
if (SslBox) {
|
387
|
+
if (length > 0) {
|
388
|
+
int w = SslBox->PutPlaintext (data, length);
|
389
|
+
if (w < 0)
|
390
|
+
ScheduleClose (false);
|
391
|
+
else
|
392
|
+
_DispatchCiphertext();
|
393
|
+
}
|
394
|
+
// TODO: What's the correct return value?
|
395
|
+
return 1; // That's a wild guess, almost certainly wrong.
|
396
|
+
}
|
397
|
+
else
|
398
|
+
#endif
|
399
|
+
return _SendRawOutboundData (data, length);
|
400
|
+
}
|
401
|
+
|
402
|
+
|
403
|
+
|
404
|
+
/******************************************
|
405
|
+
ConnectionDescriptor::_SendRawOutboundData
|
406
|
+
******************************************/
|
407
|
+
|
408
|
+
int ConnectionDescriptor::_SendRawOutboundData (const char *data, int length)
|
409
|
+
{
|
410
|
+
/* This internal method is called to schedule bytes that
|
411
|
+
* will be sent out to the remote peer.
|
412
|
+
* It's not directly accessed by the caller, who hits ::SendOutboundData,
|
413
|
+
* which may or may not filter or encrypt the caller's data before
|
414
|
+
* sending it here.
|
415
|
+
*/
|
416
|
+
|
417
|
+
// Highly naive and incomplete implementation.
|
418
|
+
// There's no throttle for runaways (which should abort only this connection
|
419
|
+
// and not the whole process), and no coalescing of small pages.
|
420
|
+
// (Well, not so bad, small pages are coalesced in ::Write)
|
421
|
+
|
422
|
+
if (IsCloseScheduled())
|
423
|
+
//if (bCloseNow || bCloseAfterWriting)
|
424
|
+
return 0;
|
425
|
+
|
426
|
+
if (!data && (length > 0))
|
427
|
+
throw std::runtime_error ("bad outbound data");
|
428
|
+
char *buffer = (char *) malloc (length + 1);
|
429
|
+
if (!buffer)
|
430
|
+
throw std::runtime_error ("no allocation for outbound data");
|
431
|
+
|
432
|
+
memcpy (buffer, data, length);
|
433
|
+
buffer [length] = 0;
|
434
|
+
OutboundPages.push_back (OutboundPage (buffer, length));
|
435
|
+
OutboundDataSize += length;
|
436
|
+
|
437
|
+
#ifdef HAVE_EPOLL
|
438
|
+
EpollEvent.events = (EPOLLIN | EPOLLOUT);
|
439
|
+
assert (MyEventMachine);
|
440
|
+
MyEventMachine->Modify (this);
|
441
|
+
#endif
|
442
|
+
#ifdef HAVE_KQUEUE
|
443
|
+
MyEventMachine->ArmKqueueWriter (this);
|
444
|
+
#endif
|
445
|
+
|
446
|
+
return length;
|
447
|
+
}
|
448
|
+
|
449
|
+
|
450
|
+
|
451
|
+
/***********************************
|
452
|
+
ConnectionDescriptor::SelectForRead
|
453
|
+
***********************************/
|
454
|
+
|
455
|
+
bool ConnectionDescriptor::SelectForRead()
|
456
|
+
{
|
457
|
+
/* A connection descriptor is always scheduled for read,
|
458
|
+
* UNLESS it's in a pending-connect state.
|
459
|
+
* On Linux, unlike Unix, a nonblocking socket on which
|
460
|
+
* connect has been called, does NOT necessarily select
|
461
|
+
* both readable and writable in case of error.
|
462
|
+
* The socket will select writable when the disposition
|
463
|
+
* of the connect is known. On the other hand, a socket
|
464
|
+
* which successfully connects and selects writable may
|
465
|
+
* indeed have some data available on it, so it will
|
466
|
+
* select readable in that case, violating expectations!
|
467
|
+
* So we will not poll for readability until the socket
|
468
|
+
* is known to be in a connected state.
|
469
|
+
*/
|
470
|
+
|
471
|
+
return bConnectPending ? false : true;
|
472
|
+
}
|
473
|
+
|
474
|
+
|
475
|
+
/************************************
|
476
|
+
ConnectionDescriptor::SelectForWrite
|
477
|
+
************************************/
|
478
|
+
|
479
|
+
bool ConnectionDescriptor::SelectForWrite()
|
480
|
+
{
|
481
|
+
/* Cf the notes under SelectForRead.
|
482
|
+
* In a pending-connect state, we ALWAYS select for writable.
|
483
|
+
* In a normal state, we only select for writable when we
|
484
|
+
* have outgoing data to send.
|
485
|
+
*/
|
486
|
+
|
487
|
+
if (bConnectPending || bNotifyWritable)
|
488
|
+
return true;
|
489
|
+
else {
|
490
|
+
return (GetOutboundDataSize() > 0);
|
491
|
+
}
|
492
|
+
}
|
493
|
+
|
494
|
+
|
495
|
+
/**************************
|
496
|
+
ConnectionDescriptor::Read
|
497
|
+
**************************/
|
498
|
+
|
499
|
+
void ConnectionDescriptor::Read()
|
500
|
+
{
|
501
|
+
/* Read and dispatch data on a socket that has selected readable.
|
502
|
+
* It's theoretically possible to get and dispatch incoming data on
|
503
|
+
* a socket that has already been scheduled for closing or close-after-writing.
|
504
|
+
* In those cases, we'll leave it up the to protocol handler to "do the
|
505
|
+
* right thing" (which probably means to ignore the incoming data).
|
506
|
+
*
|
507
|
+
* 22Aug06: Chris Ochs reports that on FreeBSD, it's possible to come
|
508
|
+
* here with the socket already closed, after the process receives
|
509
|
+
* a ctrl-C signal (not sure if that's TERM or INT on BSD). The application
|
510
|
+
* was one in which network connections were doing a lot of interleaved reads
|
511
|
+
* and writes.
|
512
|
+
* Since we always write before reading (in order to keep the outbound queues
|
513
|
+
* as light as possible), I think what happened is that an interrupt caused
|
514
|
+
* the socket to be closed in ConnectionDescriptor::Write. We'll then
|
515
|
+
* come here in the same pass through the main event loop, and won't get
|
516
|
+
* cleaned up until immediately after.
|
517
|
+
* We originally asserted that the socket was valid when we got here.
|
518
|
+
* To deal properly with the possibility that we are closed when we get here,
|
519
|
+
* I removed the assert. HOWEVER, the potential for an infinite loop scares me,
|
520
|
+
* so even though this is really clunky, I added a flag to assert that we never
|
521
|
+
* come here more than once after being closed. (FCianfrocca)
|
522
|
+
*/
|
523
|
+
|
524
|
+
int sd = GetSocket();
|
525
|
+
//assert (sd != INVALID_SOCKET); (original, removed 22Aug06)
|
526
|
+
if (sd == INVALID_SOCKET) {
|
527
|
+
assert (!bReadAttemptedAfterClose);
|
528
|
+
bReadAttemptedAfterClose = true;
|
529
|
+
return;
|
530
|
+
}
|
531
|
+
|
532
|
+
if (bNotifyReadable) {
|
533
|
+
if (EventCallback)
|
534
|
+
(*EventCallback)(GetBinding().c_str(), EM_CONNECTION_NOTIFY_READABLE, NULL, 0);
|
535
|
+
return;
|
536
|
+
}
|
537
|
+
|
538
|
+
LastIo = gCurrentLoopTime;
|
539
|
+
|
540
|
+
int total_bytes_read = 0;
|
541
|
+
char readbuffer [16 * 1024 + 1];
|
542
|
+
|
543
|
+
for (int i=0; i < 10; i++) {
|
544
|
+
// Don't read just one buffer and then move on. This is faster
|
545
|
+
// if there is a lot of incoming.
|
546
|
+
// But don't read indefinitely. Give other sockets a chance to run.
|
547
|
+
// NOTICE, we're reading one less than the buffer size.
|
548
|
+
// That's so we can put a guard byte at the end of what we send
|
549
|
+
// to user code.
|
550
|
+
|
551
|
+
|
552
|
+
int r = read (sd, readbuffer, sizeof(readbuffer) - 1);
|
553
|
+
//cerr << "<R:" << r << ">";
|
554
|
+
|
555
|
+
if (r > 0) {
|
556
|
+
total_bytes_read += r;
|
557
|
+
|
558
|
+
// Add a null-terminator at the the end of the buffer
|
559
|
+
// that we will send to the callback.
|
560
|
+
// DO NOT EVER CHANGE THIS. We want to explicitly allow users
|
561
|
+
// to be able to depend on this behavior, so they will have
|
562
|
+
// the option to do some things faster. Additionally it's
|
563
|
+
// a security guard against buffer overflows.
|
564
|
+
readbuffer [r] = 0;
|
565
|
+
_DispatchInboundData (readbuffer, r);
|
566
|
+
}
|
567
|
+
else if (r == 0) {
|
568
|
+
break;
|
569
|
+
}
|
570
|
+
else {
|
571
|
+
// Basically a would-block, meaning we've read everything there is to read.
|
572
|
+
break;
|
573
|
+
}
|
574
|
+
|
575
|
+
}
|
576
|
+
|
577
|
+
|
578
|
+
if (total_bytes_read == 0) {
|
579
|
+
// If we read no data on a socket that selected readable,
|
580
|
+
// it generally means the other end closed the connection gracefully.
|
581
|
+
ScheduleClose (false);
|
582
|
+
//bCloseNow = true;
|
583
|
+
}
|
584
|
+
|
585
|
+
}
|
586
|
+
|
587
|
+
|
588
|
+
|
589
|
+
/******************************************
|
590
|
+
ConnectionDescriptor::_DispatchInboundData
|
591
|
+
******************************************/
|
592
|
+
|
593
|
+
void ConnectionDescriptor::_DispatchInboundData (const char *buffer, int size)
|
594
|
+
{
|
595
|
+
#ifdef WITH_SSL
|
596
|
+
if (SslBox) {
|
597
|
+
SslBox->PutCiphertext (buffer, size);
|
598
|
+
|
599
|
+
int s;
|
600
|
+
char B [2048];
|
601
|
+
while ((s = SslBox->GetPlaintext (B, sizeof(B) - 1)) > 0) {
|
602
|
+
_CheckHandshakeStatus();
|
603
|
+
B [s] = 0;
|
604
|
+
_GenericInboundDispatch(B, s);
|
605
|
+
}
|
606
|
+
|
607
|
+
// If our SSL handshake had a problem, shut down the connection.
|
608
|
+
if (s == -2) {
|
609
|
+
ScheduleClose(false);
|
610
|
+
return;
|
611
|
+
}
|
612
|
+
|
613
|
+
_CheckHandshakeStatus();
|
614
|
+
_DispatchCiphertext();
|
615
|
+
}
|
616
|
+
else {
|
617
|
+
_GenericInboundDispatch(buffer, size);
|
618
|
+
}
|
619
|
+
#endif
|
620
|
+
|
621
|
+
#ifdef WITHOUT_SSL
|
622
|
+
_GenericInboundDispatch(buffer, size);
|
623
|
+
#endif
|
624
|
+
}
|
625
|
+
|
626
|
+
|
627
|
+
|
628
|
+
/*******************************************
|
629
|
+
ConnectionDescriptor::_CheckHandshakeStatus
|
630
|
+
*******************************************/
|
631
|
+
|
632
|
+
void ConnectionDescriptor::_CheckHandshakeStatus()
|
633
|
+
{
|
634
|
+
#ifdef WITH_SSL
|
635
|
+
if (SslBox && (!bHandshakeSignaled) && SslBox->IsHandshakeCompleted()) {
|
636
|
+
bHandshakeSignaled = true;
|
637
|
+
if (EventCallback)
|
638
|
+
(*EventCallback)(GetBinding().c_str(), EM_SSL_HANDSHAKE_COMPLETED, NULL, 0);
|
639
|
+
}
|
640
|
+
#endif
|
641
|
+
}
|
642
|
+
|
643
|
+
|
644
|
+
|
645
|
+
/***************************
|
646
|
+
ConnectionDescriptor::Write
|
647
|
+
***************************/
|
648
|
+
|
649
|
+
void ConnectionDescriptor::Write()
|
650
|
+
{
|
651
|
+
/* A socket which is in a pending-connect state will select
|
652
|
+
* writable when the disposition of the connect is known.
|
653
|
+
* At that point, check to be sure there are no errors,
|
654
|
+
* and if none, then promote the socket out of the pending
|
655
|
+
* state.
|
656
|
+
* TODO: I haven't figured out how Windows signals errors on
|
657
|
+
* unconnected sockets. Maybe it does the untraditional but
|
658
|
+
* logical thing and makes the socket selectable for error.
|
659
|
+
* If so, it's unsupported here for the time being, and connect
|
660
|
+
* errors will have to be caught by the timeout mechanism.
|
661
|
+
*/
|
662
|
+
|
663
|
+
if (bConnectPending) {
|
664
|
+
int error;
|
665
|
+
socklen_t len;
|
666
|
+
len = sizeof(error);
|
667
|
+
#ifdef OS_UNIX
|
668
|
+
int o = getsockopt (GetSocket(), SOL_SOCKET, SO_ERROR, &error, &len);
|
669
|
+
#endif
|
670
|
+
#ifdef OS_WIN32
|
671
|
+
int o = getsockopt (GetSocket(), SOL_SOCKET, SO_ERROR, (char*)&error, &len);
|
672
|
+
#endif
|
673
|
+
if ((o == 0) && (error == 0)) {
|
674
|
+
if (EventCallback)
|
675
|
+
(*EventCallback)(GetBinding().c_str(), EM_CONNECTION_COMPLETED, "", 0);
|
676
|
+
|
677
|
+
// 5May09: Moved epoll/kqueue read/write arming into SetConnectPending, so it can be called
|
678
|
+
// from EventMachine_t::AttachFD as well.
|
679
|
+
SetConnectPending (false);
|
680
|
+
}
|
681
|
+
else
|
682
|
+
ScheduleClose (false);
|
683
|
+
//bCloseNow = true;
|
684
|
+
}
|
685
|
+
else {
|
686
|
+
|
687
|
+
if (bNotifyWritable) {
|
688
|
+
if (EventCallback)
|
689
|
+
(*EventCallback)(GetBinding().c_str(), EM_CONNECTION_NOTIFY_WRITABLE, NULL, 0);
|
690
|
+
return;
|
691
|
+
}
|
692
|
+
|
693
|
+
/* 5May09: Kqueue bugs on OSX cause one extra writable event to fire even though we're using
|
694
|
+
EV_ONESHOT. We ignore this extra event once, but only the first time. If it happens again,
|
695
|
+
we should fall through to the assert(nbytes>0) failure to catch any EM bugs which might cause
|
696
|
+
::Write to be called in a busy-loop.
|
697
|
+
*/
|
698
|
+
#ifdef HAVE_KQUEUE
|
699
|
+
if (MyEventMachine->UsingKqueue()) {
|
700
|
+
if (OutboundDataSize == 0 && !bGotExtraKqueueEvent) {
|
701
|
+
bGotExtraKqueueEvent = true;
|
702
|
+
return;
|
703
|
+
} else if (OutboundDataSize > 0) {
|
704
|
+
bGotExtraKqueueEvent = false;
|
705
|
+
}
|
706
|
+
}
|
707
|
+
#endif
|
708
|
+
|
709
|
+
_WriteOutboundData();
|
710
|
+
}
|
711
|
+
}
|
712
|
+
|
713
|
+
|
714
|
+
/****************************************
|
715
|
+
ConnectionDescriptor::_WriteOutboundData
|
716
|
+
****************************************/
|
717
|
+
|
718
|
+
void ConnectionDescriptor::_WriteOutboundData()
|
719
|
+
{
|
720
|
+
/* This is a helper function called by ::Write.
|
721
|
+
* It's possible for a socket to select writable and then no longer
|
722
|
+
* be writable by the time we get around to writing. The kernel might
|
723
|
+
* have used up its available output buffers between the select call
|
724
|
+
* and when we get here. So this condition is not an error.
|
725
|
+
*
|
726
|
+
* 20Jul07, added the same kind of protection against an invalid socket
|
727
|
+
* that is at the top of ::Read. Not entirely how this could happen in
|
728
|
+
* real life (connection-reset from the remote peer, perhaps?), but I'm
|
729
|
+
* doing it to address some reports of crashing under heavy loads.
|
730
|
+
*/
|
731
|
+
|
732
|
+
int sd = GetSocket();
|
733
|
+
//assert (sd != INVALID_SOCKET);
|
734
|
+
if (sd == INVALID_SOCKET) {
|
735
|
+
assert (!bWriteAttemptedAfterClose);
|
736
|
+
bWriteAttemptedAfterClose = true;
|
737
|
+
return;
|
738
|
+
}
|
739
|
+
|
740
|
+
LastIo = gCurrentLoopTime;
|
741
|
+
size_t nbytes = 0;
|
742
|
+
|
743
|
+
#ifdef HAVE_WRITEV
|
744
|
+
int iovcnt = OutboundPages.size();
|
745
|
+
// Max of 16 outbound pages at a time
|
746
|
+
if (iovcnt > 16) iovcnt = 16;
|
747
|
+
|
748
|
+
struct iovec iov[ iovcnt ];
|
749
|
+
|
750
|
+
for(int i = 0; i < iovcnt; i++){
|
751
|
+
OutboundPage *op = &(OutboundPages[i]);
|
752
|
+
iov[i].iov_base = (void *)(op->Buffer + op->Offset);
|
753
|
+
iov[i].iov_len = op->Length - op->Offset;
|
754
|
+
|
755
|
+
nbytes += iov[i].iov_len;
|
756
|
+
}
|
757
|
+
#else
|
758
|
+
char output_buffer [16 * 1024];
|
759
|
+
|
760
|
+
while ((OutboundPages.size() > 0) && (nbytes < sizeof(output_buffer))) {
|
761
|
+
OutboundPage *op = &(OutboundPages[0]);
|
762
|
+
if ((nbytes + op->Length - op->Offset) < sizeof (output_buffer)) {
|
763
|
+
memcpy (output_buffer + nbytes, op->Buffer + op->Offset, op->Length - op->Offset);
|
764
|
+
nbytes += (op->Length - op->Offset);
|
765
|
+
op->Free();
|
766
|
+
OutboundPages.pop_front();
|
767
|
+
}
|
768
|
+
else {
|
769
|
+
int len = sizeof(output_buffer) - nbytes;
|
770
|
+
memcpy (output_buffer + nbytes, op->Buffer + op->Offset, len);
|
771
|
+
op->Offset += len;
|
772
|
+
nbytes += len;
|
773
|
+
}
|
774
|
+
}
|
775
|
+
#endif
|
776
|
+
|
777
|
+
// We should never have gotten here if there were no data to write,
|
778
|
+
// so assert that as a sanity check.
|
779
|
+
// Don't bother to make sure nbytes is less than output_buffer because
|
780
|
+
// if it were we probably would have crashed already.
|
781
|
+
assert (nbytes > 0);
|
782
|
+
|
783
|
+
assert (GetSocket() != INVALID_SOCKET);
|
784
|
+
#ifdef HAVE_WRITEV
|
785
|
+
int bytes_written = writev (GetSocket(), iov, iovcnt);
|
786
|
+
#else
|
787
|
+
int bytes_written = write (GetSocket(), output_buffer, nbytes);
|
788
|
+
#endif
|
789
|
+
|
790
|
+
bool err = false;
|
791
|
+
if (bytes_written < 0) {
|
792
|
+
err = true;
|
793
|
+
bytes_written = 0;
|
794
|
+
}
|
795
|
+
|
796
|
+
assert (bytes_written >= 0);
|
797
|
+
OutboundDataSize -= bytes_written;
|
798
|
+
|
799
|
+
#ifdef HAVE_WRITEV
|
800
|
+
if (!err) {
|
801
|
+
int sent = bytes_written;
|
802
|
+
deque<OutboundPage>::iterator op = OutboundPages.begin();
|
803
|
+
|
804
|
+
for (int i = 0; i < iovcnt; i++) {
|
805
|
+
if (iov[i].iov_len <= sent) {
|
806
|
+
// Sent this page in full, free it.
|
807
|
+
op->Free();
|
808
|
+
OutboundPages.pop_front();
|
809
|
+
|
810
|
+
sent -= iov[i].iov_len;
|
811
|
+
} else {
|
812
|
+
// Sent part (or none) of this page, increment offset to send the remainder
|
813
|
+
op->Offset += sent;
|
814
|
+
break;
|
815
|
+
}
|
816
|
+
|
817
|
+
// Shouldn't be possible run out of pages before the loop ends
|
818
|
+
assert(op != OutboundPages.end());
|
819
|
+
*op++;
|
820
|
+
}
|
821
|
+
}
|
822
|
+
#else
|
823
|
+
if ((size_t)bytes_written < nbytes) {
|
824
|
+
int len = nbytes - bytes_written;
|
825
|
+
char *buffer = (char*) malloc (len + 1);
|
826
|
+
if (!buffer)
|
827
|
+
throw std::runtime_error ("bad alloc throwing back data");
|
828
|
+
memcpy (buffer, output_buffer + bytes_written, len);
|
829
|
+
buffer [len] = 0;
|
830
|
+
OutboundPages.push_front (OutboundPage (buffer, len));
|
831
|
+
}
|
832
|
+
#endif
|
833
|
+
|
834
|
+
#ifdef HAVE_EPOLL
|
835
|
+
EpollEvent.events = (EPOLLIN | (SelectForWrite() ? EPOLLOUT : 0));
|
836
|
+
assert (MyEventMachine);
|
837
|
+
MyEventMachine->Modify (this);
|
838
|
+
#endif
|
839
|
+
#ifdef HAVE_KQUEUE
|
840
|
+
if (SelectForWrite())
|
841
|
+
MyEventMachine->ArmKqueueWriter (this);
|
842
|
+
#endif
|
843
|
+
|
844
|
+
|
845
|
+
if (err) {
|
846
|
+
#ifdef OS_UNIX
|
847
|
+
if ((errno != EINPROGRESS) && (errno != EWOULDBLOCK) && (errno != EINTR))
|
848
|
+
#endif
|
849
|
+
#ifdef OS_WIN32
|
850
|
+
if ((errno != WSAEINPROGRESS) && (errno != WSAEWOULDBLOCK))
|
851
|
+
#endif
|
852
|
+
Close();
|
853
|
+
}
|
854
|
+
}
|
855
|
+
|
856
|
+
|
857
|
+
/****************************************
|
858
|
+
ConnectionDescriptor::_ReportErrorStatus
|
859
|
+
****************************************/
|
860
|
+
|
861
|
+
int ConnectionDescriptor::_ReportErrorStatus()
|
862
|
+
{
|
863
|
+
int error;
|
864
|
+
socklen_t len;
|
865
|
+
len = sizeof(error);
|
866
|
+
#ifdef OS_UNIX
|
867
|
+
int o = getsockopt (GetSocket(), SOL_SOCKET, SO_ERROR, &error, &len);
|
868
|
+
#endif
|
869
|
+
#ifdef OS_WIN32
|
870
|
+
int o = getsockopt (GetSocket(), SOL_SOCKET, SO_ERROR, (char*)&error, &len);
|
871
|
+
#endif
|
872
|
+
if ((o == 0) && (error == 0))
|
873
|
+
return 0;
|
874
|
+
else
|
875
|
+
return 1;
|
876
|
+
}
|
877
|
+
|
878
|
+
|
879
|
+
/******************************
|
880
|
+
ConnectionDescriptor::StartTls
|
881
|
+
******************************/
|
882
|
+
|
883
|
+
void ConnectionDescriptor::StartTls()
|
884
|
+
{
|
885
|
+
#ifdef WITH_SSL
|
886
|
+
if (SslBox)
|
887
|
+
throw std::runtime_error ("SSL/TLS already running on connection");
|
888
|
+
|
889
|
+
SslBox = new SslBox_t (bIsServer, PrivateKeyFilename, CertChainFilename, bSslVerifyPeer, GetBinding().c_str());
|
890
|
+
_DispatchCiphertext();
|
891
|
+
#endif
|
892
|
+
|
893
|
+
#ifdef WITHOUT_SSL
|
894
|
+
throw std::runtime_error ("Encryption not available on this event-machine");
|
895
|
+
#endif
|
896
|
+
}
|
897
|
+
|
898
|
+
|
899
|
+
/*********************************
|
900
|
+
ConnectionDescriptor::SetTlsParms
|
901
|
+
*********************************/
|
902
|
+
|
903
|
+
void ConnectionDescriptor::SetTlsParms (const char *privkey_filename, const char *certchain_filename, bool verify_peer)
|
904
|
+
{
|
905
|
+
#ifdef WITH_SSL
|
906
|
+
if (SslBox)
|
907
|
+
throw std::runtime_error ("call SetTlsParms before calling StartTls");
|
908
|
+
if (privkey_filename && *privkey_filename)
|
909
|
+
PrivateKeyFilename = privkey_filename;
|
910
|
+
if (certchain_filename && *certchain_filename)
|
911
|
+
CertChainFilename = certchain_filename;
|
912
|
+
bSslVerifyPeer = verify_peer;
|
913
|
+
#endif
|
914
|
+
|
915
|
+
#ifdef WITHOUT_SSL
|
916
|
+
throw std::runtime_error ("Encryption not available on this event-machine");
|
917
|
+
#endif
|
918
|
+
}
|
919
|
+
|
920
|
+
|
921
|
+
/*********************************
|
922
|
+
ConnectionDescriptor::GetPeerCert
|
923
|
+
*********************************/
|
924
|
+
|
925
|
+
#ifdef WITH_SSL
|
926
|
+
X509 *ConnectionDescriptor::GetPeerCert()
|
927
|
+
{
|
928
|
+
if (!SslBox)
|
929
|
+
throw std::runtime_error ("SSL/TLS not running on this connection");
|
930
|
+
return SslBox->GetPeerCert();
|
931
|
+
}
|
932
|
+
#endif
|
933
|
+
|
934
|
+
|
935
|
+
/***********************************
|
936
|
+
ConnectionDescriptor::VerifySslPeer
|
937
|
+
***********************************/
|
938
|
+
|
939
|
+
#ifdef WITH_SSL
|
940
|
+
bool ConnectionDescriptor::VerifySslPeer(const char *cert)
|
941
|
+
{
|
942
|
+
bSslPeerAccepted = false;
|
943
|
+
|
944
|
+
if (EventCallback)
|
945
|
+
(*EventCallback)(GetBinding().c_str(), EM_SSL_VERIFY, cert, strlen(cert));
|
946
|
+
|
947
|
+
return bSslPeerAccepted;
|
948
|
+
}
|
949
|
+
#endif
|
950
|
+
|
951
|
+
|
952
|
+
/***********************************
|
953
|
+
ConnectionDescriptor::AcceptSslPeer
|
954
|
+
***********************************/
|
955
|
+
|
956
|
+
#ifdef WITH_SSL
|
957
|
+
void ConnectionDescriptor::AcceptSslPeer()
|
958
|
+
{
|
959
|
+
bSslPeerAccepted = true;
|
960
|
+
}
|
961
|
+
#endif
|
962
|
+
|
963
|
+
|
964
|
+
/*****************************************
|
965
|
+
ConnectionDescriptor::_DispatchCiphertext
|
966
|
+
*****************************************/
|
967
|
+
|
968
|
+
#ifdef WITH_SSL
|
969
|
+
void ConnectionDescriptor::_DispatchCiphertext()
|
970
|
+
{
|
971
|
+
assert (SslBox);
|
972
|
+
|
973
|
+
|
974
|
+
char BigBuf [2048];
|
975
|
+
bool did_work;
|
976
|
+
|
977
|
+
do {
|
978
|
+
did_work = false;
|
979
|
+
|
980
|
+
// try to drain ciphertext
|
981
|
+
while (SslBox->CanGetCiphertext()) {
|
982
|
+
int r = SslBox->GetCiphertext (BigBuf, sizeof(BigBuf));
|
983
|
+
assert (r > 0);
|
984
|
+
_SendRawOutboundData (BigBuf, r);
|
985
|
+
did_work = true;
|
986
|
+
}
|
987
|
+
|
988
|
+
// Pump the SslBox, in case it has queued outgoing plaintext
|
989
|
+
// This will return >0 if data was written,
|
990
|
+
// 0 if no data was written, and <0 if there was a fatal error.
|
991
|
+
bool pump;
|
992
|
+
do {
|
993
|
+
pump = false;
|
994
|
+
int w = SslBox->PutPlaintext (NULL, 0);
|
995
|
+
if (w > 0) {
|
996
|
+
did_work = true;
|
997
|
+
pump = true;
|
998
|
+
}
|
999
|
+
else if (w < 0)
|
1000
|
+
ScheduleClose (false);
|
1001
|
+
} while (pump);
|
1002
|
+
|
1003
|
+
// try to put plaintext. INCOMPLETE, doesn't belong here?
|
1004
|
+
// In SendOutboundData, we're spooling plaintext directly
|
1005
|
+
// into SslBox. That may be wrong, we may need to buffer it
|
1006
|
+
// up here!
|
1007
|
+
/*
|
1008
|
+
const char *ptr;
|
1009
|
+
int ptr_length;
|
1010
|
+
while (OutboundPlaintext.GetPage (&ptr, &ptr_length)) {
|
1011
|
+
assert (ptr && (ptr_length > 0));
|
1012
|
+
int w = SslMachine.PutPlaintext (ptr, ptr_length);
|
1013
|
+
if (w > 0) {
|
1014
|
+
OutboundPlaintext.DiscardBytes (w);
|
1015
|
+
did_work = true;
|
1016
|
+
}
|
1017
|
+
else
|
1018
|
+
break;
|
1019
|
+
}
|
1020
|
+
*/
|
1021
|
+
|
1022
|
+
} while (did_work);
|
1023
|
+
|
1024
|
+
}
|
1025
|
+
#endif
|
1026
|
+
|
1027
|
+
|
1028
|
+
|
1029
|
+
/*******************************
|
1030
|
+
ConnectionDescriptor::Heartbeat
|
1031
|
+
*******************************/
|
1032
|
+
|
1033
|
+
void ConnectionDescriptor::Heartbeat()
|
1034
|
+
{
|
1035
|
+
/* Only allow a certain amount of time to go by while waiting
|
1036
|
+
* for a pending connect. If it expires, then kill the socket.
|
1037
|
+
* For a connected socket, close it if its inactivity timer
|
1038
|
+
* has expired.
|
1039
|
+
*/
|
1040
|
+
|
1041
|
+
if (bConnectPending) {
|
1042
|
+
if ((gCurrentLoopTime - CreatedAt) >= PendingConnectTimeout)
|
1043
|
+
ScheduleClose (false);
|
1044
|
+
//bCloseNow = true;
|
1045
|
+
}
|
1046
|
+
else {
|
1047
|
+
if (InactivityTimeout && ((gCurrentLoopTime - LastIo) >= InactivityTimeout))
|
1048
|
+
ScheduleClose (false);
|
1049
|
+
//bCloseNow = true;
|
1050
|
+
}
|
1051
|
+
}
|
1052
|
+
|
1053
|
+
|
1054
|
+
/****************************************
|
1055
|
+
LoopbreakDescriptor::LoopbreakDescriptor
|
1056
|
+
****************************************/
|
1057
|
+
|
1058
|
+
LoopbreakDescriptor::LoopbreakDescriptor (int sd, EventMachine_t *parent_em):
|
1059
|
+
EventableDescriptor (sd, parent_em)
|
1060
|
+
{
|
1061
|
+
/* This is really bad and ugly. Change someday if possible.
|
1062
|
+
* We have to know about an event-machine (probably the one that owns us),
|
1063
|
+
* so we can pass newly-created connections to it.
|
1064
|
+
*/
|
1065
|
+
|
1066
|
+
bCallbackUnbind = false;
|
1067
|
+
|
1068
|
+
#ifdef HAVE_EPOLL
|
1069
|
+
EpollEvent.events = EPOLLIN;
|
1070
|
+
#endif
|
1071
|
+
#ifdef HAVE_KQUEUE
|
1072
|
+
MyEventMachine->ArmKqueueReader (this);
|
1073
|
+
#endif
|
1074
|
+
}
|
1075
|
+
|
1076
|
+
|
1077
|
+
|
1078
|
+
|
1079
|
+
/*************************
|
1080
|
+
LoopbreakDescriptor::Read
|
1081
|
+
*************************/
|
1082
|
+
|
1083
|
+
void LoopbreakDescriptor::Read()
|
1084
|
+
{
|
1085
|
+
// TODO, refactor, this code is probably in the wrong place.
|
1086
|
+
assert (MyEventMachine);
|
1087
|
+
MyEventMachine->_ReadLoopBreaker();
|
1088
|
+
}
|
1089
|
+
|
1090
|
+
|
1091
|
+
/**************************
|
1092
|
+
LoopbreakDescriptor::Write
|
1093
|
+
**************************/
|
1094
|
+
|
1095
|
+
void LoopbreakDescriptor::Write()
|
1096
|
+
{
|
1097
|
+
// Why are we here?
|
1098
|
+
throw std::runtime_error ("bad code path in loopbreak");
|
1099
|
+
}
|
1100
|
+
|
1101
|
+
/**************************************
|
1102
|
+
AcceptorDescriptor::AcceptorDescriptor
|
1103
|
+
**************************************/
|
1104
|
+
|
1105
|
+
AcceptorDescriptor::AcceptorDescriptor (int sd, EventMachine_t *parent_em):
|
1106
|
+
EventableDescriptor (sd, parent_em)
|
1107
|
+
{
|
1108
|
+
#ifdef HAVE_EPOLL
|
1109
|
+
EpollEvent.events = EPOLLIN;
|
1110
|
+
#endif
|
1111
|
+
#ifdef HAVE_KQUEUE
|
1112
|
+
MyEventMachine->ArmKqueueReader (this);
|
1113
|
+
#endif
|
1114
|
+
}
|
1115
|
+
|
1116
|
+
|
1117
|
+
/***************************************
|
1118
|
+
AcceptorDescriptor::~AcceptorDescriptor
|
1119
|
+
***************************************/
|
1120
|
+
|
1121
|
+
AcceptorDescriptor::~AcceptorDescriptor()
|
1122
|
+
{
|
1123
|
+
}
|
1124
|
+
|
1125
|
+
/****************************************
|
1126
|
+
STATIC: AcceptorDescriptor::StopAcceptor
|
1127
|
+
****************************************/
|
1128
|
+
|
1129
|
+
void AcceptorDescriptor::StopAcceptor (const char *binding)
|
1130
|
+
{
|
1131
|
+
// TODO: This is something of a hack, or at least it's a static method of the wrong class.
|
1132
|
+
AcceptorDescriptor *ad = dynamic_cast <AcceptorDescriptor*> (Bindable_t::GetObject (binding));
|
1133
|
+
if (ad)
|
1134
|
+
ad->ScheduleClose (false);
|
1135
|
+
else
|
1136
|
+
throw std::runtime_error ("failed to close nonexistent acceptor");
|
1137
|
+
}
|
1138
|
+
|
1139
|
+
|
1140
|
+
/************************
|
1141
|
+
AcceptorDescriptor::Read
|
1142
|
+
************************/
|
1143
|
+
|
1144
|
+
void AcceptorDescriptor::Read()
|
1145
|
+
{
|
1146
|
+
/* Accept up to a certain number of sockets on the listening connection.
|
1147
|
+
* Don't try to accept all that are present, because this would allow a DoS attack
|
1148
|
+
* in which no data were ever read or written. We should accept more than one,
|
1149
|
+
* if available, to keep the partially accepted sockets from backing up in the kernel.
|
1150
|
+
*/
|
1151
|
+
|
1152
|
+
/* Make sure we use non-blocking i/o on the acceptor socket, since we're selecting it
|
1153
|
+
* for readability. According to Stevens UNP, it's possible for an acceptor to select readable
|
1154
|
+
* and then block when we call accept. For example, the other end resets the connection after
|
1155
|
+
* the socket selects readable and before we call accept. The kernel will remove the dead
|
1156
|
+
* socket from the accept queue. If the accept queue is now empty, accept will block.
|
1157
|
+
*/
|
1158
|
+
|
1159
|
+
|
1160
|
+
struct sockaddr_in pin;
|
1161
|
+
socklen_t addrlen = sizeof (pin);
|
1162
|
+
|
1163
|
+
for (int i=0; i < 10; i++) {
|
1164
|
+
int sd = accept (GetSocket(), (struct sockaddr*)&pin, &addrlen);
|
1165
|
+
if (sd == INVALID_SOCKET) {
|
1166
|
+
// This breaks the loop when we've accepted everything on the kernel queue,
|
1167
|
+
// up to 10 new connections. But what if the *first* accept fails?
|
1168
|
+
// Does that mean anything serious is happening, beyond the situation
|
1169
|
+
// described in the note above?
|
1170
|
+
break;
|
1171
|
+
}
|
1172
|
+
|
1173
|
+
// Set the newly-accepted socket non-blocking.
|
1174
|
+
// On Windows, this may fail because, weirdly, Windows inherits the non-blocking
|
1175
|
+
// attribute that we applied to the acceptor socket into the accepted one.
|
1176
|
+
if (!SetSocketNonblocking (sd)) {
|
1177
|
+
//int val = fcntl (sd, F_GETFL, 0);
|
1178
|
+
//if (fcntl (sd, F_SETFL, val | O_NONBLOCK) == -1) {
|
1179
|
+
shutdown (sd, 1);
|
1180
|
+
closesocket (sd);
|
1181
|
+
continue;
|
1182
|
+
}
|
1183
|
+
|
1184
|
+
|
1185
|
+
// Disable slow-start (Nagle algorithm). Eventually make this configurable.
|
1186
|
+
int one = 1;
|
1187
|
+
setsockopt (sd, IPPROTO_TCP, TCP_NODELAY, (char*) &one, sizeof(one));
|
1188
|
+
|
1189
|
+
|
1190
|
+
ConnectionDescriptor *cd = new ConnectionDescriptor (sd, MyEventMachine);
|
1191
|
+
if (!cd)
|
1192
|
+
throw std::runtime_error ("no newly accepted connection");
|
1193
|
+
cd->SetServerMode();
|
1194
|
+
if (EventCallback) {
|
1195
|
+
(*EventCallback) (GetBinding().c_str(), EM_CONNECTION_ACCEPTED, cd->GetBinding().c_str(), cd->GetBinding().size());
|
1196
|
+
}
|
1197
|
+
#ifdef HAVE_EPOLL
|
1198
|
+
cd->GetEpollEvent()->events = EPOLLIN | (cd->SelectForWrite() ? EPOLLOUT : 0);
|
1199
|
+
#endif
|
1200
|
+
assert (MyEventMachine);
|
1201
|
+
MyEventMachine->Add (cd);
|
1202
|
+
#ifdef HAVE_KQUEUE
|
1203
|
+
if (cd->SelectForWrite())
|
1204
|
+
MyEventMachine->ArmKqueueWriter (cd);
|
1205
|
+
MyEventMachine->ArmKqueueReader (cd);
|
1206
|
+
#endif
|
1207
|
+
}
|
1208
|
+
|
1209
|
+
}
|
1210
|
+
|
1211
|
+
|
1212
|
+
/*************************
|
1213
|
+
AcceptorDescriptor::Write
|
1214
|
+
*************************/
|
1215
|
+
|
1216
|
+
void AcceptorDescriptor::Write()
|
1217
|
+
{
|
1218
|
+
// Why are we here?
|
1219
|
+
throw std::runtime_error ("bad code path in acceptor");
|
1220
|
+
}
|
1221
|
+
|
1222
|
+
|
1223
|
+
/*****************************
|
1224
|
+
AcceptorDescriptor::Heartbeat
|
1225
|
+
*****************************/
|
1226
|
+
|
1227
|
+
void AcceptorDescriptor::Heartbeat()
|
1228
|
+
{
|
1229
|
+
// No-op
|
1230
|
+
}
|
1231
|
+
|
1232
|
+
|
1233
|
+
/*******************************
|
1234
|
+
AcceptorDescriptor::GetSockname
|
1235
|
+
*******************************/
|
1236
|
+
|
1237
|
+
bool AcceptorDescriptor::GetSockname (struct sockaddr *s)
|
1238
|
+
{
|
1239
|
+
bool ok = false;
|
1240
|
+
if (s) {
|
1241
|
+
socklen_t len = sizeof(*s);
|
1242
|
+
int gp = getsockname (GetSocket(), s, &len);
|
1243
|
+
if (gp == 0)
|
1244
|
+
ok = true;
|
1245
|
+
}
|
1246
|
+
return ok;
|
1247
|
+
}
|
1248
|
+
|
1249
|
+
|
1250
|
+
|
1251
|
+
/**************************************
|
1252
|
+
DatagramDescriptor::DatagramDescriptor
|
1253
|
+
**************************************/
|
1254
|
+
|
1255
|
+
DatagramDescriptor::DatagramDescriptor (int sd, EventMachine_t *parent_em):
|
1256
|
+
EventableDescriptor (sd, parent_em),
|
1257
|
+
OutboundDataSize (0),
|
1258
|
+
LastIo (gCurrentLoopTime),
|
1259
|
+
InactivityTimeout (0)
|
1260
|
+
{
|
1261
|
+
memset (&ReturnAddress, 0, sizeof(ReturnAddress));
|
1262
|
+
|
1263
|
+
/* Provisionally added 19Oct07. All datagram sockets support broadcasting.
|
1264
|
+
* Until now, sending to a broadcast address would give EACCES (permission denied)
|
1265
|
+
* on systems like Linux and BSD that require the SO_BROADCAST socket-option in order
|
1266
|
+
* to accept a packet to a broadcast address. Solaris doesn't require it. I think
|
1267
|
+
* Windows DOES require it but I'm not sure.
|
1268
|
+
*
|
1269
|
+
* Ruby does NOT do what we're doing here. In Ruby, you have to explicitly set SO_BROADCAST
|
1270
|
+
* on a UDP socket in order to enable broadcasting. The reason for requiring the option
|
1271
|
+
* in the first place is so that applications don't send broadcast datagrams by mistake.
|
1272
|
+
* I imagine that could happen if a user of an application typed in an address that happened
|
1273
|
+
* to be a broadcast address on that particular subnet.
|
1274
|
+
*
|
1275
|
+
* This is provisional because someone may eventually come up with a good reason not to
|
1276
|
+
* do it for all UDP sockets. If that happens, then we'll need to add a usercode-level API
|
1277
|
+
* to set the socket option, just like Ruby does. AND WE'LL ALSO BREAK CODE THAT DOESN'T
|
1278
|
+
* EXPLICITLY SET THE OPTION.
|
1279
|
+
*/
|
1280
|
+
|
1281
|
+
int oval = 1;
|
1282
|
+
int sob = setsockopt (GetSocket(), SOL_SOCKET, SO_BROADCAST, (char*)&oval, sizeof(oval));
|
1283
|
+
|
1284
|
+
#ifdef HAVE_EPOLL
|
1285
|
+
EpollEvent.events = EPOLLIN;
|
1286
|
+
#endif
|
1287
|
+
#ifdef HAVE_KQUEUE
|
1288
|
+
MyEventMachine->ArmKqueueReader (this);
|
1289
|
+
#endif
|
1290
|
+
}
|
1291
|
+
|
1292
|
+
|
1293
|
+
/***************************************
|
1294
|
+
DatagramDescriptor::~DatagramDescriptor
|
1295
|
+
***************************************/
|
1296
|
+
|
1297
|
+
DatagramDescriptor::~DatagramDescriptor()
|
1298
|
+
{
|
1299
|
+
// Run down any stranded outbound data.
|
1300
|
+
for (size_t i=0; i < OutboundPages.size(); i++)
|
1301
|
+
OutboundPages[i].Free();
|
1302
|
+
}
|
1303
|
+
|
1304
|
+
|
1305
|
+
/*****************************
|
1306
|
+
DatagramDescriptor::Heartbeat
|
1307
|
+
*****************************/
|
1308
|
+
|
1309
|
+
void DatagramDescriptor::Heartbeat()
|
1310
|
+
{
|
1311
|
+
// Close it if its inactivity timer has expired.
|
1312
|
+
|
1313
|
+
if (InactivityTimeout && ((gCurrentLoopTime - LastIo) >= InactivityTimeout))
|
1314
|
+
ScheduleClose (false);
|
1315
|
+
//bCloseNow = true;
|
1316
|
+
}
|
1317
|
+
|
1318
|
+
|
1319
|
+
/************************
|
1320
|
+
DatagramDescriptor::Read
|
1321
|
+
************************/
|
1322
|
+
|
1323
|
+
void DatagramDescriptor::Read()
|
1324
|
+
{
|
1325
|
+
int sd = GetSocket();
|
1326
|
+
assert (sd != INVALID_SOCKET);
|
1327
|
+
LastIo = gCurrentLoopTime;
|
1328
|
+
|
1329
|
+
// This is an extremely large read buffer.
|
1330
|
+
// In many cases you wouldn't expect to get any more than 4K.
|
1331
|
+
char readbuffer [16 * 1024];
|
1332
|
+
|
1333
|
+
for (int i=0; i < 10; i++) {
|
1334
|
+
// Don't read just one buffer and then move on. This is faster
|
1335
|
+
// if there is a lot of incoming.
|
1336
|
+
// But don't read indefinitely. Give other sockets a chance to run.
|
1337
|
+
// NOTICE, we're reading one less than the buffer size.
|
1338
|
+
// That's so we can put a guard byte at the end of what we send
|
1339
|
+
// to user code.
|
1340
|
+
|
1341
|
+
struct sockaddr_in sin;
|
1342
|
+
socklen_t slen = sizeof (sin);
|
1343
|
+
memset (&sin, 0, slen);
|
1344
|
+
|
1345
|
+
int r = recvfrom (sd, readbuffer, sizeof(readbuffer) - 1, 0, (struct sockaddr*)&sin, &slen);
|
1346
|
+
//cerr << "<R:" << r << ">";
|
1347
|
+
|
1348
|
+
// In UDP, a zero-length packet is perfectly legal.
|
1349
|
+
if (r >= 0) {
|
1350
|
+
|
1351
|
+
// Add a null-terminator at the the end of the buffer
|
1352
|
+
// that we will send to the callback.
|
1353
|
+
// DO NOT EVER CHANGE THIS. We want to explicitly allow users
|
1354
|
+
// to be able to depend on this behavior, so they will have
|
1355
|
+
// the option to do some things faster. Additionally it's
|
1356
|
+
// a security guard against buffer overflows.
|
1357
|
+
readbuffer [r] = 0;
|
1358
|
+
|
1359
|
+
|
1360
|
+
// Set up a "temporary" return address so that callers can "reply" to us
|
1361
|
+
// from within the callback we are about to invoke. That means that ordinary
|
1362
|
+
// calls to "send_data_to_connection" (which is of course misnamed in this
|
1363
|
+
// case) will result in packets being sent back to the same place that sent
|
1364
|
+
// us this one.
|
1365
|
+
// There is a different call (evma_send_datagram) for cases where the caller
|
1366
|
+
// actually wants to send a packet somewhere else.
|
1367
|
+
|
1368
|
+
memset (&ReturnAddress, 0, sizeof(ReturnAddress));
|
1369
|
+
memcpy (&ReturnAddress, &sin, slen);
|
1370
|
+
|
1371
|
+
_GenericInboundDispatch(readbuffer, r);
|
1372
|
+
|
1373
|
+
}
|
1374
|
+
else {
|
1375
|
+
// Basically a would-block, meaning we've read everything there is to read.
|
1376
|
+
break;
|
1377
|
+
}
|
1378
|
+
|
1379
|
+
}
|
1380
|
+
|
1381
|
+
|
1382
|
+
}
|
1383
|
+
|
1384
|
+
|
1385
|
+
/*************************
|
1386
|
+
DatagramDescriptor::Write
|
1387
|
+
*************************/
|
1388
|
+
|
1389
|
+
void DatagramDescriptor::Write()
|
1390
|
+
{
|
1391
|
+
/* It's possible for a socket to select writable and then no longer
|
1392
|
+
* be writable by the time we get around to writing. The kernel might
|
1393
|
+
* have used up its available output buffers between the select call
|
1394
|
+
* and when we get here. So this condition is not an error.
|
1395
|
+
* This code is very reminiscent of ConnectionDescriptor::_WriteOutboundData,
|
1396
|
+
* but differs in the that the outbound data pages (received from the
|
1397
|
+
* user) are _message-structured._ That is, we send each of them out
|
1398
|
+
* one message at a time.
|
1399
|
+
* TODO, we are currently suppressing the EMSGSIZE error!!!
|
1400
|
+
*/
|
1401
|
+
|
1402
|
+
int sd = GetSocket();
|
1403
|
+
assert (sd != INVALID_SOCKET);
|
1404
|
+
LastIo = gCurrentLoopTime;
|
1405
|
+
|
1406
|
+
assert (OutboundPages.size() > 0);
|
1407
|
+
|
1408
|
+
// Send out up to 10 packets, then cycle the machine.
|
1409
|
+
for (int i = 0; i < 10; i++) {
|
1410
|
+
if (OutboundPages.size() <= 0)
|
1411
|
+
break;
|
1412
|
+
OutboundPage *op = &(OutboundPages[0]);
|
1413
|
+
|
1414
|
+
// The nasty cast to (char*) is needed because Windows is brain-dead.
|
1415
|
+
int s = sendto (sd, (char*)op->Buffer, op->Length, 0, (struct sockaddr*)&(op->From), sizeof(op->From));
|
1416
|
+
int e = errno;
|
1417
|
+
|
1418
|
+
OutboundDataSize -= op->Length;
|
1419
|
+
op->Free();
|
1420
|
+
OutboundPages.pop_front();
|
1421
|
+
|
1422
|
+
if (s == SOCKET_ERROR) {
|
1423
|
+
#ifdef OS_UNIX
|
1424
|
+
if ((e != EINPROGRESS) && (e != EWOULDBLOCK) && (e != EINTR)) {
|
1425
|
+
#endif
|
1426
|
+
#ifdef OS_WIN32
|
1427
|
+
if ((e != WSAEINPROGRESS) && (e != WSAEWOULDBLOCK)) {
|
1428
|
+
#endif
|
1429
|
+
Close();
|
1430
|
+
break;
|
1431
|
+
}
|
1432
|
+
}
|
1433
|
+
}
|
1434
|
+
|
1435
|
+
#ifdef HAVE_EPOLL
|
1436
|
+
EpollEvent.events = (EPOLLIN | (SelectForWrite() ? EPOLLOUT : 0));
|
1437
|
+
assert (MyEventMachine);
|
1438
|
+
MyEventMachine->Modify (this);
|
1439
|
+
#endif
|
1440
|
+
}
|
1441
|
+
|
1442
|
+
|
1443
|
+
/**********************************
|
1444
|
+
DatagramDescriptor::SelectForWrite
|
1445
|
+
**********************************/
|
1446
|
+
|
1447
|
+
bool DatagramDescriptor::SelectForWrite()
|
1448
|
+
{
|
1449
|
+
/* Changed 15Nov07, per bug report by Mark Zvillius.
|
1450
|
+
* The outbound data size will be zero if there are zero-length outbound packets,
|
1451
|
+
* so we now select writable in case the outbound page buffer is not empty.
|
1452
|
+
* Note that the superclass ShouldDelete method still checks for outbound data size,
|
1453
|
+
* which may be wrong.
|
1454
|
+
*/
|
1455
|
+
//return (GetOutboundDataSize() > 0); (Original)
|
1456
|
+
return (OutboundPages.size() > 0);
|
1457
|
+
}
|
1458
|
+
|
1459
|
+
|
1460
|
+
/************************************
|
1461
|
+
DatagramDescriptor::SendOutboundData
|
1462
|
+
************************************/
|
1463
|
+
|
1464
|
+
int DatagramDescriptor::SendOutboundData (const char *data, int length)
|
1465
|
+
{
|
1466
|
+
// This is an exact clone of ConnectionDescriptor::SendOutboundData.
|
1467
|
+
// That means it needs to move to a common ancestor.
|
1468
|
+
|
1469
|
+
if (IsCloseScheduled())
|
1470
|
+
//if (bCloseNow || bCloseAfterWriting)
|
1471
|
+
return 0;
|
1472
|
+
|
1473
|
+
if (!data && (length > 0))
|
1474
|
+
throw std::runtime_error ("bad outbound data");
|
1475
|
+
char *buffer = (char *) malloc (length + 1);
|
1476
|
+
if (!buffer)
|
1477
|
+
throw std::runtime_error ("no allocation for outbound data");
|
1478
|
+
memcpy (buffer, data, length);
|
1479
|
+
buffer [length] = 0;
|
1480
|
+
OutboundPages.push_back (OutboundPage (buffer, length, ReturnAddress));
|
1481
|
+
OutboundDataSize += length;
|
1482
|
+
|
1483
|
+
#ifdef HAVE_EPOLL
|
1484
|
+
EpollEvent.events = (EPOLLIN | EPOLLOUT);
|
1485
|
+
assert (MyEventMachine);
|
1486
|
+
MyEventMachine->Modify (this);
|
1487
|
+
#endif
|
1488
|
+
|
1489
|
+
return length;
|
1490
|
+
}
|
1491
|
+
|
1492
|
+
|
1493
|
+
/****************************************
|
1494
|
+
DatagramDescriptor::SendOutboundDatagram
|
1495
|
+
****************************************/
|
1496
|
+
|
1497
|
+
int DatagramDescriptor::SendOutboundDatagram (const char *data, int length, const char *address, int port)
|
1498
|
+
{
|
1499
|
+
// This is an exact clone of ConnectionDescriptor::SendOutboundData.
|
1500
|
+
// That means it needs to move to a common ancestor.
|
1501
|
+
// TODO: Refactor this so there's no overlap with SendOutboundData.
|
1502
|
+
|
1503
|
+
if (IsCloseScheduled())
|
1504
|
+
//if (bCloseNow || bCloseAfterWriting)
|
1505
|
+
return 0;
|
1506
|
+
|
1507
|
+
if (!address || !*address || !port)
|
1508
|
+
return 0;
|
1509
|
+
|
1510
|
+
sockaddr_in pin;
|
1511
|
+
unsigned long HostAddr;
|
1512
|
+
|
1513
|
+
HostAddr = inet_addr (address);
|
1514
|
+
if (HostAddr == INADDR_NONE) {
|
1515
|
+
// The nasty cast to (char*) is because Windows is brain-dead.
|
1516
|
+
hostent *hp = gethostbyname ((char*)address);
|
1517
|
+
if (!hp)
|
1518
|
+
return 0;
|
1519
|
+
HostAddr = ((in_addr*)(hp->h_addr))->s_addr;
|
1520
|
+
}
|
1521
|
+
|
1522
|
+
memset (&pin, 0, sizeof(pin));
|
1523
|
+
pin.sin_family = AF_INET;
|
1524
|
+
pin.sin_addr.s_addr = HostAddr;
|
1525
|
+
pin.sin_port = htons (port);
|
1526
|
+
|
1527
|
+
|
1528
|
+
if (!data && (length > 0))
|
1529
|
+
throw std::runtime_error ("bad outbound data");
|
1530
|
+
char *buffer = (char *) malloc (length + 1);
|
1531
|
+
if (!buffer)
|
1532
|
+
throw std::runtime_error ("no allocation for outbound data");
|
1533
|
+
memcpy (buffer, data, length);
|
1534
|
+
buffer [length] = 0;
|
1535
|
+
OutboundPages.push_back (OutboundPage (buffer, length, pin));
|
1536
|
+
OutboundDataSize += length;
|
1537
|
+
|
1538
|
+
#ifdef HAVE_EPOLL
|
1539
|
+
EpollEvent.events = (EPOLLIN | EPOLLOUT);
|
1540
|
+
assert (MyEventMachine);
|
1541
|
+
MyEventMachine->Modify (this);
|
1542
|
+
#endif
|
1543
|
+
|
1544
|
+
return length;
|
1545
|
+
}
|
1546
|
+
|
1547
|
+
|
1548
|
+
/****************************************
|
1549
|
+
STATIC: DatagramDescriptor::SendDatagram
|
1550
|
+
****************************************/
|
1551
|
+
|
1552
|
+
int DatagramDescriptor::SendDatagram (const char *binding, const char *data, int length, const char *address, int port)
|
1553
|
+
{
|
1554
|
+
DatagramDescriptor *dd = dynamic_cast <DatagramDescriptor*> (Bindable_t::GetObject (binding));
|
1555
|
+
if (dd)
|
1556
|
+
return dd->SendOutboundDatagram (data, length, address, port);
|
1557
|
+
else
|
1558
|
+
return -1;
|
1559
|
+
}
|
1560
|
+
|
1561
|
+
|
1562
|
+
/*********************************
|
1563
|
+
ConnectionDescriptor::GetPeername
|
1564
|
+
*********************************/
|
1565
|
+
|
1566
|
+
bool ConnectionDescriptor::GetPeername (struct sockaddr *s)
|
1567
|
+
{
|
1568
|
+
bool ok = false;
|
1569
|
+
if (s) {
|
1570
|
+
socklen_t len = sizeof(*s);
|
1571
|
+
int gp = getpeername (GetSocket(), s, &len);
|
1572
|
+
if (gp == 0)
|
1573
|
+
ok = true;
|
1574
|
+
}
|
1575
|
+
return ok;
|
1576
|
+
}
|
1577
|
+
|
1578
|
+
/*********************************
|
1579
|
+
ConnectionDescriptor::GetSockname
|
1580
|
+
*********************************/
|
1581
|
+
|
1582
|
+
bool ConnectionDescriptor::GetSockname (struct sockaddr *s)
|
1583
|
+
{
|
1584
|
+
bool ok = false;
|
1585
|
+
if (s) {
|
1586
|
+
socklen_t len = sizeof(*s);
|
1587
|
+
int gp = getsockname (GetSocket(), s, &len);
|
1588
|
+
if (gp == 0)
|
1589
|
+
ok = true;
|
1590
|
+
}
|
1591
|
+
return ok;
|
1592
|
+
}
|
1593
|
+
|
1594
|
+
|
1595
|
+
/**********************************************
|
1596
|
+
ConnectionDescriptor::GetCommInactivityTimeout
|
1597
|
+
**********************************************/
|
1598
|
+
|
1599
|
+
float ConnectionDescriptor::GetCommInactivityTimeout()
|
1600
|
+
{
|
1601
|
+
return ((float)InactivityTimeout / 1000000);
|
1602
|
+
}
|
1603
|
+
|
1604
|
+
|
1605
|
+
/**********************************************
|
1606
|
+
ConnectionDescriptor::SetCommInactivityTimeout
|
1607
|
+
**********************************************/
|
1608
|
+
|
1609
|
+
int ConnectionDescriptor::SetCommInactivityTimeout (float value)
|
1610
|
+
{
|
1611
|
+
if (value > 0) {
|
1612
|
+
InactivityTimeout = (Int64)(value * 1000000);
|
1613
|
+
return 1;
|
1614
|
+
}
|
1615
|
+
return 0;
|
1616
|
+
}
|
1617
|
+
|
1618
|
+
/*******************************
|
1619
|
+
DatagramDescriptor::GetPeername
|
1620
|
+
*******************************/
|
1621
|
+
|
1622
|
+
bool DatagramDescriptor::GetPeername (struct sockaddr *s)
|
1623
|
+
{
|
1624
|
+
bool ok = false;
|
1625
|
+
if (s) {
|
1626
|
+
memset (s, 0, sizeof(struct sockaddr));
|
1627
|
+
memcpy (s, &ReturnAddress, sizeof(ReturnAddress));
|
1628
|
+
ok = true;
|
1629
|
+
}
|
1630
|
+
return ok;
|
1631
|
+
}
|
1632
|
+
|
1633
|
+
/*******************************
|
1634
|
+
DatagramDescriptor::GetSockname
|
1635
|
+
*******************************/
|
1636
|
+
|
1637
|
+
bool DatagramDescriptor::GetSockname (struct sockaddr *s)
|
1638
|
+
{
|
1639
|
+
bool ok = false;
|
1640
|
+
if (s) {
|
1641
|
+
socklen_t len = sizeof(*s);
|
1642
|
+
int gp = getsockname (GetSocket(), s, &len);
|
1643
|
+
if (gp == 0)
|
1644
|
+
ok = true;
|
1645
|
+
}
|
1646
|
+
return ok;
|
1647
|
+
}
|
1648
|
+
|
1649
|
+
|
1650
|
+
|
1651
|
+
/********************************************
|
1652
|
+
DatagramDescriptor::GetCommInactivityTimeout
|
1653
|
+
********************************************/
|
1654
|
+
|
1655
|
+
float DatagramDescriptor::GetCommInactivityTimeout()
|
1656
|
+
{
|
1657
|
+
return ((float)InactivityTimeout / 1000000);
|
1658
|
+
}
|
1659
|
+
|
1660
|
+
/********************************************
|
1661
|
+
DatagramDescriptor::SetCommInactivityTimeout
|
1662
|
+
********************************************/
|
1663
|
+
|
1664
|
+
int DatagramDescriptor::SetCommInactivityTimeout (float value)
|
1665
|
+
{
|
1666
|
+
if (value > 0) {
|
1667
|
+
InactivityTimeout = (Int64)(value * 1000000);
|
1668
|
+
return 1;
|
1669
|
+
}
|
1670
|
+
return 0;
|
1671
|
+
}
|
1672
|
+
|
1673
|
+
|
1674
|
+
/************************************
|
1675
|
+
InotifyDescriptor::InotifyDescriptor
|
1676
|
+
*************************************/
|
1677
|
+
|
1678
|
+
InotifyDescriptor::InotifyDescriptor (EventMachine_t *em):
|
1679
|
+
EventableDescriptor(0, em)
|
1680
|
+
{
|
1681
|
+
bCallbackUnbind = false;
|
1682
|
+
|
1683
|
+
#ifndef HAVE_INOTIFY
|
1684
|
+
throw std::runtime_error("no inotify support on this system");
|
1685
|
+
#else
|
1686
|
+
|
1687
|
+
int fd = inotify_init();
|
1688
|
+
if (fd == -1) {
|
1689
|
+
char buf[200];
|
1690
|
+
snprintf (buf, sizeof(buf)-1, "unable to create inotify descriptor: %s", strerror(errno));
|
1691
|
+
throw std::runtime_error (buf);
|
1692
|
+
}
|
1693
|
+
|
1694
|
+
MySocket = fd;
|
1695
|
+
SetSocketNonblocking(MySocket);
|
1696
|
+
#ifdef HAVE_EPOLL
|
1697
|
+
EpollEvent.events = EPOLLIN;
|
1698
|
+
#endif
|
1699
|
+
|
1700
|
+
#endif
|
1701
|
+
}
|
1702
|
+
|
1703
|
+
|
1704
|
+
/*************************************
|
1705
|
+
InotifyDescriptor::~InotifyDescriptor
|
1706
|
+
**************************************/
|
1707
|
+
|
1708
|
+
InotifyDescriptor::~InotifyDescriptor()
|
1709
|
+
{
|
1710
|
+
close(MySocket);
|
1711
|
+
MySocket = INVALID_SOCKET;
|
1712
|
+
}
|
1713
|
+
|
1714
|
+
/***********************
|
1715
|
+
InotifyDescriptor::Read
|
1716
|
+
************************/
|
1717
|
+
|
1718
|
+
void InotifyDescriptor::Read()
|
1719
|
+
{
|
1720
|
+
assert (MyEventMachine);
|
1721
|
+
MyEventMachine->_ReadInotifyEvents();
|
1722
|
+
}
|
1723
|
+
|
1724
|
+
|
1725
|
+
/************************
|
1726
|
+
InotifyDescriptor::Write
|
1727
|
+
*************************/
|
1728
|
+
|
1729
|
+
void InotifyDescriptor::Write()
|
1730
|
+
{
|
1731
|
+
throw std::runtime_error("bad code path in inotify");
|
1732
|
+
}
|