wj_eventmachine 1.3.0.dev.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +179 -0
  3. data/GNU +281 -0
  4. data/LICENSE +60 -0
  5. data/README.md +110 -0
  6. data/docs/DocumentationGuidesIndex.md +27 -0
  7. data/docs/GettingStarted.md +520 -0
  8. data/docs/old/ChangeLog +211 -0
  9. data/docs/old/DEFERRABLES +246 -0
  10. data/docs/old/EPOLL +141 -0
  11. data/docs/old/INSTALL +13 -0
  12. data/docs/old/KEYBOARD +42 -0
  13. data/docs/old/LEGAL +25 -0
  14. data/docs/old/LIGHTWEIGHT_CONCURRENCY +130 -0
  15. data/docs/old/PURE_RUBY +75 -0
  16. data/docs/old/RELEASE_NOTES +94 -0
  17. data/docs/old/SMTP +4 -0
  18. data/docs/old/SPAWNED_PROCESSES +148 -0
  19. data/docs/old/TODO +8 -0
  20. data/examples/guides/getting_started/01_eventmachine_echo_server.rb +18 -0
  21. data/examples/guides/getting_started/02_eventmachine_echo_server_that_recognizes_exit_command.rb +22 -0
  22. data/examples/guides/getting_started/03_simple_chat_server.rb +149 -0
  23. data/examples/guides/getting_started/04_simple_chat_server_step_one.rb +27 -0
  24. data/examples/guides/getting_started/05_simple_chat_server_step_two.rb +43 -0
  25. data/examples/guides/getting_started/06_simple_chat_server_step_three.rb +98 -0
  26. data/examples/guides/getting_started/07_simple_chat_server_step_four.rb +121 -0
  27. data/examples/guides/getting_started/08_simple_chat_server_step_five.rb +141 -0
  28. data/examples/old/ex_channel.rb +43 -0
  29. data/examples/old/ex_queue.rb +2 -0
  30. data/examples/old/ex_tick_loop_array.rb +15 -0
  31. data/examples/old/ex_tick_loop_counter.rb +32 -0
  32. data/examples/old/helper.rb +2 -0
  33. data/ext/binder.cpp +124 -0
  34. data/ext/binder.h +52 -0
  35. data/ext/cmain.cpp +1046 -0
  36. data/ext/ed.cpp +2238 -0
  37. data/ext/ed.h +460 -0
  38. data/ext/em.cpp +2378 -0
  39. data/ext/em.h +266 -0
  40. data/ext/eventmachine.h +152 -0
  41. data/ext/extconf.rb +285 -0
  42. data/ext/fastfilereader/extconf.rb +120 -0
  43. data/ext/fastfilereader/mapper.cpp +214 -0
  44. data/ext/fastfilereader/mapper.h +59 -0
  45. data/ext/fastfilereader/rubymain.cpp +126 -0
  46. data/ext/kb.cpp +79 -0
  47. data/ext/page.cpp +107 -0
  48. data/ext/page.h +51 -0
  49. data/ext/pipe.cpp +354 -0
  50. data/ext/project.h +174 -0
  51. data/ext/rubymain.cpp +1610 -0
  52. data/ext/ssl.cpp +627 -0
  53. data/ext/ssl.h +103 -0
  54. data/ext/wait_for_single_fd.h +36 -0
  55. data/java/.classpath +8 -0
  56. data/java/.project +17 -0
  57. data/java/src/com/rubyeventmachine/EmReactor.java +625 -0
  58. data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
  59. data/java/src/com/rubyeventmachine/EmReactorInterface.java +70 -0
  60. data/java/src/com/rubyeventmachine/EventableChannel.java +72 -0
  61. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +201 -0
  62. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +415 -0
  63. data/java/src/com/rubyeventmachine/NullEmReactor.java +157 -0
  64. data/java/src/com/rubyeventmachine/NullEventableChannel.java +81 -0
  65. data/lib/em/buftok.rb +59 -0
  66. data/lib/em/callback.rb +58 -0
  67. data/lib/em/channel.rb +69 -0
  68. data/lib/em/completion.rb +307 -0
  69. data/lib/em/connection.rb +776 -0
  70. data/lib/em/deferrable.rb +210 -0
  71. data/lib/em/deferrable/pool.rb +2 -0
  72. data/lib/em/file_watch.rb +73 -0
  73. data/lib/em/future.rb +61 -0
  74. data/lib/em/io_streamer.rb +68 -0
  75. data/lib/em/iterator.rb +252 -0
  76. data/lib/em/messages.rb +66 -0
  77. data/lib/em/pool.rb +151 -0
  78. data/lib/em/process_watch.rb +45 -0
  79. data/lib/em/processes.rb +123 -0
  80. data/lib/em/protocols.rb +37 -0
  81. data/lib/em/protocols/header_and_content.rb +138 -0
  82. data/lib/em/protocols/httpclient.rb +303 -0
  83. data/lib/em/protocols/httpclient2.rb +602 -0
  84. data/lib/em/protocols/line_and_text.rb +125 -0
  85. data/lib/em/protocols/line_protocol.rb +33 -0
  86. data/lib/em/protocols/linetext2.rb +179 -0
  87. data/lib/em/protocols/memcache.rb +331 -0
  88. data/lib/em/protocols/object_protocol.rb +46 -0
  89. data/lib/em/protocols/postgres3.rb +246 -0
  90. data/lib/em/protocols/saslauth.rb +175 -0
  91. data/lib/em/protocols/smtpclient.rb +394 -0
  92. data/lib/em/protocols/smtpserver.rb +666 -0
  93. data/lib/em/protocols/socks4.rb +66 -0
  94. data/lib/em/protocols/stomp.rb +205 -0
  95. data/lib/em/protocols/tcptest.rb +54 -0
  96. data/lib/em/pure_ruby.rb +1299 -0
  97. data/lib/em/queue.rb +80 -0
  98. data/lib/em/resolver.rb +232 -0
  99. data/lib/em/spawnable.rb +84 -0
  100. data/lib/em/streamer.rb +118 -0
  101. data/lib/em/threaded_resource.rb +90 -0
  102. data/lib/em/tick_loop.rb +85 -0
  103. data/lib/em/timers.rb +61 -0
  104. data/lib/em/version.rb +3 -0
  105. data/lib/eventmachine.rb +1602 -0
  106. data/lib/jeventmachine.rb +318 -0
  107. data/rakelib/package.rake +120 -0
  108. data/rakelib/test.rake +6 -0
  109. data/rakelib/test_pure.rake +11 -0
  110. data/tests/client.crt +31 -0
  111. data/tests/client.key +51 -0
  112. data/tests/dhparam.pem +13 -0
  113. data/tests/em_ssl_handlers.rb +153 -0
  114. data/tests/em_test_helper.rb +198 -0
  115. data/tests/jruby/test_jeventmachine.rb +38 -0
  116. data/tests/test_attach.rb +199 -0
  117. data/tests/test_basic.rb +321 -0
  118. data/tests/test_channel.rb +75 -0
  119. data/tests/test_completion.rb +178 -0
  120. data/tests/test_connection_count.rb +83 -0
  121. data/tests/test_connection_write.rb +35 -0
  122. data/tests/test_defer.rb +35 -0
  123. data/tests/test_deferrable.rb +35 -0
  124. data/tests/test_epoll.rb +141 -0
  125. data/tests/test_error_handler.rb +38 -0
  126. data/tests/test_exc.rb +37 -0
  127. data/tests/test_file_watch.rb +86 -0
  128. data/tests/test_fork.rb +75 -0
  129. data/tests/test_futures.rb +170 -0
  130. data/tests/test_handler_check.rb +35 -0
  131. data/tests/test_hc.rb +155 -0
  132. data/tests/test_httpclient.rb +238 -0
  133. data/tests/test_httpclient2.rb +132 -0
  134. data/tests/test_idle_connection.rb +31 -0
  135. data/tests/test_inactivity_timeout.rb +102 -0
  136. data/tests/test_io_streamer.rb +47 -0
  137. data/tests/test_ipv4.rb +96 -0
  138. data/tests/test_ipv6.rb +107 -0
  139. data/tests/test_iterator.rb +122 -0
  140. data/tests/test_kb.rb +28 -0
  141. data/tests/test_keepalive.rb +113 -0
  142. data/tests/test_line_protocol.rb +33 -0
  143. data/tests/test_ltp.rb +155 -0
  144. data/tests/test_ltp2.rb +332 -0
  145. data/tests/test_many_fds.rb +21 -0
  146. data/tests/test_next_tick.rb +104 -0
  147. data/tests/test_object_protocol.rb +36 -0
  148. data/tests/test_pause.rb +109 -0
  149. data/tests/test_pending_connect_timeout.rb +52 -0
  150. data/tests/test_pool.rb +196 -0
  151. data/tests/test_process_watch.rb +50 -0
  152. data/tests/test_processes.rb +128 -0
  153. data/tests/test_proxy_connection.rb +180 -0
  154. data/tests/test_pure.rb +156 -0
  155. data/tests/test_queue.rb +64 -0
  156. data/tests/test_resolver.rb +129 -0
  157. data/tests/test_running.rb +14 -0
  158. data/tests/test_sasl.rb +46 -0
  159. data/tests/test_send_file.rb +217 -0
  160. data/tests/test_servers.rb +32 -0
  161. data/tests/test_shutdown_hooks.rb +23 -0
  162. data/tests/test_smtpclient.rb +75 -0
  163. data/tests/test_smtpserver.rb +90 -0
  164. data/tests/test_sock_opt.rb +53 -0
  165. data/tests/test_spawn.rb +290 -0
  166. data/tests/test_ssl_args.rb +41 -0
  167. data/tests/test_ssl_dhparam.rb +57 -0
  168. data/tests/test_ssl_ecdh_curve.rb +57 -0
  169. data/tests/test_ssl_extensions.rb +24 -0
  170. data/tests/test_ssl_methods.rb +31 -0
  171. data/tests/test_ssl_protocols.rb +190 -0
  172. data/tests/test_ssl_verify.rb +52 -0
  173. data/tests/test_stomp.rb +38 -0
  174. data/tests/test_system.rb +46 -0
  175. data/tests/test_threaded_resource.rb +68 -0
  176. data/tests/test_tick_loop.rb +58 -0
  177. data/tests/test_timers.rb +150 -0
  178. data/tests/test_ud.rb +8 -0
  179. data/tests/test_unbind_reason.rb +40 -0
  180. metadata +384 -0
