eventmachine 0.12.6-x86-mswin32-60 → 0.12.8-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. data/{docs/README → README} +21 -13
  2. data/Rakefile +14 -4
  3. data/docs/DEFERRABLES +0 -5
  4. data/docs/INSTALL +2 -4
  5. data/docs/LEGAL +1 -1
  6. data/docs/LIGHTWEIGHT_CONCURRENCY +0 -2
  7. data/docs/PURE_RUBY +0 -2
  8. data/docs/RELEASE_NOTES +0 -2
  9. data/docs/SMTP +0 -7
  10. data/docs/SPAWNED_PROCESSES +0 -4
  11. data/docs/TODO +0 -2
  12. data/eventmachine.gemspec +41 -32
  13. data/examples/ex_channel.rb +43 -0
  14. data/examples/ex_queue.rb +2 -0
  15. data/examples/helper.rb +2 -0
  16. data/ext/cmain.cpp +685 -586
  17. data/ext/cplusplus.cpp +15 -6
  18. data/ext/ed.cpp +1732 -1522
  19. data/ext/ed.h +407 -380
  20. data/ext/em.cpp +2263 -1937
  21. data/ext/em.h +223 -186
  22. data/ext/eventmachine.h +111 -98
  23. data/ext/eventmachine_cpp.h +1 -0
  24. data/ext/extconf.rb +4 -0
  25. data/ext/kb.cpp +81 -82
  26. data/ext/pipe.cpp +349 -351
  27. data/ext/project.h +21 -0
  28. data/ext/rubymain.cpp +1047 -847
  29. data/ext/ssl.cpp +38 -1
  30. data/ext/ssl.h +5 -1
  31. data/java/src/com/rubyeventmachine/Application.java +7 -3
  32. data/java/src/com/rubyeventmachine/EmReactor.java +16 -1
  33. data/java/src/com/rubyeventmachine/tests/ConnectTest.java +25 -3
  34. data/lib/{protocols → em}/buftok.rb +16 -5
  35. data/lib/em/callback.rb +26 -0
  36. data/lib/em/channel.rb +57 -0
  37. data/lib/em/connection.rb +505 -0
  38. data/lib/em/deferrable.rb +144 -165
  39. data/lib/em/file_watch.rb +54 -0
  40. data/lib/em/future.rb +24 -25
  41. data/lib/em/messages.rb +1 -1
  42. data/lib/em/process_watch.rb +44 -0
  43. data/lib/em/processes.rb +119 -113
  44. data/lib/em/protocols.rb +35 -0
  45. data/lib/em/protocols/header_and_content.rb +138 -0
  46. data/lib/em/protocols/httpclient.rb +263 -0
  47. data/lib/em/protocols/httpclient2.rb +582 -0
  48. data/lib/{protocols → em/protocols}/line_and_text.rb +2 -2
  49. data/lib/em/protocols/linetext2.rb +160 -0
  50. data/lib/{protocols → em/protocols}/memcache.rb +37 -7
  51. data/lib/em/protocols/object_protocol.rb +39 -0
  52. data/lib/em/protocols/postgres3.rb +247 -0
  53. data/lib/em/protocols/saslauth.rb +175 -0
  54. data/lib/em/protocols/smtpclient.rb +331 -0
  55. data/lib/em/protocols/smtpserver.rb +547 -0
  56. data/lib/em/protocols/stomp.rb +200 -0
  57. data/lib/{protocols → em/protocols}/tcptest.rb +21 -25
  58. data/lib/em/queue.rb +61 -0
  59. data/lib/em/spawnable.rb +53 -56
  60. data/lib/em/streamer.rb +92 -74
  61. data/lib/em/timers.rb +55 -0
  62. data/lib/em/version.rb +3 -0
  63. data/lib/eventmachine.rb +1636 -1926
  64. data/lib/evma.rb +1 -1
  65. data/lib/jeventmachine.rb +106 -101
  66. data/lib/pr_eventmachine.rb +47 -36
  67. data/tasks/project.rake +2 -1
  68. data/tests/client.crt +31 -0
  69. data/tests/client.key +51 -0
  70. data/tests/test_attach.rb +18 -0
  71. data/tests/test_basic.rb +285 -231
  72. data/tests/test_channel.rb +63 -0
  73. data/tests/test_connection_count.rb +2 -2
  74. data/tests/test_epoll.rb +162 -163
  75. data/tests/test_errors.rb +36 -36
  76. data/tests/test_exc.rb +22 -25
  77. data/tests/test_file_watch.rb +49 -0
  78. data/tests/test_futures.rb +77 -93
  79. data/tests/test_hc.rb +2 -2
  80. data/tests/test_httpclient.rb +55 -52
  81. data/tests/test_httpclient2.rb +153 -155
  82. data/tests/test_inactivity_timeout.rb +30 -0
  83. data/tests/test_kb.rb +8 -9
  84. data/tests/test_ltp2.rb +274 -277
  85. data/tests/test_next_tick.rb +135 -109
  86. data/tests/test_object_protocol.rb +37 -0
  87. data/tests/test_process_watch.rb +48 -0
  88. data/tests/test_processes.rb +128 -95
  89. data/tests/test_proxy_connection.rb +92 -0
  90. data/tests/test_pure.rb +1 -5
  91. data/tests/test_queue.rb +44 -0
  92. data/tests/test_running.rb +9 -14
  93. data/tests/test_sasl.rb +32 -34
  94. data/tests/test_send_file.rb +175 -176
  95. data/tests/test_servers.rb +37 -41
  96. data/tests/test_smtpserver.rb +47 -55
  97. data/tests/test_spawn.rb +284 -291
  98. data/tests/test_ssl_args.rb +1 -1
  99. data/tests/test_ssl_methods.rb +1 -1
  100. data/tests/test_ssl_verify.rb +82 -0
  101. data/tests/test_timers.rb +81 -88
  102. data/tests/test_ud.rb +0 -7
  103. data/tests/testem.rb +1 -1
  104. metadata +52 -36
  105. data/lib/em/eventable.rb +0 -39
  106. data/lib/eventmachine_version.rb +0 -31
  107. data/lib/protocols/header_and_content.rb +0 -129
  108. data/lib/protocols/httpcli2.rb +0 -803
  109. data/lib/protocols/httpclient.rb +0 -270
  110. data/lib/protocols/linetext2.rb +0 -161
  111. data/lib/protocols/postgres.rb +0 -261
  112. data/lib/protocols/saslauth.rb +0 -179
  113. data/lib/protocols/smtpclient.rb +0 -308
  114. data/lib/protocols/smtpserver.rb +0 -556
  115. data/lib/protocols/stomp.rb +0 -153
  116. data/tests/test_eventables.rb +0 -77
