smparkes-eventmachine 0.12.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. data/.gitignore +15 -0
  2. data/README +81 -0
  3. data/Rakefile +374 -0
  4. data/docs/COPYING +60 -0
  5. data/docs/ChangeLog +211 -0
  6. data/docs/DEFERRABLES +133 -0
  7. data/docs/EPOLL +141 -0
  8. data/docs/GNU +281 -0
  9. data/docs/INSTALL +13 -0
  10. data/docs/KEYBOARD +38 -0
  11. data/docs/LEGAL +25 -0
  12. data/docs/LIGHTWEIGHT_CONCURRENCY +70 -0
  13. data/docs/PURE_RUBY +75 -0
  14. data/docs/RELEASE_NOTES +94 -0
  15. data/docs/SMTP +2 -0
  16. data/docs/SPAWNED_PROCESSES +89 -0
  17. data/docs/TODO +8 -0
  18. data/eventmachine.gemspec +40 -0
  19. data/examples/ex_channel.rb +43 -0
  20. data/examples/ex_queue.rb +2 -0
  21. data/examples/helper.rb +2 -0
  22. data/ext/binder.cpp +125 -0
  23. data/ext/binder.h +46 -0
  24. data/ext/cmain.cpp +827 -0
  25. data/ext/cplusplus.cpp +202 -0
  26. data/ext/ed.cpp +1901 -0
  27. data/ext/ed.h +424 -0
  28. data/ext/em.cpp +2288 -0
  29. data/ext/em.h +229 -0
  30. data/ext/emwin.cpp +300 -0
  31. data/ext/emwin.h +94 -0
  32. data/ext/epoll.cpp +26 -0
  33. data/ext/epoll.h +25 -0
  34. data/ext/eventmachine.h +122 -0
  35. data/ext/eventmachine_cpp.h +96 -0
  36. data/ext/extconf.rb +150 -0
  37. data/ext/fastfilereader/extconf.rb +85 -0
  38. data/ext/fastfilereader/mapper.cpp +214 -0
  39. data/ext/fastfilereader/mapper.h +59 -0
  40. data/ext/fastfilereader/rubymain.cpp +127 -0
  41. data/ext/files.cpp +94 -0
  42. data/ext/files.h +65 -0
  43. data/ext/kb.cpp +81 -0
  44. data/ext/page.cpp +107 -0
  45. data/ext/page.h +51 -0
  46. data/ext/pipe.cpp +349 -0
  47. data/ext/project.h +156 -0
  48. data/ext/rubymain.cpp +1194 -0
  49. data/ext/sigs.cpp +89 -0
  50. data/ext/sigs.h +32 -0
  51. data/ext/ssl.cpp +460 -0
  52. data/ext/ssl.h +94 -0
  53. data/java/.classpath +8 -0
  54. data/java/.project +17 -0
  55. data/java/src/com/rubyeventmachine/EmReactor.java +570 -0
  56. data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
  57. data/java/src/com/rubyeventmachine/EventableChannel.java +69 -0
  58. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +189 -0
  59. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +364 -0
  60. data/java/src/com/rubyeventmachine/application/Application.java +194 -0
  61. data/java/src/com/rubyeventmachine/application/Connection.java +74 -0
  62. data/java/src/com/rubyeventmachine/application/ConnectionFactory.java +37 -0
  63. data/java/src/com/rubyeventmachine/application/DefaultConnectionFactory.java +46 -0
  64. data/java/src/com/rubyeventmachine/application/PeriodicTimer.java +38 -0
  65. data/java/src/com/rubyeventmachine/application/Timer.java +54 -0
  66. data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +109 -0
  67. data/java/src/com/rubyeventmachine/tests/ConnectTest.java +148 -0
  68. data/java/src/com/rubyeventmachine/tests/EMTest.java +80 -0
  69. data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +53 -0
  70. data/java/src/com/rubyeventmachine/tests/TestServers.java +75 -0
  71. data/java/src/com/rubyeventmachine/tests/TestTimers.java +90 -0
  72. data/lib/em/buftok.rb +138 -0
  73. data/lib/em/callback.rb +26 -0
  74. data/lib/em/channel.rb +57 -0
  75. data/lib/em/connection.rb +564 -0
  76. data/lib/em/deferrable.rb +192 -0
  77. data/lib/em/file_watch.rb +54 -0
  78. data/lib/em/future.rb +61 -0
  79. data/lib/em/messages.rb +66 -0
  80. data/lib/em/process_watch.rb +44 -0
  81. data/lib/em/processes.rb +119 -0
  82. data/lib/em/protocols/header_and_content.rb +138 -0
  83. data/lib/em/protocols/httpclient.rb +263 -0
  84. data/lib/em/protocols/httpclient2.rb +590 -0
  85. data/lib/em/protocols/line_and_text.rb +125 -0
  86. data/lib/em/protocols/linetext2.rb +161 -0
  87. data/lib/em/protocols/memcache.rb +323 -0
  88. data/lib/em/protocols/object_protocol.rb +45 -0
  89. data/lib/em/protocols/postgres3.rb +247 -0
  90. data/lib/em/protocols/saslauth.rb +175 -0
  91. data/lib/em/protocols/smtpclient.rb +357 -0
  92. data/lib/em/protocols/smtpserver.rb +547 -0
  93. data/lib/em/protocols/socks4.rb +66 -0
  94. data/lib/em/protocols/stomp.rb +200 -0
  95. data/lib/em/protocols/tcptest.rb +53 -0
  96. data/lib/em/protocols.rb +36 -0
  97. data/lib/em/queue.rb +61 -0
  98. data/lib/em/spawnable.rb +85 -0
  99. data/lib/em/streamer.rb +130 -0
  100. data/lib/em/timers.rb +56 -0
  101. data/lib/em/version.rb +3 -0
  102. data/lib/eventmachine.rb +1592 -0
  103. data/lib/evma/callback.rb +32 -0
  104. data/lib/evma/container.rb +75 -0
  105. data/lib/evma/factory.rb +77 -0
  106. data/lib/evma/protocol.rb +87 -0
  107. data/lib/evma/reactor.rb +48 -0
  108. data/lib/evma.rb +32 -0
  109. data/lib/jeventmachine.rb +257 -0
  110. data/lib/pr_eventmachine.rb +1022 -0
  111. data/setup.rb +1585 -0
  112. data/tasks/cpp.rake_example +77 -0
  113. data/tests/client.crt +31 -0
  114. data/tests/client.key +51 -0
  115. data/tests/test_attach.rb +126 -0
  116. data/tests/test_basic.rb +284 -0
  117. data/tests/test_channel.rb +63 -0
  118. data/tests/test_connection_count.rb +35 -0
  119. data/tests/test_defer.rb +47 -0
  120. data/tests/test_epoll.rb +160 -0
  121. data/tests/test_error_handler.rb +35 -0
  122. data/tests/test_errors.rb +82 -0
  123. data/tests/test_exc.rb +55 -0
  124. data/tests/test_file_watch.rb +49 -0
  125. data/tests/test_futures.rb +198 -0
  126. data/tests/test_get_sock_opt.rb +30 -0
  127. data/tests/test_handler_check.rb +37 -0
  128. data/tests/test_hc.rb +218 -0
  129. data/tests/test_httpclient.rb +218 -0
  130. data/tests/test_httpclient2.rb +153 -0
  131. data/tests/test_inactivity_timeout.rb +50 -0
  132. data/tests/test_kb.rb +60 -0
  133. data/tests/test_ltp.rb +182 -0
  134. data/tests/test_ltp2.rb +317 -0
  135. data/tests/test_next_tick.rb +133 -0
  136. data/tests/test_object_protocol.rb +37 -0
  137. data/tests/test_pause.rb +70 -0
  138. data/tests/test_pending_connect_timeout.rb +48 -0
  139. data/tests/test_process_watch.rb +48 -0
  140. data/tests/test_processes.rb +128 -0
  141. data/tests/test_proxy_connection.rb +92 -0
  142. data/tests/test_pure.rb +125 -0
  143. data/tests/test_queue.rb +44 -0
  144. data/tests/test_running.rb +42 -0
  145. data/tests/test_sasl.rb +72 -0
  146. data/tests/test_send_file.rb +242 -0
  147. data/tests/test_servers.rb +76 -0
  148. data/tests/test_smtpclient.rb +83 -0
  149. data/tests/test_smtpserver.rb +85 -0
  150. data/tests/test_spawn.rb +322 -0
  151. data/tests/test_ssl_args.rb +79 -0
  152. data/tests/test_ssl_methods.rb +50 -0
  153. data/tests/test_ssl_verify.rb +82 -0
  154. data/tests/test_timers.rb +162 -0
  155. data/tests/test_ud.rb +36 -0
  156. data/tests/testem.rb +31 -0
  157. data/web/whatis +7 -0
  158. metadata +237 -0