@@ -0,0 +1,460 @@
1
+ /*****************************************************************************
2
+
3
+ $Id$
4
+
5
+ File: ed.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
+ #ifndef __EventableDescriptor__H_
21
+ #define __EventableDescriptor__H_
22
+
23
+
24
+ class EventMachine_t; // forward reference
25
+ #ifdef WITH_SSL
26
+ class SslBox_t; // forward reference
27
+ #endif
28
+
29
+ bool SetSocketNonblocking (SOCKET);
30
+ bool SetFdCloexec (int);
31
+
32
+ /*************************
33
+ class EventableDescriptor
34
+ *************************/
35
+
36
+ class EventableDescriptor: public Bindable_t
37
+ {
38
+ public:
39
+ EventableDescriptor (SOCKET, EventMachine_t*);
40
+ virtual ~EventableDescriptor() NO_EXCEPT_FALSE;
41
+
42
+ SOCKET GetSocket() {return MySocket;}
43
+ void SetSocketInvalid() { MySocket = INVALID_SOCKET; }
44
+ void Close();
45
+
46
+ virtual void Read() = 0;
47
+ virtual void Write() = 0;
48
+ virtual void Heartbeat() = 0;
49
+
50
+ // These methods tell us whether the descriptor
51
+ // should be selected or polled for read/write.
52
+ virtual bool SelectForRead() = 0;
53
+ virtual bool SelectForWrite() = 0;
54
+
55
+ // are we scheduled for a close, or in an error state, or already closed?
56
+ bool ShouldDelete();
57
+ // Do we have any data to write? This is used by ShouldDelete.
58
+ virtual int GetOutboundDataSize() {return 0;}
59
+ virtual bool IsWatchOnly(){ return bWatchOnly; }
60
+
61
+ virtual void ScheduleClose (bool after_writing);
62
+ bool IsCloseScheduled();
63
+ virtual void HandleError(){ ScheduleClose (false); }
64
+
65
+ int EnableKeepalive(int idle, int intvl, int cnt);
66
+ int DisableKeepalive();
67
+
68
+ void SetEventCallback (EMCallback);
69
+
70
+ virtual bool GetPeername (struct sockaddr*, socklen_t*) = 0;
71
+ virtual bool GetSockname (struct sockaddr*, socklen_t*) = 0;
72
+ virtual bool GetSubprocessPid (pid_t*) {return false;}
73
+
74
+ virtual void StartTls() {}
75
+ virtual void SetTlsParms (const char *, const char *, bool, bool, const char *, const char *, const char *, const char *, int) {}
76
+
77
+ #ifdef WITH_SSL
78
+ virtual X509 *GetPeerCert() {return NULL;}
79
+ virtual int GetCipherBits() {return -1;}
80
+ virtual const char *GetCipherName() {return NULL;}
81
+ virtual const char *GetCipherProtocol() {return NULL;}
82
+ virtual const char *GetSNIHostname() {return NULL;}
83
+ #endif
84
+
85
+ virtual uint64_t GetCommInactivityTimeout() {return 0;}
86
+ virtual int SetCommInactivityTimeout (uint64_t) {return 0;}
87
+ uint64_t GetPendingConnectTimeout();
88
+ int SetPendingConnectTimeout (uint64_t value);
89
+ uint64_t GetLastActivity() { return LastActivity; }
90
+
91
+ #ifdef HAVE_EPOLL
92
+ struct epoll_event *GetEpollEvent() { return &EpollEvent; }
93
+ #endif
94
+
95
+ #ifdef HAVE_KQUEUE
96
+ bool GetKqueueArmWrite() { return bKqueueArmWrite; }
97
+ #endif
98
+
99
+ virtual void StartProxy(const uintptr_t, const unsigned long, const unsigned long);
100
+ virtual void StopProxy();
101
+ virtual unsigned long GetProxiedBytes(){ return ProxiedBytes; };
102
+ virtual void SetProxiedFrom(EventableDescriptor*, const unsigned long);
103
+ virtual int SendOutboundData(const char*,unsigned long){ return -1; }
104
+ virtual bool IsPaused(){ return bPaused; }
105
+ virtual bool Pause(){ bPaused = true; return bPaused; }
106
+ virtual bool Resume(){ bPaused = false; return bPaused; }
107
+
108
+ void SetUnbindReasonCode(int code){ UnbindReasonCode = code; }
109
+ virtual int ReportErrorStatus(){ return 0; }
110
+ virtual bool IsConnectPending(){ return false; }
111
+ virtual uint64_t GetNextHeartbeat();
112
+
113
+ private:
114
+ bool bCloseNow;
115
+ bool bCloseAfterWriting;
116
+
117
+ protected:
118
+ SOCKET MySocket;
119
+ bool bAttached;
120
+ bool bWatchOnly;
121
+
122
+ EMCallback EventCallback;
123
+ void _GenericInboundDispatch (const char *buffer, unsigned long size);
124
+ bool _GenericGetPeername (struct sockaddr*, socklen_t*);
125
+ bool _GenericGetSockname (struct sockaddr*, socklen_t*);
126
+
127
+ uint64_t CreatedAt;
128
+ bool bCallbackUnbind;
129
+ int UnbindReasonCode;
130
+
131
+ unsigned long BytesToProxy;
132
+ EventableDescriptor *ProxyTarget;
133
+ EventableDescriptor *ProxiedFrom;
134
+ unsigned long ProxiedBytes;
135
+
136
+ unsigned long MaxOutboundBufSize;
137
+
138
+ #ifdef HAVE_EPOLL
139
+ struct epoll_event EpollEvent;
140
+ #endif
141
+
142
+ #ifdef HAVE_KQUEUE
143
+ bool bKqueueArmWrite;
144
+ #endif
145
+
146
+ EventMachine_t *MyEventMachine;
147
+ uint64_t PendingConnectTimeout;
148
+ uint64_t InactivityTimeout;
149
+ uint64_t LastActivity;
150
+ uint64_t NextHeartbeat;
151
+ bool bPaused;
152
+ };
153
+
154
+
155
+
156
+ /*************************
157
+ class LoopbreakDescriptor
158
+ *************************/
159
+
160
+ class LoopbreakDescriptor: public EventableDescriptor
161
+ {
162
+ public:
163
+ LoopbreakDescriptor (SOCKET, EventMachine_t*);
164
+ virtual ~LoopbreakDescriptor() {}
165
+
166
+ virtual void Read();
167
+ virtual void Write();
168
+ virtual void Heartbeat() {}
169
+
170
+ virtual bool SelectForRead() {return true;}
171
+ virtual bool SelectForWrite() {return false;}
172
+
173
+ virtual bool GetPeername (struct sockaddr* s, socklen_t* len) { return _GenericGetPeername (s, len); }
174
+ virtual bool GetSockname (struct sockaddr* s, socklen_t* len) { return _GenericGetSockname (s, len); }
175
+ };
176
+
177
+
178
+ /**************************
179
+ class ConnectionDescriptor
180
+ **************************/
181
+
182
+ class ConnectionDescriptor: public EventableDescriptor
183
+ {
184
+ public:
185
+ ConnectionDescriptor (SOCKET, EventMachine_t*);
186
+ virtual ~ConnectionDescriptor();
187
+
188
+ int SendOutboundData (const char*, unsigned long);
189
+
190
+ void SetConnectPending (bool f);
191
+ virtual void ScheduleClose (bool after_writing);
192
+ virtual void HandleError();
193
+
194
+ void SetNotifyReadable (bool);
195
+ void SetNotifyWritable (bool);
196
+ void SetAttached (bool);
197
+ void SetWatchOnly (bool);
198
+
199
+ bool Pause();
200
+ bool Resume();
201
+
202
+ bool IsNotifyReadable(){ return bNotifyReadable; }
203
+ bool IsNotifyWritable(){ return bNotifyWritable; }
204
+
205
+ virtual void Read();
206
+ virtual void Write();
207
+ virtual void Heartbeat();
208
+
209
+ virtual bool SelectForRead();
210
+ virtual bool SelectForWrite();
211
+
212
+ // Do we have any data to write? This is used by ShouldDelete.
213
+ virtual int GetOutboundDataSize() {return OutboundDataSize;}
214
+
215
+ virtual void StartTls();
216
+ virtual void SetTlsParms (const char *, const char *, bool, bool, const char *, const char *, const char *, const char *, int);
217
+
218
+ #ifdef WITH_SSL
219
+ virtual X509 *GetPeerCert();
220
+ virtual int GetCipherBits();
221
+ virtual const char *GetCipherName();
222
+ virtual const char *GetCipherProtocol();
223
+ virtual const char *GetSNIHostname();
224
+ virtual bool VerifySslPeer(const char*);
225
+ virtual void AcceptSslPeer();
226
+ #endif
227
+
228
+ void SetServerMode() {bIsServer = true;}
229
+
230
+ virtual bool GetPeername (struct sockaddr* s, socklen_t* len) { return _GenericGetPeername (s, len); }
231
+ virtual bool GetSockname (struct sockaddr* s, socklen_t* len) { return _GenericGetSockname (s, len); }
232
+
233
+ virtual uint64_t GetCommInactivityTimeout();
234
+ virtual int SetCommInactivityTimeout (uint64_t value);
235
+
236
+ virtual int ReportErrorStatus();
237
+ virtual bool IsConnectPending(){ return bConnectPending; }
238
+
239
+ protected:
240
+ struct OutboundPage {
241
+ OutboundPage (const char *b, int l, int o=0): Buffer(b), Length(l), Offset(o) {}
242
+ void Free() {if (Buffer) free (const_cast<char*>(Buffer)); }
243
+ const char *Buffer;
244
+ int Length;
245
+ int Offset;
246
+ };
247
+
248
+ protected:
249
+ bool bConnectPending;
250
+
251
+ bool bNotifyReadable;
252
+ bool bNotifyWritable;
253
+
254
+ bool bReadAttemptedAfterClose;
255
+ bool bWriteAttemptedAfterClose;
256
+
257
+ std::deque<OutboundPage> OutboundPages;
258
+ int OutboundDataSize;
259
+
260
+ #ifdef WITH_SSL
261
+ SslBox_t *SslBox;
262
+ std::string CertChainFilename;
263
+ std::string PrivateKeyFilename;
264
+ std::string CipherList;
265
+ std::string EcdhCurve;
266
+ std::string DhParam;
267
+ int Protocols;
268
+ bool bHandshakeSignaled;
269
+ bool bSslVerifyPeer;
270
+ bool bSslFailIfNoPeerCert;
271
+ std::string SniHostName;
272
+ bool bSslPeerAccepted;
273
+ #endif
274
+
275
+ #ifdef HAVE_KQUEUE
276
+ bool bGotExtraKqueueEvent;
277
+ #endif
278
+
279
+ bool bIsServer;
280
+
281
+ private:
282
+ void _UpdateEvents();
283
+ void _UpdateEvents(bool, bool);
284
+ void _WriteOutboundData();
285
+ void _DispatchInboundData (const char *buffer, unsigned long size);
286
+ void _DispatchCiphertext();
287
+ int _SendRawOutboundData (const char *buffer, unsigned long size);
288
+ void _CheckHandshakeStatus();
289
+
290
+ };
291
+
292
+
293
+ /************************
294
+ class DatagramDescriptor
295
+ ************************/
296
+
297
+ class DatagramDescriptor: public EventableDescriptor
298
+ {
299
+ public:
300
+ DatagramDescriptor (SOCKET, EventMachine_t*);
301
+ virtual ~DatagramDescriptor();
302
+
303
+ virtual void Read();
304
+ virtual void Write();
305
+ virtual void Heartbeat();
306
+
307
+ virtual bool SelectForRead() {return true;}
308
+ virtual bool SelectForWrite();
309
+
310
+ int SendOutboundData (const char*, unsigned long);
311
+ int SendOutboundDatagram (const char*, unsigned long, const char*, int);
312
+
313
+ // Do we have any data to write? This is used by ShouldDelete.
314
+ virtual int GetOutboundDataSize() {return OutboundDataSize;}
315
+
316
+ virtual bool GetPeername (struct sockaddr* s, socklen_t* len);
317
+ virtual bool GetSockname (struct sockaddr* s, socklen_t* len) { return _GenericGetSockname (s, len); };
318
+
319
+ virtual uint64_t GetCommInactivityTimeout();
320
+ virtual int SetCommInactivityTimeout (uint64_t value);
321
+
322
+ protected:
323
+ struct OutboundPage {
324
+ OutboundPage (const char *b, int l, struct sockaddr_in6 f, int o=0): Buffer(b), Length(l), Offset(o), From(f) {}
325
+ void Free() {if (Buffer) free (const_cast<char*>(Buffer)); }
326
+ const char *Buffer;
327
+ int Length;
328
+ int Offset;
329
+ struct sockaddr_in6 From;
330
+ };
331
+
332
+ std::deque<OutboundPage> OutboundPages;
333
+ int OutboundDataSize;
334
+
335
+ struct sockaddr_in6 ReturnAddress;
336
+ };
337
+
338
+
339
+ /************************
340
+ class AcceptorDescriptor
341
+ ************************/
342
+
343
+ class AcceptorDescriptor: public EventableDescriptor
344
+ {
345
+ public:
346
+ AcceptorDescriptor (SOCKET, EventMachine_t*);
347
+ virtual ~AcceptorDescriptor();
348
+
349
+ virtual void Read();
350
+ virtual void Write();
351
+ virtual void Heartbeat();
352
+
353
+ virtual bool SelectForRead() {return true;}
354
+ virtual bool SelectForWrite() {return false;}
355
+
356
+ virtual bool GetPeername (struct sockaddr* s, socklen_t* len) { return _GenericGetPeername (s, len); }
357
+ virtual bool GetSockname (struct sockaddr* s, socklen_t* len) { return _GenericGetSockname (s, len); };
358
+
359
+ static void StopAcceptor (const uintptr_t binding);
360
+ };
361
+
362
+ /********************
363
+ class PipeDescriptor
364
+ ********************/
365
+
366
+ #ifdef OS_UNIX
367
+ class PipeDescriptor: public EventableDescriptor
368
+ {
369
+ public:
370
+ PipeDescriptor (SOCKET, pid_t, EventMachine_t*);
371
+ virtual ~PipeDescriptor() NO_EXCEPT_FALSE;
372
+
373
+ virtual void Read();
374
+ virtual void Write();
375
+ virtual void Heartbeat();
376
+
377
+ virtual bool SelectForRead();
378
+ virtual bool SelectForWrite();
379
+
380
+ int SendOutboundData (const char*, unsigned long);
381
+ virtual int GetOutboundDataSize() {return OutboundDataSize;}
382
+
383
+ virtual bool GetPeername (struct sockaddr* s, socklen_t* len) { return _GenericGetPeername (s, len); }
384
+ virtual bool GetSockname (struct sockaddr* s, socklen_t* len) { return _GenericGetSockname (s, len); }
385
+
386
+ virtual bool GetSubprocessPid (pid_t*);
387
+
388
+ protected:
389
+ struct OutboundPage {
390
+ OutboundPage (const char *b, int l, int o=0): Buffer(b), Length(l), Offset(o) {}
391
+ void Free() {if (Buffer) free (const_cast<char*>(Buffer)); }
392
+ const char *Buffer;
393
+ int Length;
394
+ int Offset;
395
+ };
396
+
397
+ protected:
398
+ bool bReadAttemptedAfterClose;
399
+
400
+ std::deque<OutboundPage> OutboundPages;
401
+ int OutboundDataSize;
402
+
403
+ pid_t SubprocessPid;
404
+
405
+ private:
406
+ void _DispatchInboundData (const char *buffer, int size);
407
+ };
408
+ #endif // OS_UNIX
409
+
410
+
411
+ /************************
412
+ class KeyboardDescriptor
413
+ ************************/
414
+
415
+ class KeyboardDescriptor: public EventableDescriptor
416
+ {
417
+ public:
418
+ KeyboardDescriptor (EventMachine_t*);
419
+ virtual ~KeyboardDescriptor();
420
+
421
+ virtual void Read();
422
+ virtual void Write();
423
+ virtual void Heartbeat();
424
+
425
+ virtual bool SelectForRead() {return true;}
426
+ virtual bool SelectForWrite() {return false;}
427
+
428
+ virtual bool GetPeername (struct sockaddr* s, socklen_t* len) { return _GenericGetPeername (s, len); }
429
+ virtual bool GetSockname (struct sockaddr* s, socklen_t* len) { return _GenericGetSockname (s, len); }
430
+
431
+ protected:
432
+ bool bReadAttemptedAfterClose;
433
+
434
+ private:
435
+ void _DispatchInboundData (const char *buffer, int size);
436
+ };
437
+
438
+
439
+ /***********************
440
+ class InotifyDescriptor
441
+ ************************/
442
+
443
+ class InotifyDescriptor: public EventableDescriptor
444
+ {
445
+ public:
446
+ InotifyDescriptor (EventMachine_t*);
447
+ virtual ~InotifyDescriptor();
448
+
449
+ void Read();
450
+ void Write();
451
+
452
+ virtual void Heartbeat() {}
453
+ virtual bool SelectForRead() {return true;}
454
+ virtual bool SelectForWrite() {return false;}
455
+
456
+ virtual bool GetPeername (struct sockaddr* s, socklen_t* len) { return false; }
457
+ virtual bool GetSockname (struct sockaddr* s, socklen_t* len) { return false; }
458
+ };
459
+
460
+ #endif // __EventableDescriptor__H_