data/ext/ed.h CHANGED
@@ -1,380 +1,407 @@
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
-
31
-
32
- /*************************
33
- class EventableDescriptor
34
- *************************/
35
-
36
- class EventableDescriptor: public Bindable_t
37
- {
38
- public:
39
- EventableDescriptor (int, EventMachine_t*);
40
- virtual ~EventableDescriptor();
41
-
42
- int 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
-
60
- void ScheduleClose (bool after_writing);
61
- bool IsCloseScheduled();
62
-
63
- void SetEventCallback (void (*cb)(const char*, int, const char*, int));
64
-
65
- virtual bool GetPeername (struct sockaddr*) {return false;}
66
- virtual bool GetSockname (struct sockaddr*) {return false;}
67
- virtual bool GetSubprocessPid (pid_t*) {return false;}
68
-
69
- virtual void StartTls() {}
70
- virtual void SetTlsParms (const char *privkey_filename, const char *certchain_filename) {}
71
-
72
- #ifdef WITH_SSL
73
- virtual X509 *GetPeerCert() {return NULL;}
74
- #endif
75
-
76
- // Properties: return 0/1 to signify T/F, and handle the values
77
- // through arguments.
78
- virtual int GetCommInactivityTimeout (int *value) {return 0;}
79
- virtual int SetCommInactivityTimeout (int *value) {return 0;}
80
-
81
- #ifdef HAVE_EPOLL
82
- struct epoll_event *GetEpollEvent() { return &EpollEvent; }
83
- #endif
84
-
85
- private:
86
- bool bCloseNow;
87
- bool bCloseAfterWriting;
88
- int MySocket;
89
-
90
- protected:
91
- enum {
92
- // 4 seconds is too short, most other libraries default to OS settings
93
- // which in 2.6 kernel defaults to a 60 second connect timeout.
94
- //
95
- // Curl-Multi: http://curl.haxx.se/mail/lib-2001-01/0019.html
96
- //
97
- // updating to 50 seconds, so we catch it before the OS does
98
-
99
- PendingConnectTimeout = 50 // can easily be made an instance variable
100
- };
101
-
102
- void (*EventCallback)(const char*, int, const char*, int);
103
-
104
- time_t CreatedAt;
105
- time_t LastRead;
106
- time_t LastWritten;
107
- bool bCallbackUnbind;
108
- int UnbindReasonCode;
109
-
110
- #ifdef HAVE_EPOLL
111
- struct epoll_event EpollEvent;
112
- #endif
113
-
114
- EventMachine_t *MyEventMachine;
115
- };
116
-
117
-
118
-
119
- /*************************
120
- class LoopbreakDescriptor
121
- *************************/
122
-
123
- class LoopbreakDescriptor: public EventableDescriptor
124
- {
125
- public:
126
- LoopbreakDescriptor (int, EventMachine_t*);
127
- virtual ~LoopbreakDescriptor() {}
128
-
129
- virtual void Read();
130
- virtual void Write();
131
- virtual void Heartbeat() {}
132
-
133
- virtual bool SelectForRead() {return true;}
134
- virtual bool SelectForWrite() {return false;}
135
- };
136
-
137
-
138
- /**************************
139
- class ConnectionDescriptor
140
- **************************/
141
-
142
- class ConnectionDescriptor: public EventableDescriptor
143
- {
144
- public:
145
- ConnectionDescriptor (int, EventMachine_t*);
146
- virtual ~ConnectionDescriptor();
147
-
148
- static int SendDataToConnection (const char*, const char*, int);
149
- static void CloseConnection (const char*, bool);
150
- static int ReportErrorStatus (const char*);
151
-
152
- int SendOutboundData (const char*, int);
153
-
154
- void SetConnectPending (bool f);
155
-
156
- void SetNotifyReadable (bool readable) { bNotifyReadable = readable; }
157
- void SetNotifyWritable (bool writable) { bNotifyWritable = writable; }
158
-
159
- virtual void Read();
160
- virtual void Write();
161
- virtual void Heartbeat();
162
-
163
- virtual bool SelectForRead();
164
- virtual bool SelectForWrite();
165
-
166
- // Do we have any data to write? This is used by ShouldDelete.
167
- virtual int GetOutboundDataSize() {return OutboundDataSize;}
168
-
169
- virtual void StartTls();
170
- virtual void SetTlsParms (const char *privkey_filename, const char *certchain_filename);
171
-
172
- #ifdef WITH_SSL
173
- virtual X509 *GetPeerCert();
174
- #endif
175
-
176
- void SetServerMode() {bIsServer = true;}
177
-
178
- virtual bool GetPeername (struct sockaddr*);
179
- virtual bool GetSockname (struct sockaddr*);
180
-
181
- virtual int GetCommInactivityTimeout (int *value);
182
- virtual int SetCommInactivityTimeout (int *value);
183
-
184
-
185
- protected:
186
- struct OutboundPage {
187
- OutboundPage (const char *b, int l, int o=0): Buffer(b), Length(l), Offset(o) {}
188
- void Free() {if (Buffer) free ((char*)Buffer); }
189
- const char *Buffer;
190
- int Length;
191
- int Offset;
192
- };
193
-
194
- protected:
195
- bool bConnectPending;
196
-
197
- bool bNotifyReadable;
198
- bool bNotifyWritable;
199
-
200
- bool bReadAttemptedAfterClose;
201
- bool bWriteAttemptedAfterClose;
202
-
203
- deque<OutboundPage> OutboundPages;
204
- int OutboundDataSize;
205
-
206
- #ifdef WITH_SSL
207
- SslBox_t *SslBox;
208
- std::string CertChainFilename;
209
- std::string PrivateKeyFilename;
210
- bool bHandshakeSignaled;
211
- #endif
212
- bool bIsServer;
213
-
214
- time_t LastIo;
215
- int InactivityTimeout;
216
-
217
- private:
218
- void _WriteOutboundData();
219
- void _DispatchInboundData (const char *buffer, int size);
220
- void _DispatchCiphertext();
221
- int _SendRawOutboundData (const char*, int);
222
- int _ReportErrorStatus();
223
- void _CheckHandshakeStatus();
224
-
225
- };
226
-
227
-
228
- /************************
229
- class DatagramDescriptor
230
- ************************/
231
-
232
- class DatagramDescriptor: public EventableDescriptor
233
- {
234
- public:
235
- DatagramDescriptor (int, EventMachine_t*);
236
- virtual ~DatagramDescriptor();
237
-
238
- virtual void Read();
239
- virtual void Write();
240
- virtual void Heartbeat();
241
-
242
- virtual bool SelectForRead() {return true;}
243
- virtual bool SelectForWrite();
244
-
245
- int SendOutboundData (const char*, int);
246
- int SendOutboundDatagram (const char*, int, const char*, int);
247
-
248
- // Do we have any data to write? This is used by ShouldDelete.
249
- virtual int GetOutboundDataSize() {return OutboundDataSize;}
250
-
251
- virtual bool GetPeername (struct sockaddr*);
252
- virtual bool GetSockname (struct sockaddr*);
253
-
254
- virtual int GetCommInactivityTimeout (int *value);
255
- virtual int SetCommInactivityTimeout (int *value);
256
-
257
- static int SendDatagram (const char*, const char*, int, const char*, int);
258
-
259
-
260
- protected:
261
- struct OutboundPage {
262
- OutboundPage (const char *b, int l, struct sockaddr_in f, int o=0): Buffer(b), Length(l), Offset(o), From(f) {}
263
- void Free() {if (Buffer) free ((char*)Buffer); }
264
- const char *Buffer;
265
- int Length;
266
- int Offset;
267
- struct sockaddr_in From;
268
- };
269
-
270
- deque<OutboundPage> OutboundPages;
271
- int OutboundDataSize;
272
-
273
- struct sockaddr_in ReturnAddress;
274
-
275
- time_t LastIo;
276
- int InactivityTimeout;
277
- };
278
-
279
-
280
- /************************
281
- class AcceptorDescriptor
282
- ************************/
283
-
284
- class AcceptorDescriptor: public EventableDescriptor
285
- {
286
- public:
287
- AcceptorDescriptor (int, EventMachine_t*);
288
- virtual ~AcceptorDescriptor();
289
-
290
- virtual void Read();
291
- virtual void Write();
292
- virtual void Heartbeat();
293
-
294
- virtual bool SelectForRead() {return true;}
295
- virtual bool SelectForWrite() {return false;}
296
-
297
- virtual bool GetSockname (struct sockaddr*);
298
-
299
- static void StopAcceptor (const char *binding);
300
- };
301
-
302
- /********************
303
- class PipeDescriptor
304
- ********************/
305
-
306
- #ifdef OS_UNIX
307
- class PipeDescriptor: public EventableDescriptor
308
- {
309
- public:
310
- PipeDescriptor (int, pid_t, EventMachine_t*);
311
- virtual ~PipeDescriptor();
312
-
313
- virtual void Read();
314
- virtual void Write();
315
- virtual void Heartbeat();
316
-
317
- virtual bool SelectForRead();
318
- virtual bool SelectForWrite();
319
-
320
- int SendOutboundData (const char*, int);
321
- virtual int GetOutboundDataSize() {return OutboundDataSize;}
322
-
323
- virtual bool GetSubprocessPid (pid_t*);
324
-
325
- protected:
326
- struct OutboundPage {
327
- OutboundPage (const char *b, int l, int o=0): Buffer(b), Length(l), Offset(o) {}
328
- void Free() {if (Buffer) free ((char*)Buffer); }
329
- const char *Buffer;
330
- int Length;
331
- int Offset;
332
- };
333
-
334
- protected:
335
- bool bReadAttemptedAfterClose;
336
- time_t LastIo;
337
- int InactivityTimeout;
338
-
339
- deque<OutboundPage> OutboundPages;
340
- int OutboundDataSize;
341
-
342
- pid_t SubprocessPid;
343
-
344
- private:
345
- void _DispatchInboundData (const char *buffer, int size);
346
- };
347
- #endif // OS_UNIX
348
-
349
-
350
- /************************
351
- class KeyboardDescriptor
352
- ************************/
353
-
354
- class KeyboardDescriptor: public EventableDescriptor
355
- {
356
- public:
357
- KeyboardDescriptor (EventMachine_t*);
358
- virtual ~KeyboardDescriptor();
359
-
360
- virtual void Read();
361
- virtual void Write();
362
- virtual void Heartbeat();
363
-
364
- virtual bool SelectForRead() {return true;}
365
- virtual bool SelectForWrite() {return false;}
366
-
367
- protected:
368
- bool bReadAttemptedAfterClose;
369
- time_t LastIo;
370
- int InactivityTimeout;
371
-
372
- private:
373
- void _DispatchInboundData (const char *buffer, int size);
374
- };
375
-
376
-
377
-
378
- #endif // __EventableDescriptor__H_
379
-
380
-
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
+
31
+
32
+ /*************************
33
+ class EventableDescriptor
34
+ *************************/
35
+
36
+ class EventableDescriptor: public Bindable_t
37
+ {
38
+ public:
39
+ EventableDescriptor (int, EventMachine_t*);
40
+ virtual ~EventableDescriptor();
41
+
42
+ int 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
+
60
+ void ScheduleClose (bool after_writing);
61
+ bool IsCloseScheduled();
62
+
63
+ void SetEventCallback (void (*cb)(const char*, int, const char*, int));
64
+
65
+ virtual bool GetPeername (struct sockaddr*) {return false;}
66
+ virtual bool GetSockname (struct sockaddr*) {return false;}
67
+ virtual bool GetSubprocessPid (pid_t*) {return false;}
68
+
69
+ virtual void StartTls() {}
70
+ virtual void SetTlsParms (const char *privkey_filename, const char *certchain_filename, bool verify_peer) {}
71
+
72
+ #ifdef WITH_SSL
73
+ virtual X509 *GetPeerCert() {return NULL;}
74
+ #endif
75
+
76
+ virtual float GetCommInactivityTimeout() {return 0.0;}
77
+ virtual int SetCommInactivityTimeout (float value) {return 0;}
78
+
79
+ #ifdef HAVE_EPOLL
80
+ struct epoll_event *GetEpollEvent() { return &EpollEvent; }
81
+ #endif
82
+
83
+ virtual void StartProxy(const char*);
84
+ virtual void StopProxy();
85
+
86
+ private:
87
+ bool bCloseNow;
88
+ bool bCloseAfterWriting;
89
+
90
+ protected:
91
+ int MySocket;
92
+ enum {
93
+ // 4 seconds is too short, most other libraries default to OS settings
94
+ // which in 2.6 kernel defaults to a 60 second connect timeout.
95
+ //
96
+ // Curl-Multi: http://curl.haxx.se/mail/lib-2001-01/0019.html
97
+ //
98
+ // updating to 50 seconds, so we catch it before the OS does
99
+
100
+ // can easily be made an instance variable
101
+ PendingConnectTimeout = 50000000 // now in usec
102
+ };
103
+
104
+ void (*EventCallback)(const char*, int, const char*, int);
105
+ void _GenericInboundDispatch(const char*, int);
106
+
107
+ Int64 CreatedAt;
108
+ bool bCallbackUnbind;
109
+ int UnbindReasonCode;
110
+ char *ProxyTarget;
111
+
112
+ #ifdef HAVE_EPOLL
113
+ struct epoll_event EpollEvent;
114
+ #endif
115
+
116
+ EventMachine_t *MyEventMachine;
117
+ };
118
+
119
+
120
+
121
+ /*************************
122
+ class LoopbreakDescriptor
123
+ *************************/
124
+
125
+ class LoopbreakDescriptor: public EventableDescriptor
126
+ {
127
+ public:
128
+ LoopbreakDescriptor (int, EventMachine_t*);
129
+ virtual ~LoopbreakDescriptor() {}
130
+
131
+ virtual void Read();
132
+ virtual void Write();
133
+ virtual void Heartbeat() {}
134
+
135
+ virtual bool SelectForRead() {return true;}
136
+ virtual bool SelectForWrite() {return false;}
137
+ };
138
+
139
+
140
+ /**************************
141
+ class ConnectionDescriptor
142
+ **************************/
143
+
144
+ class ConnectionDescriptor: public EventableDescriptor
145
+ {
146
+ public:
147
+ ConnectionDescriptor (int, EventMachine_t*);
148
+ virtual ~ConnectionDescriptor();
149
+
150
+ static int SendDataToConnection (const char*, const char*, int);
151
+ static void CloseConnection (const char*, bool);
152
+ static int ReportErrorStatus (const char*);
153
+
154
+ int SendOutboundData (const char*, int);
155
+
156
+ void SetConnectPending (bool f);
157
+
158
+ void SetNotifyReadable (bool);
159
+ void SetNotifyWritable (bool);
160
+
161
+ virtual void Read();
162
+ virtual void Write();
163
+ virtual void Heartbeat();
164
+
165
+ virtual bool SelectForRead();
166
+ virtual bool SelectForWrite();
167
+
168
+ // Do we have any data to write? This is used by ShouldDelete.
169
+ virtual int GetOutboundDataSize() {return OutboundDataSize;}
170
+
171
+ virtual void StartTls();
172
+ virtual void SetTlsParms (const char *privkey_filename, const char *certchain_filename, bool verify_peer);
173
+
174
+ #ifdef WITH_SSL
175
+ virtual X509 *GetPeerCert();
176
+ virtual bool VerifySslPeer(const char*);
177
+ virtual void AcceptSslPeer();
178
+ #endif
179
+
180
+ void SetServerMode() {bIsServer = true;}
181
+
182
+ virtual bool GetPeername (struct sockaddr*);
183
+ virtual bool GetSockname (struct sockaddr*);
184
+
185
+ virtual float GetCommInactivityTimeout();
186
+ virtual int SetCommInactivityTimeout (float value);
187
+
188
+
189
+ protected:
190
+ struct OutboundPage {
191
+ OutboundPage (const char *b, int l, int o=0): Buffer(b), Length(l), Offset(o) {}
192
+ void Free() {if (Buffer) free ((char*)Buffer); }
193
+ const char *Buffer;
194
+ int Length;
195
+ int Offset;
196
+ };
197
+
198
+ protected:
199
+ bool bConnectPending;
200
+
201
+ bool bNotifyReadable;
202
+ bool bNotifyWritable;
203
+
204
+ bool bReadAttemptedAfterClose;
205
+ bool bWriteAttemptedAfterClose;
206
+
207
+ deque<OutboundPage> OutboundPages;
208
+ int OutboundDataSize;
209
+
210
+ #ifdef WITH_SSL
211
+ SslBox_t *SslBox;
212
+ std::string CertChainFilename;
213
+ std::string PrivateKeyFilename;
214
+ bool bHandshakeSignaled;
215
+ bool bSslVerifyPeer;
216
+ bool bSslPeerAccepted;
217
+ #endif
218
+ bool bIsServer;
219
+
220
+ #ifdef HAVE_KQUEUE
221
+ bool bGotExtraKqueueEvent;
222
+ #endif
223
+
224
+ Int64 LastIo;
225
+ int InactivityTimeout;
226
+
227
+ private:
228
+ void _WriteOutboundData();
229
+ void _DispatchInboundData (const char *buffer, int size);
230
+ void _DispatchCiphertext();
231
+ int _SendRawOutboundData (const char*, int);
232
+ int _ReportErrorStatus();
233
+ void _CheckHandshakeStatus();
234
+
235
+ };
236
+
237
+
238
+ /************************
239
+ class DatagramDescriptor
240
+ ************************/
241
+
242
+ class DatagramDescriptor: public EventableDescriptor
243
+ {
244
+ public:
245
+ DatagramDescriptor (int, EventMachine_t*);
246
+ virtual ~DatagramDescriptor();
247
+
248
+ virtual void Read();
249
+ virtual void Write();
250
+ virtual void Heartbeat();
251
+
252
+ virtual bool SelectForRead() {return true;}
253
+ virtual bool SelectForWrite();
254
+
255
+ int SendOutboundData (const char*, int);
256
+ int SendOutboundDatagram (const char*, int, const char*, int);
257
+
258
+ // Do we have any data to write? This is used by ShouldDelete.
259
+ virtual int GetOutboundDataSize() {return OutboundDataSize;}
260
+
261
+ virtual bool GetPeername (struct sockaddr*);
262
+ virtual bool GetSockname (struct sockaddr*);
263
+
264
+ virtual float GetCommInactivityTimeout();
265
+ virtual int SetCommInactivityTimeout (float value);
266
+
267
+ static int SendDatagram (const char*, const char*, int, const char*, int);
268
+
269
+
270
+ protected:
271
+ struct OutboundPage {
272
+ OutboundPage (const char *b, int l, struct sockaddr_in f, int o=0): Buffer(b), Length(l), Offset(o), From(f) {}
273
+ void Free() {if (Buffer) free ((char*)Buffer); }
274
+ const char *Buffer;
275
+ int Length;
276
+ int Offset;
277
+ struct sockaddr_in From;
278
+ };
279
+
280
+ deque<OutboundPage> OutboundPages;
281
+ int OutboundDataSize;
282
+
283
+ struct sockaddr_in ReturnAddress;
284
+
285
+ Int64 LastIo;
286
+ int InactivityTimeout;
287
+ };
288
+
289
+
290
+ /************************
291
+ class AcceptorDescriptor
292
+ ************************/
293
+
294
+ class AcceptorDescriptor: public EventableDescriptor
295
+ {
296
+ public:
297
+ AcceptorDescriptor (int, EventMachine_t*);
298
+ virtual ~AcceptorDescriptor();
299
+
300
+ virtual void Read();
301
+ virtual void Write();
302
+ virtual void Heartbeat();
303
+
304
+ virtual bool SelectForRead() {return true;}
305
+ virtual bool SelectForWrite() {return false;}
306
+
307
+ virtual bool GetSockname (struct sockaddr*);
308
+
309
+ static void StopAcceptor (const char *binding);
310
+ };
311
+
312
+ /********************
313
+ class PipeDescriptor
314
+ ********************/
315
+
316
+ #ifdef OS_UNIX
317
+ class PipeDescriptor: public EventableDescriptor
318
+ {
319
+ public:
320
+ PipeDescriptor (int, pid_t, EventMachine_t*);
321
+ virtual ~PipeDescriptor();
322
+
323
+ virtual void Read();
324
+ virtual void Write();
325
+ virtual void Heartbeat();
326
+
327
+ virtual bool SelectForRead();
328
+ virtual bool SelectForWrite();
329
+
330
+ int SendOutboundData (const char*, int);
331
+ virtual int GetOutboundDataSize() {return OutboundDataSize;}
332
+
333
+ virtual bool GetSubprocessPid (pid_t*);
334
+
335
+ protected:
336
+ struct OutboundPage {
337
+ OutboundPage (const char *b, int l, int o=0): Buffer(b), Length(l), Offset(o) {}
338
+ void Free() {if (Buffer) free ((char*)Buffer); }
339
+ const char *Buffer;
340
+ int Length;
341
+ int Offset;
342
+ };
343
+
344
+ protected:
345
+ bool bReadAttemptedAfterClose;
346
+ Int64 LastIo;
347
+ int InactivityTimeout;
348
+
349
+ deque<OutboundPage> OutboundPages;
350
+ int OutboundDataSize;
351
+
352
+ pid_t SubprocessPid;
353
+
354
+ private:
355
+ void _DispatchInboundData (const char *buffer, int size);
356
+ };
357
+ #endif // OS_UNIX
358
+
359
+
360
+ /************************
361
+ class KeyboardDescriptor
362
+ ************************/
363
+
364
+ class KeyboardDescriptor: public EventableDescriptor
365
+ {
366
+ public:
367
+ KeyboardDescriptor (EventMachine_t*);
368
+ virtual ~KeyboardDescriptor();
369
+
370
+ virtual void Read();
371
+ virtual void Write();
372
+ virtual void Heartbeat();
373
+
374
+ virtual bool SelectForRead() {return true;}
375
+ virtual bool SelectForWrite() {return false;}
376
+
377
+ protected:
378
+ bool bReadAttemptedAfterClose;
379
+ Int64 LastIo;
380
+ int InactivityTimeout;
381
+
382
+ private:
383
+ void _DispatchInboundData (const char *buffer, int size);
384
+ };
385
+
386
+
387
+ /***********************
388
+ class InotifyDescriptor
389
+ ************************/
390
+
391
+ class InotifyDescriptor: public EventableDescriptor
392
+ {
393
+ public:
394
+ InotifyDescriptor (EventMachine_t*);
395
+ virtual ~InotifyDescriptor();
396
+
397
+ void Read();
398
+ void Write();
399
+
400
+ virtual void Heartbeat() {}
401
+ virtual bool SelectForRead() {return true;}
402
+ virtual bool SelectForWrite() {return false;}
403
+ };
404
+
405
+ #endif // __EventableDescriptor__H_
406
+
407
+