data/docs/GNU ADDED
@@ -0,0 +1,281 @@
1
+ .
2
+
3
+ GNU GENERAL PUBLIC LICENSE
4
+ Version 2, June 1991
5
+
6
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
7
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
8
+ Everyone is permitted to copy and distribute verbatim copies
9
+ of this license document, but changing it is not allowed.
10
+
11
+ Preamble
12
+
13
+ The licenses for most software are designed to take away your
14
+ freedom to share and change it. By contrast, the GNU General Public
15
+ License is intended to guarantee your freedom to share and change free
16
+ software--to make sure the software is free for all its users. This
17
+ General Public License applies to most of the Free Software
18
+ Foundation's software and to any other program whose authors commit to
19
+ using it. (Some other Free Software Foundation software is covered by
20
+ the GNU Lesser General Public License instead.) You can apply it to
21
+ your programs, too.
22
+
23
+ When we speak of free software, we are referring to freedom, not
24
+ price. Our General Public Licenses are designed to make sure that you
25
+ have the freedom to distribute copies of free software (and charge for
26
+ this service if you wish), that you receive source code or can get it
27
+ if you want it, that you can change the software or use pieces of it
28
+ in new free programs; and that you know you can do these things.
29
+
30
+ To protect your rights, we need to make restrictions that forbid
31
+ anyone to deny you these rights or to ask you to surrender the rights.
32
+ These restrictions translate to certain responsibilities for you if you
33
+ distribute copies of the software, or if you modify it.
34
+
35
+ For example, if you distribute copies of such a program, whether
36
+ gratis or for a fee, you must give the recipients all the rights that
37
+ you have. You must make sure that they, too, receive or can get the
38
+ source code. And you must show them these terms so they know their
39
+ rights.
40
+
41
+ We protect your rights with two steps: (1) copyright the software, and
42
+ (2) offer you this license which gives you legal permission to copy,
43
+ distribute and/or modify the software.
44
+
45
+ Also, for each author's protection and ours, we want to make certain
46
+ that everyone understands that there is no warranty for this free
47
+ software. If the software is modified by someone else and passed on, we
48
+ want its recipients to know that what they have is not the original, so
49
+ that any problems introduced by others will not reflect on the original
50
+ authors' reputations.
51
+
52
+ Finally, any free program is threatened constantly by software
53
+ patents. We wish to avoid the danger that redistributors of a free
54
+ program will individually obtain patent licenses, in effect making the
55
+ program proprietary. To prevent this, we have made it clear that any
56
+ patent must be licensed for everyone's free use or not licensed at all.
57
+
58
+ The precise terms and conditions for copying, distribution and
59
+ modification follow.
60
+
61
+ GNU GENERAL PUBLIC LICENSE
62
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
63
+
64
+ 0. This License applies to any program or other work which contains
65
+ a notice placed by the copyright holder saying it may be distributed
66
+ under the terms of this General Public License. The "Program", below,
67
+ refers to any such program or work, and a "work based on the Program"
68
+ means either the Program or any derivative work under copyright law:
69
+ that is to say, a work containing the Program or a portion of it,
70
+ either verbatim or with modifications and/or translated into another
71
+ language. (Hereinafter, translation is included without limitation in
72
+ the term "modification".) Each licensee is addressed as "you".
73
+
74
+ Activities other than copying, distribution and modification are not
75
+ covered by this License; they are outside its scope. The act of
76
+ running the Program is not restricted, and the output from the Program
77
+ is covered only if its contents constitute a work based on the
78
+ Program (independent of having been made by running the Program).
79
+ Whether that is true depends on what the Program does.
80
+
81
+ 1. You may copy and distribute verbatim copies of the Program's
82
+ source code as you receive it, in any medium, provided that you
83
+ conspicuously and appropriately publish on each copy an appropriate
84
+ copyright notice and disclaimer of warranty; keep intact all the
85
+ notices that refer to this License and to the absence of any warranty;
86
+ and give any other recipients of the Program a copy of this License
87
+ along with the Program.
88
+
89
+ You may charge a fee for the physical act of transferring a copy, and
90
+ you may at your option offer warranty protection in exchange for a fee.
91
+
92
+ 2. You may modify your copy or copies of the Program or any portion
93
+ of it, thus forming a work based on the Program, and copy and
94
+ distribute such modifications or work under the terms of Section 1
95
+ above, provided that you also meet all of these conditions:
96
+
97
+ a) You must cause the modified files to carry prominent notices
98
+ stating that you changed the files and the date of any change.
99
+
100
+ b) You must cause any work that you distribute or publish, that in
101
+ whole or in part contains or is derived from the Program or any
102
+ part thereof, to be licensed as a whole at no charge to all third
103
+ parties under the terms of this License.
104
+
105
+ c) If the modified program normally reads commands interactively
106
+ when run, you must cause it, when started running for such
107
+ interactive use in the most ordinary way, to print or display an
108
+ announcement including an appropriate copyright notice and a
109
+ notice that there is no warranty (or else, saying that you provide
110
+ a warranty) and that users may redistribute the program under
111
+ these conditions, and telling the user how to view a copy of this
112
+ License. (Exception: if the Program itself is interactive but
113
+ does not normally print such an announcement, your work based on
114
+ the Program is not required to print an announcement.)
115
+
116
+ These requirements apply to the modified work as a whole. If
117
+ identifiable sections of that work are not derived from the Program,
118
+ and can be reasonably considered independent and separate works in
119
+ themselves, then this License, and its terms, do not apply to those
120
+ sections when you distribute them as separate works. But when you
121
+ distribute the same sections as part of a whole which is a work based
122
+ on the Program, the distribution of the whole must be on the terms of
123
+ this License, whose permissions for other licensees extend to the
124
+ entire whole, and thus to each and every part regardless of who wrote it.
125
+
126
+ Thus, it is not the intent of this section to claim rights or contest
127
+ your rights to work written entirely by you; rather, the intent is to
128
+ exercise the right to control the distribution of derivative or
129
+ collective works based on the Program.
130
+
131
+ In addition, mere aggregation of another work not based on the Program
132
+ with the Program (or with a work based on the Program) on a volume of
133
+ a storage or distribution medium does not bring the other work under
134
+ the scope of this License.
135
+
136
+ 3. You may copy and distribute the Program (or a work based on it,
137
+ under Section 2) in object code or executable form under the terms of
138
+ Sections 1 and 2 above provided that you also do one of the following:
139
+
140
+ a) Accompany it with the complete corresponding machine-readable
141
+ source code, which must be distributed under the terms of Sections
142
+ 1 and 2 above on a medium customarily used for software interchange; or,
143
+
144
+ b) Accompany it with a written offer, valid for at least three
145
+ years, to give any third party, for a charge no more than your
146
+ cost of physically performing source distribution, a complete
147
+ machine-readable copy of the corresponding source code, to be
148
+ distributed under the terms of Sections 1 and 2 above on a medium
149
+ customarily used for software interchange; or,
150
+
151
+ c) Accompany it with the information you received as to the offer
152
+ to distribute corresponding source code. (This alternative is
153
+ allowed only for noncommercial distribution and only if you
154
+ received the program in object code or executable form with such
155
+ an offer, in accord with Subsection b above.)
156
+
157
+ The source code for a work means the preferred form of the work for
158
+ making modifications to it. For an executable work, complete source
159
+ code means all the source code for all modules it contains, plus any
160
+ associated interface definition files, plus the scripts used to
161
+ control compilation and installation of the executable. However, as a
162
+ special exception, the source code distributed need not include
163
+ anything that is normally distributed (in either source or binary
164
+ form) with the major components (compiler, kernel, and so on) of the
165
+ operating system on which the executable runs, unless that component
166
+ itself accompanies the executable.
167
+
168
+ If distribution of executable or object code is made by offering
169
+ access to copy from a designated place, then offering equivalent
170
+ access to copy the source code from the same place counts as
171
+ distribution of the source code, even though third parties are not
172
+ compelled to copy the source along with the object code.
173
+
174
+ 4. You may not copy, modify, sublicense, or distribute the Program
175
+ except as expressly provided under this License. Any attempt
176
+ otherwise to copy, modify, sublicense or distribute the Program is
177
+ void, and will automatically terminate your rights under this License.
178
+ However, parties who have received copies, or rights, from you under
179
+ this License will not have their licenses terminated so long as such
180
+ parties remain in full compliance.
181
+
182
+ 5. You are not required to accept this License, since you have not
183
+ signed it. However, nothing else grants you permission to modify or
184
+ distribute the Program or its derivative works. These actions are
185
+ prohibited by law if you do not accept this License. Therefore, by
186
+ modifying or distributing the Program (or any work based on the
187
+ Program), you indicate your acceptance of this License to do so, and
188
+ all its terms and conditions for copying, distributing or modifying
189
+ the Program or works based on it.
190
+
191
+ 6. Each time you redistribute the Program (or any work based on the
192
+ Program), the recipient automatically receives a license from the
193
+ original licensor to copy, distribute or modify the Program subject to
194
+ these terms and conditions. You may not impose any further
195
+ restrictions on the recipients' exercise of the rights granted herein.
196
+ You are not responsible for enforcing compliance by third parties to
197
+ this License.
198
+
199
+ 7. If, as a consequence of a court judgment or allegation of patent
200
+ infringement or for any other reason (not limited to patent issues),
201
+ conditions are imposed on you (whether by court order, agreement or
202
+ otherwise) that contradict the conditions of this License, they do not
203
+ excuse you from the conditions of this License. If you cannot
204
+ distribute so as to satisfy simultaneously your obligations under this
205
+ License and any other pertinent obligations, then as a consequence you
206
+ may not distribute the Program at all. For example, if a patent
207
+ license would not permit royalty-free redistribution of the Program by
208
+ all those who receive copies directly or indirectly through you, then
209
+ the only way you could satisfy both it and this License would be to
210
+ refrain entirely from distribution of the Program.
211
+
212
+ If any portion of this section is held invalid or unenforceable under
213
+ any particular circumstance, the balance of the section is intended to
214
+ apply and the section as a whole is intended to apply in other
215
+ circumstances.
216
+
217
+ It is not the purpose of this section to induce you to infringe any
218
+ patents or other property right claims or to contest validity of any
219
+ such claims; this section has the sole purpose of protecting the
220
+ integrity of the free software distribution system, which is
221
+ implemented by public license practices. Many people have made
222
+ generous contributions to the wide range of software distributed
223
+ through that system in reliance on consistent application of that
224
+ system; it is up to the author/donor to decide if he or she is willing
225
+ to distribute software through any other system and a licensee cannot
226
+ impose that choice.
227
+
228
+ This section is intended to make thoroughly clear what is believed to
229
+ be a consequence of the rest of this License.
230
+
231
+ 8. If the distribution and/or use of the Program is restricted in
232
+ certain countries either by patents or by copyrighted interfaces, the
233
+ original copyright holder who places the Program under this License
234
+ may add an explicit geographical distribution limitation excluding
235
+ those countries, so that distribution is permitted only in or among
236
+ countries not thus excluded. In such case, this License incorporates
237
+ the limitation as if written in the body of this License.
238
+
239
+ 9. The Free Software Foundation may publish revised and/or new versions
240
+ of the General Public License from time to time. Such new versions will
241
+ be similar in spirit to the present version, but may differ in detail to
242
+ address new problems or concerns.
243
+
244
+ Each version is given a distinguishing version number. If the Program
245
+ specifies a version number of this License which applies to it and "any
246
+ later version", you have the option of following the terms and conditions
247
+ either of that version or of any later version published by the Free
248
+ Software Foundation. If the Program does not specify a version number of
249
+ this License, you may choose any version ever published by the Free Software
250
+ Foundation.
251
+
252
+ 10. If you wish to incorporate parts of the Program into other free
253
+ programs whose distribution conditions are different, write to the author
254
+ to ask for permission. For software which is copyrighted by the Free
255
+ Software Foundation, write to the Free Software Foundation; we sometimes
256
+ make exceptions for this. Our decision will be guided by the two goals
257
+ of preserving the free status of all derivatives of our free software and
258
+ of promoting the sharing and reuse of software generally.
259
+
260
+ NO WARRANTY
261
+
262
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
263
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
264
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
265
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
266
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
267
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
268
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
269
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
270
+ REPAIR OR CORRECTION.
271
+
272
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
273
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
274
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
275
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
276
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
277
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
278
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
279
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
280
+ POSSIBILITY OF SUCH DAMAGES.
281
+
data/docs/INSTALL ADDED
@@ -0,0 +1,13 @@
1
+ If you have obtained an EventMachine source-tarball (.tar.gz):
2
+ unzip and untar the tarball, and enter the directory that is
3
+ created. In that directory, say:
4
+ ruby setup.rb
5
+ (You may need to be root to execute this command.)
6
+
7
+ To create documentation for EventMachine, simply type:
8
+ rake rdoc
9
+ in the distro directory. Rdocs will be created in subdirectory rdoc.
10
+
11
+ If you have obtained a gem version of EventMachine, install it in the
12
+ usual way (gem install eventmachine). You may need superuser privileges
13
+ to execute this command.
data/docs/KEYBOARD ADDED
@@ -0,0 +1,38 @@
1
+ EventMachine (EM) can respond to keyboard events. This gives your event-driven programs the ability to respond to input from local users.
2
+
3
+ Programming EM to handle keyboard input in Ruby is simplicity itself. Just use EventMachine#open_keyboard, and supply the name of a Ruby module or class that will receive the input:
4
+
5
+ require 'rubygems'
6
+ require 'eventmachine'
7
+
8
+ module MyKeyboardHandler
9
+ def receive_data keystrokes
10
+ puts "I received the following data from the keyboard: #{keystrokes}"
11
+ end
12
+ end
13
+
14
+ EM.run {
15
+ EM.open_keyboard(MyKeyboardHandler)
16
+ }
17
+
18
+
19
+ If you want EM to send line-buffered keyboard input to your program, just include the LineText2 protocol module in your handler class or module:
20
+
21
+
22
+
23
+ require 'rubygems'
24
+ require 'eventmachine'
25
+
26
+ module MyKeyboardHandler
27
+ include EM::Protocols::LineText2
28
+ def receive_line data
29
+ puts "I received the following line from the keyboard: #{data}"
30
+ end
31
+ end
32
+
33
+ EM.run {
34
+ EM.open_keyboard(MyKeyboardHandler)
35
+ }
36
+
37
+ As we said, simplicity itself. You can call EventMachine#open_keyboard at any time while the EM reactor loop is running. In other words, the method invocation may appear anywhere in an EventMachine#run block, or in any code invoked in the #run block.
38
+
data/docs/LEGAL ADDED
@@ -0,0 +1,25 @@
1
+ LEGAL NOTICE INFORMATION
2
+ ------------------------
3
+
4
+ EventMachine is Copyright (C) 2006-07 by Francis Cianfrocca.
5
+
6
+ EventMachine is copyrighted software owned by Francis Cianfrocca
7
+ (blackhedd ... gmail.com). You may redistribute and/or modify this
8
+ software as long as you comply with either the terms of the GPL
9
+ (see the file GPL), or Ruby's license (see the file COPYING).
10
+
11
+ Your use of all the files in this distribution is controlled by these
12
+ license terms, except for those files specifically mentioned below:
13
+
14
+
15
+
16
+ setup.rb
17
+ This file is Copyright (C) 2000-2005 by Minero Aoki
18
+ You can distribute/modify this file under the terms of
19
+ the GNU LGPL, Lesser General Public License version 2.1.
20
+
21
+
22
+ lib/em/buftok.rb
23
+ This file is Copyright (C) 2007 by Tony Arcieri. This file is
24
+ covered by the terms of Ruby's License (see the file COPYING).
25
+
@@ -0,0 +1,70 @@
1
+ EventMachine (EM) adds two different formalisms for lightweight concurrency to the Ruby programmer's toolbox: spawned processes and deferrables. This note will show you how to use them.
2
+
3
+
4
+ === What is Lightweight Concurrency?
5
+
6
+ We use the term "Lightweight Concurrency" (LC) to refer to concurrency mechanisms that are lighter than Ruby threads. By "lighter," we mean: less resource-intensive in one or more dimensions, usually including memory and CPU usage. In general, you turn to LC in the hope of improving the performance and scalability of your programs.
7
+
8
+ In addition to the two EventMachine mechanisms we will discuss here, Ruby has at least one other LC construct: Fibers, which are currently under development in Ruby 1.9.
9
+
10
+ The technical feature that makes all of these LC mechanisms different from standard Ruby threads is that they are not scheduled automatically.
11
+
12
+ When you create and run Ruby threads, you can assume (within certain constraints) that your threads will all be scheduled fairly by Ruby's runtime. Ruby itself is responsible for giving each of your threads its own share of the total runtime.
13
+
14
+ But with LC, your program is responsible for causing different execution paths to run. In effect, your program has to act as a "thread scheduler." Scheduled entities in LC run to completion and are never preempted. The runtime system has far less work to do since it has no need to interrupt threads or to schedule them fairly. This is what makes LC lighter and faster.
15
+
16
+ You'll learn exactly how LC scheduling works in practice as we work through specific examples.
17
+
18
+
19
+ === EventMachine Lightweight Concurrency
20
+
21
+ Recall that EM provides a reactor loop that must be running in order for your programs to perform event-driven logic. An EM program typically has a structure like this:
22
+
23
+ require 'eventmachine'
24
+
25
+ # your initializations
26
+
27
+ EM.run {
28
+ # perform event-driven I/O here, including network clients,
29
+ # servers, timers, and thread-pool operations.
30
+ }
31
+
32
+ # your cleanup
33
+ # end of the program
34
+
35
+
36
+ EventMachine#run executes the reactor loop, which causes your code to be called as events of interest to your program occur. The block you pass to EventMachine#run is executed right after the reactor loop starts, and is the right place to start socket acceptors, etc.
37
+
38
+ Because the reactor loop runs constantly in an EM program (until it is stopped by a call to EventMachine#stop), it has the ability to schedule blocks of code for asynchronous execution. Unlike a pre-emptive thread scheduler, it's NOT able to interrupt code blocks while they execute. But the scheduling capability it does have is enough to enable lightweight concurrency.
39
+
40
+
41
+ For information on Spawned Processes, see the separate document SPAWNED_PROCESSES.
42
+
43
+ For information on Deferrables, see the separate document DEFERRABLES.
44
+
45
+
46
+ === [SIDEBAR]: I Heard That EventMachine Doesn't Work With Ruby Threads.
47
+
48
+ This is incorrect. EM is fully interoperable with all versions of Ruby threads, and has been since its earliest releases.
49
+
50
+ It's very true that EM encourages an "evented" (non-threaded) programming style. The specific benefits of event-driven programming are far better performance and scalabiity for well-written programs, and far easier debugging.
51
+
52
+ The benefit of using threads for similar applications is a possibly more intuitive programming model, as well as the fact that threads are already familiar to most programmers. Also, bugs in threaded programs often fail to show up until programs go into production. These factors create the illusion that threaded programs are easier to write.
53
+
54
+ However, some operations that occur frequently in professional-caliber applications simply can't be done without threads. (The classic example is making calls to database client-libraries that block on network I/O until they complete.)
55
+
56
+ EventMachine not only allows the use of Ruby threads in these cases, but it even provides a built-in thread-pool object to make them easier to work with.
57
+
58
+ You may have heard a persistent criticism that evented I/O is fundamentally incompatible with Ruby threads. It is true that some well-publicized attempts to incorporate event-handling libraries into Ruby were not successful. But EventMachine was designed from the ground up with Ruby compatibility in mind, so EM never suffered from the problems that defeated the earlier attempts.
59
+
60
+
61
+ === [SIDEBAR]: I Heard That EventMachine Doesn't Work Very Well On Windows.
62
+
63
+ This too is incorrect. EventMachine is an extension written in C++ and Java, and therefore it requires compilation. Many Windows computers (and some Unix computers, especially in production environments) don't have a build stack. Attempting to install EventMachine on a machine without a compiler usually produces a confusing error.
64
+
65
+ In addition, Ruby has a much-debated issue with Windows compiler versions. Ruby on Windows works best with Visual Studio 6, a compiler version that is long out-of-print, no longer supported by Microsoft, and difficult to obtain. (This problem is not specific to EventMachine.)
66
+
67
+ Shortly after EventMachine was first released, the compiler issues led to criticism that EM was incompatible with Windows. Since that time, every EventMachine release has been supplied in a precompiled binary form for Windows users, that does not require you to compile the code yourself. EM binary Gems for Windows are compiled using Visual Studio 6.
68
+
69
+ EventMachine does supply some advanced features (such as Linux EPOLL support, reduced-privilege operation, UNIX-domain sockets, etc.) that have no meaningful implementation on Windows. Apart from these special cases, all EM functionality (including lightweight concurrency) works perfectly well on Windows.
70
+
data/docs/PURE_RUBY ADDED
@@ -0,0 +1,75 @@
1
+ EventMachine is supplied in three alternative versions.
2
+
3
+ 1) A version that includes a Ruby extension written in C++. This version requires compilation;
4
+ 2) A version for JRuby that contains a precompiled JAR file written in Java;
5
+ 3) A pure Ruby version that has no external dependencies and can run in any Ruby environment.
6
+
7
+ The Java version of EventMachine is packaged in a distinct manner and must be installed using a
8
+ special procedure. This version is described fully in a different document, and not considered
9
+ further here.
10
+
11
+ The C++ and pure-Ruby versions, however, are shipped in the same distribution. You use the same
12
+ files (either tarball or Ruby gem) to install both of these versions.
13
+
14
+ If you intend to use the C++ version, you must successfully compile EventMachine after you install it.
15
+ (The gem installation attempts to perform this step automatically.)
16
+
17
+ If you choose not to compile the EventMachine C++ extension, or if your compilation fails for any
18
+ reason, you still have a fully-functional installation of the pure-Ruby version of EM.
19
+
20
+ However, for technical reasons, a default EM installation (whether or not the compilation succeeds)
21
+ will always assume that the compiled ("extension") implementation should be used.
22
+
23
+ If you want your EM program to use the pure Ruby version, you must specifically request it. There
24
+ are two ways to do this: by setting either a Ruby global variable, or an environment string.
25
+
26
+ The following code will invoke the pure-Ruby implementation of EM:
27
+
28
+ $eventmachine_library = :pure_ruby
29
+ require 'eventmachine'
30
+
31
+ EM.library_type #=> "pure_ruby"
32
+
33
+ Notice that this requires a code change and is not the preferred way to select pure Ruby, unless
34
+ for some reason you are absolutely sure you will never want the compiled implementation.
35
+
36
+ Setting the following environment string has the same effect:
37
+
38
+ export EVENTMACHINE_LIBRARY="pure_ruby"
39
+
40
+ This technique gives you the flexibility to select either version at runtime with no code changes.
41
+
42
+ Support
43
+
44
+ The EventMachine development team has committed to support precisely the same APIs for all the
45
+ various implementations of EM.
46
+
47
+ This means that you can expect any EM program to behave identically, whether you use pure Ruby,
48
+ the compiled C++ extension, or JRuby. Deviations from this behavior are to be considered bugs
49
+ and should be reported as such.
50
+
51
+ There is a small number of exceptions to this rule, which arise from underlying platform
52
+ distinctions. Notably, EM#epoll is a silent no-op in the pure Ruby implementation.
53
+
54
+
55
+ When Should You Use the Pure-Ruby Implementation of EM?
56
+
57
+
58
+ Use the pure Ruby implementation of EM when you must support a platform for which no C++ compiler
59
+ is available, or on which the standard EM C++ code can't be compiled.
60
+
61
+ Keep in mind that you don't need a C++ compiler in order to deploy EM applications that rely on
62
+ the compiled version, so long as appropriate C++ runtime libraries are available on the target platform.
63
+
64
+ In extreme cases, you may find that you can develop software with the compiled EM version, but are
65
+ not allowed to install required runtime libraries on the deployment system(s). This would be another
66
+ case in which the pure Ruby implementation can be useful.
67
+
68
+ In general you should avoid the pure Ruby version of EM when performance and scalability are important.
69
+ EM in pure Ruby will necessarily run slower than the compiled version. Depending on your application
70
+ this may or may not be a key issue.
71
+
72
+ Also, since EPOLL is not supported in pure Ruby, your applications will be affected by Ruby's built-in
73
+ limit of 1024 file and socket descriptors that may be open in a single process. For maximum scalability
74
+ and performance, always use EPOLL if possible.
75
+
@@ -0,0 +1,94 @@
1
+ RUBY/EventMachine RELEASE NOTES
2
+
3
+ --------------------------------------------------
4
+ Version: 0.9.0, released xxXXX07
5
+ Added Erlang-like distributed-computing features
6
+
7
+ --------------------------------------------------
8
+ Version: 0.8.0, released 23Jun07
9
+ Added an epoll implementation for Linux 2.6 kernels.
10
+ Added evented #popen.
11
+
12
+ --------------------------------------------------
13
+ Version: 0.7.3, released 22May07
14
+ Added a large variety of small features. See the ChangeLog.
15
+
16
+ --------------------------------------------------
17
+ Version: 0.7.1, released xxNov06
18
+ Added protocol handlers for line-oriented protocols.
19
+ Various bug fixes.
20
+
21
+ --------------------------------------------------
22
+ Version: 0.7.0, released 20Nov06
23
+ Added a fix in em.cpp/ConnectToServer to fix a fatal exception that
24
+ occurred in FreeBSD when connecting successfully to a remote server.
25
+
26
+ --------------------------------------------------
27
+ Version: 0.6.0, released xxJul06
28
+ Added deferred operations, suggested by Don Stocks, amillionhitpoints@yahoo.com.
29
+
30
+ --------------------------------------------------
31
+ Version: 0.5.4, released xxJun06
32
+ Added get_peername support for streams and datagrams.
33
+
34
+ --------------------------------------------------
35
+ Version: 0.5.3, released 17May06
36
+ Fixed bugs in extconf.rb, thanks to Daniel Harple, dharple@generalconsumption.org.
37
+ Added proper setup.rb and rake tasks, thanks to Austin Ziegler.
38
+ Fixed a handful of reported problems with builds on various platforms.
39
+
40
+ --------------------------------------------------
41
+ Version: 0.5.2, released 05May06
42
+ Made several nonvisible improvements to the Windows
43
+ implementation.
44
+ Added an exception-handling patch contributed by Jeff Rose, jeff@rosejn.net.
45
+ Added a dir-config patch contributed anonymously.
46
+ Supported builds on Solaris.
47
+
48
+ --------------------------------------------------
49
+ Version: 0.5.1, released 05May06
50
+ Made it possible to pass a Class rather than a Module
51
+ to a protocol handler.
52
+ Added Windows port.
53
+
54
+ --------------------------------------------------
55
+ Version: 0.5.0, released 30Apr06
56
+ Added a preliminary SSL/TLS extension. This will probably
57
+ change over the next few releases.
58
+
59
+ --------------------------------------------------
60
+ Version: 0.4.5, released 29Apr06
61
+ Changed ext files so the ruby.h is installed after unistd.h
62
+ otherwise it doesn't compile on gcc 4.1
63
+
64
+ --------------------------------------------------
65
+ Version: 0.4.2, released 19Apr06
66
+ Changed the Ruby-glue so the extension will play nicer
67
+ in the sandbox with Ruby threads.
68
+ Added an EventMachine::run_without_threads API to
69
+ switch off the thread-awareness for better performance
70
+ in programs that do not spin any Ruby threads.
71
+
72
+ --------------------------------------------------
73
+ Version: 0.4.1, released 15Apr06
74
+ Reworked the shared-object interface to make it easier to
75
+ use EventMachine from languages other than Ruby.
76
+
77
+ --------------------------------------------------
78
+ Version: 0.3.2, released 12Apr06
79
+ Added support for a user-supplied block in EventMachine#connect.
80
+
81
+ --------------------------------------------------
82
+ Version: 0.3.1, released 11Apr06
83
+ Fixed bug that prevented EventMachine from being run multiple
84
+ times in a single process.
85
+
86
+ --------------------------------------------------
87
+ Version: 0.3.0, released 10Apr06
88
+ Added method EventHandler::Connection::post_init
89
+
90
+ --------------------------------------------------
91
+ Version: 0.2.0, released 10Apr06
92
+ Added method EventHandler::stop
93
+
94
+
data/docs/SMTP ADDED
@@ -0,0 +1,2 @@
1
+ This note details the usage of EventMachine's built-in support for SMTP. EM supports both client and server connections, which will be described in separate sections.
2
+