libc-eventmachine 0.12.5.42

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. data/Rakefile +195 -0
  2. data/docs/COPYING +60 -0
  3. data/docs/ChangeLog +211 -0
  4. data/docs/DEFERRABLES +138 -0
  5. data/docs/EPOLL +141 -0
  6. data/docs/GNU +281 -0
  7. data/docs/INSTALL +15 -0
  8. data/docs/KEYBOARD +38 -0
  9. data/docs/LEGAL +25 -0
  10. data/docs/LIGHTWEIGHT_CONCURRENCY +72 -0
  11. data/docs/PURE_RUBY +77 -0
  12. data/docs/README +74 -0
  13. data/docs/RELEASE_NOTES +96 -0
  14. data/docs/SMTP +9 -0
  15. data/docs/SPAWNED_PROCESSES +93 -0
  16. data/docs/TODO +10 -0
  17. data/ext/binder.cpp +126 -0
  18. data/ext/binder.h +48 -0
  19. data/ext/cmain.cpp +582 -0
  20. data/ext/cplusplus.cpp +177 -0
  21. data/ext/ed.cpp +1522 -0
  22. data/ext/ed.h +380 -0
  23. data/ext/em.cpp +1947 -0
  24. data/ext/em.h +186 -0
  25. data/ext/emwin.cpp +300 -0
  26. data/ext/emwin.h +94 -0
  27. data/ext/epoll.cpp +26 -0
  28. data/ext/epoll.h +25 -0
  29. data/ext/eventmachine.h +98 -0
  30. data/ext/eventmachine_cpp.h +96 -0
  31. data/ext/extconf.rb +129 -0
  32. data/ext/fastfilereader/extconf.rb +77 -0
  33. data/ext/fastfilereader/mapper.cpp +214 -0
  34. data/ext/fastfilereader/mapper.h +59 -0
  35. data/ext/fastfilereader/rubymain.cpp +127 -0
  36. data/ext/files.cpp +94 -0
  37. data/ext/files.h +65 -0
  38. data/ext/kb.cpp +82 -0
  39. data/ext/page.cpp +107 -0
  40. data/ext/page.h +51 -0
  41. data/ext/pipe.cpp +351 -0
  42. data/ext/project.h +119 -0
  43. data/ext/rubymain.cpp +858 -0
  44. data/ext/sigs.cpp +89 -0
  45. data/ext/sigs.h +32 -0
  46. data/ext/ssl.cpp +423 -0
  47. data/ext/ssl.h +90 -0
  48. data/java/src/com/rubyeventmachine/Application.java +196 -0
  49. data/java/src/com/rubyeventmachine/Connection.java +74 -0
  50. data/java/src/com/rubyeventmachine/ConnectionFactory.java +37 -0
  51. data/java/src/com/rubyeventmachine/DefaultConnectionFactory.java +46 -0
  52. data/java/src/com/rubyeventmachine/EmReactor.java +408 -0
  53. data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
  54. data/java/src/com/rubyeventmachine/EventableChannel.java +57 -0
  55. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +171 -0
  56. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +244 -0
  57. data/java/src/com/rubyeventmachine/PeriodicTimer.java +38 -0
  58. data/java/src/com/rubyeventmachine/Timer.java +54 -0
  59. data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +108 -0
  60. data/java/src/com/rubyeventmachine/tests/ConnectTest.java +124 -0
  61. data/java/src/com/rubyeventmachine/tests/EMTest.java +80 -0
  62. data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +53 -0
  63. data/java/src/com/rubyeventmachine/tests/TestServers.java +74 -0
  64. data/java/src/com/rubyeventmachine/tests/TestTimers.java +89 -0
  65. data/lib/em/deferrable.rb +208 -0
  66. data/lib/em/eventable.rb +39 -0
  67. data/lib/em/future.rb +62 -0
  68. data/lib/em/messages.rb +66 -0
  69. data/lib/em/processes.rb +68 -0
  70. data/lib/em/spawnable.rb +88 -0
  71. data/lib/em/streamer.rb +112 -0
  72. data/lib/eventmachine.rb +1920 -0
  73. data/lib/eventmachine_version.rb +31 -0
  74. data/lib/evma/callback.rb +32 -0
  75. data/lib/evma/container.rb +75 -0
  76. data/lib/evma/factory.rb +77 -0
  77. data/lib/evma/protocol.rb +87 -0
  78. data/lib/evma/reactor.rb +48 -0
  79. data/lib/evma.rb +32 -0
  80. data/lib/jeventmachine.rb +140 -0
  81. data/lib/pr_eventmachine.rb +1017 -0
  82. data/lib/protocols/buftok.rb +127 -0
  83. data/lib/protocols/header_and_content.rb +129 -0
  84. data/lib/protocols/httpcli2.rb +803 -0
  85. data/lib/protocols/httpclient.rb +270 -0
  86. data/lib/protocols/line_and_text.rb +126 -0
  87. data/lib/protocols/linetext2.rb +161 -0
  88. data/lib/protocols/memcache.rb +293 -0
  89. data/lib/protocols/postgres.rb +261 -0
  90. data/lib/protocols/saslauth.rb +179 -0
  91. data/lib/protocols/smtpclient.rb +308 -0
  92. data/lib/protocols/smtpserver.rb +556 -0
  93. data/lib/protocols/stomp.rb +153 -0
  94. data/lib/protocols/tcptest.rb +57 -0
  95. data/tasks/cpp.rake +77 -0
  96. data/tasks/project.rake +78 -0
  97. data/tasks/tests.rake +193 -0
  98. data/tests/test_attach.rb +83 -0
  99. data/tests/test_basic.rb +231 -0
  100. data/tests/test_bind.rb +73 -0
  101. data/tests/test_connection_count.rb +35 -0
  102. data/tests/test_defer.rb +47 -0
  103. data/tests/test_epoll.rb +163 -0
  104. data/tests/test_error_handler.rb +32 -0
  105. data/tests/test_errors.rb +82 -0
  106. data/tests/test_eventables.rb +77 -0
  107. data/tests/test_exc.rb +58 -0
  108. data/tests/test_futures.rb +214 -0
  109. data/tests/test_handler_check.rb +37 -0
  110. data/tests/test_hc.rb +218 -0
  111. data/tests/test_httpclient.rb +215 -0
  112. data/tests/test_httpclient2.rb +155 -0
  113. data/tests/test_kb.rb +61 -0
  114. data/tests/test_ltp.rb +188 -0
  115. data/tests/test_ltp2.rb +320 -0
  116. data/tests/test_next_tick.rb +109 -0
  117. data/tests/test_processes.rb +56 -0
  118. data/tests/test_pure.rb +129 -0
  119. data/tests/test_running.rb +47 -0
  120. data/tests/test_sasl.rb +74 -0
  121. data/tests/test_send_file.rb +243 -0
  122. data/tests/test_servers.rb +80 -0
  123. data/tests/test_smtpclient.rb +83 -0
  124. data/tests/test_smtpserver.rb +93 -0
  125. data/tests/test_spawn.rb +329 -0
  126. data/tests/test_ssl_args.rb +68 -0
  127. data/tests/test_ssl_methods.rb +50 -0
  128. data/tests/test_timers.rb +148 -0
  129. data/tests/test_ud.rb +43 -0
  130. data/tests/testem.rb +31 -0
  131. metadata +230 -0
data/ext/ed.h ADDED
@@ -0,0 +1,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) {}
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
+