eventmachine-maglev- 0.12.10 → 1.0.0.beta.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. data/.gitignore +7 -0
  2. data/.yardopts +7 -0
  3. data/Gemfile +3 -0
  4. data/README.md +109 -0
  5. data/Rakefile +14 -368
  6. data/docs/DocumentationGuidesIndex.md +27 -0
  7. data/docs/GettingStarted.md +521 -0
  8. data/docs/old/DEFERRABLES +246 -0
  9. data/docs/{KEYBOARD → old/KEYBOARD} +15 -11
  10. data/docs/old/LIGHTWEIGHT_CONCURRENCY +130 -0
  11. data/docs/old/SMTP +4 -0
  12. data/docs/old/SPAWNED_PROCESSES +148 -0
  13. data/eventmachine.gemspec +20 -26
  14. data/examples/guides/getting_started/01_eventmachine_echo_server.rb +18 -0
  15. data/examples/guides/getting_started/02_eventmachine_echo_server_that_recognizes_exit_command.rb +22 -0
  16. data/examples/guides/getting_started/03_simple_chat_server.rb +149 -0
  17. data/examples/guides/getting_started/04_simple_chat_server_step_one.rb +27 -0
  18. data/examples/guides/getting_started/05_simple_chat_server_step_two.rb +43 -0
  19. data/examples/guides/getting_started/06_simple_chat_server_step_three.rb +98 -0
  20. data/examples/guides/getting_started/07_simple_chat_server_step_four.rb +121 -0
  21. data/examples/guides/getting_started/08_simple_chat_server_step_five.rb +141 -0
  22. data/examples/{ex_channel.rb → old/ex_channel.rb} +3 -3
  23. data/examples/old/ex_tick_loop_array.rb +15 -0
  24. data/examples/old/ex_tick_loop_counter.rb +32 -0
  25. data/ext/binder.cpp +0 -1
  26. data/ext/cmain.cpp +40 -29
  27. data/ext/ed.cpp +189 -134
  28. data/ext/ed.h +34 -40
  29. data/ext/em.cpp +388 -340
  30. data/ext/em.h +29 -32
  31. data/ext/eventmachine.h +7 -6
  32. data/ext/extconf.rb +57 -48
  33. data/ext/fastfilereader/extconf.rb +5 -3
  34. data/ext/fastfilereader/mapper.cpp +1 -1
  35. data/ext/fastfilereader/rubymain.cpp +0 -1
  36. data/ext/kb.cpp +1 -3
  37. data/ext/pipe.cpp +9 -11
  38. data/ext/project.h +12 -8
  39. data/ext/rubymain.cpp +158 -112
  40. data/java/src/com/rubyeventmachine/EmReactor.java +3 -2
  41. data/lib/em/buftok.rb +35 -63
  42. data/lib/em/callback.rb +43 -11
  43. data/lib/em/channel.rb +22 -15
  44. data/lib/em/completion.rb +303 -0
  45. data/lib/em/connection.rb +341 -208
  46. data/lib/em/deferrable/pool.rb +2 -0
  47. data/lib/em/deferrable.rb +20 -2
  48. data/lib/em/file_watch.rb +37 -18
  49. data/lib/em/iterator.rb +270 -0
  50. data/lib/em/pool.rb +146 -0
  51. data/lib/em/process_watch.rb +5 -4
  52. data/lib/em/processes.rb +8 -4
  53. data/lib/em/protocols/httpclient.rb +27 -11
  54. data/lib/em/protocols/httpclient2.rb +15 -5
  55. data/lib/em/protocols/line_protocol.rb +29 -0
  56. data/lib/em/protocols/memcache.rb +17 -9
  57. data/lib/em/protocols/object_protocol.rb +2 -1
  58. data/lib/em/protocols/postgres3.rb +2 -1
  59. data/lib/em/protocols/smtpclient.rb +19 -11
  60. data/lib/em/protocols/smtpserver.rb +101 -8
  61. data/lib/em/protocols/stomp.rb +9 -7
  62. data/lib/em/protocols/tcptest.rb +3 -2
  63. data/lib/em/protocols.rb +1 -1
  64. data/lib/{pr_eventmachine.rb → em/pure_ruby.rb} +188 -205
  65. data/lib/em/queue.rb +23 -13
  66. data/lib/em/resolver.rb +192 -0
  67. data/lib/em/spawnable.rb +9 -10
  68. data/lib/em/streamer.rb +34 -46
  69. data/lib/em/threaded_resource.rb +90 -0
  70. data/lib/em/tick_loop.rb +85 -0
  71. data/lib/em/timers.rb +8 -3
  72. data/lib/em/version.rb +1 -1
  73. data/lib/eventmachine.rb +582 -686
  74. data/lib/jeventmachine.rb +25 -3
  75. data/tasks/package.rake +98 -0
  76. data/tasks/test.rake +8 -0
  77. data/tests/em_test_helper.rb +64 -0
  78. data/tests/test_attach.rb +56 -56
  79. data/tests/test_basic.rb +111 -168
  80. data/tests/test_channel.rb +5 -6
  81. data/tests/test_completion.rb +177 -0
  82. data/tests/test_connection_count.rb +1 -3
  83. data/tests/test_defer.rb +3 -32
  84. data/tests/test_deferrable.rb +35 -0
  85. data/tests/test_epoll.rb +27 -57
  86. data/tests/test_error_handler.rb +10 -7
  87. data/tests/test_exc.rb +6 -33
  88. data/tests/test_file_watch.rb +51 -35
  89. data/tests/test_futures.rb +10 -38
  90. data/tests/test_get_sock_opt.rb +27 -20
  91. data/tests/test_handler_check.rb +1 -3
  92. data/tests/test_hc.rb +49 -112
  93. data/tests/test_httpclient.rb +34 -62
  94. data/tests/test_httpclient2.rb +14 -39
  95. data/tests/test_inactivity_timeout.rb +44 -40
  96. data/tests/test_kb.rb +26 -52
  97. data/tests/test_ltp.rb +27 -71
  98. data/tests/test_ltp2.rb +1 -30
  99. data/tests/test_next_tick.rb +2 -31
  100. data/tests/test_object_protocol.rb +8 -9
  101. data/tests/test_pause.rb +45 -37
  102. data/tests/test_pending_connect_timeout.rb +42 -38
  103. data/tests/test_pool.rb +128 -0
  104. data/tests/test_process_watch.rb +37 -37
  105. data/tests/test_processes.rb +92 -110
  106. data/tests/test_proxy_connection.rb +137 -61
  107. data/tests/test_pure.rb +30 -67
  108. data/tests/test_queue.rb +10 -4
  109. data/tests/test_resolver.rb +55 -0
  110. data/tests/test_running.rb +1 -29
  111. data/tests/test_sasl.rb +8 -33
  112. data/tests/test_send_file.rb +163 -188
  113. data/tests/test_servers.rb +12 -55
  114. data/tests/test_shutdown_hooks.rb +23 -0
  115. data/tests/test_smtpclient.rb +1 -29
  116. data/tests/test_smtpserver.rb +1 -29
  117. data/tests/test_spawn.rb +2 -31
  118. data/tests/test_ssl_args.rb +9 -10
  119. data/tests/test_ssl_methods.rb +1 -3
  120. data/tests/test_ssl_verify.rb +63 -63
  121. data/tests/test_threaded_resource.rb +53 -0
  122. data/tests/test_tick_loop.rb +59 -0
  123. data/tests/test_timers.rb +52 -91
  124. data/tests/test_ud.rb +1 -29
  125. data/tests/test_unbind_reason.rb +31 -0
  126. metadata +113 -70
  127. data/README +0 -82
  128. data/docs/DEFERRABLES +0 -133
  129. data/docs/LIGHTWEIGHT_CONCURRENCY +0 -70
  130. data/docs/SMTP +0 -2
  131. data/docs/SPAWNED_PROCESSES +0 -89
  132. data/ext/cplusplus.cpp +0 -202
  133. data/ext/emwin.cpp +0 -300
  134. data/ext/emwin.h +0 -94
  135. data/ext/epoll.cpp +0 -26
  136. data/ext/epoll.h +0 -25
  137. data/ext/eventmachine_cpp.h +0 -96
  138. data/ext/files.cpp +0 -94
  139. data/ext/files.h +0 -65
  140. data/ext/sigs.cpp +0 -89
  141. data/ext/sigs.h +0 -32
  142. data/java/src/com/rubyeventmachine/application/Application.java +0 -194
  143. data/java/src/com/rubyeventmachine/application/Connection.java +0 -74
  144. data/java/src/com/rubyeventmachine/application/ConnectionFactory.java +0 -37
  145. data/java/src/com/rubyeventmachine/application/DefaultConnectionFactory.java +0 -46
  146. data/java/src/com/rubyeventmachine/application/PeriodicTimer.java +0 -38
  147. data/java/src/com/rubyeventmachine/application/Timer.java +0 -54
  148. data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +0 -109
  149. data/java/src/com/rubyeventmachine/tests/ConnectTest.java +0 -148
  150. data/java/src/com/rubyeventmachine/tests/EMTest.java +0 -80
  151. data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +0 -53
  152. data/java/src/com/rubyeventmachine/tests/TestServers.java +0 -75
  153. data/java/src/com/rubyeventmachine/tests/TestTimers.java +0 -90
  154. data/lib/evma/callback.rb +0 -32
  155. data/lib/evma/container.rb +0 -75
  156. data/lib/evma/factory.rb +0 -77
  157. data/lib/evma/protocol.rb +0 -87
  158. data/lib/evma/reactor.rb +0 -48
  159. data/lib/evma.rb +0 -32
  160. data/setup.rb +0 -1585
  161. data/tests/test_errors.rb +0 -82
  162. data/tests/testem.rb +0 -31
  163. data/web/whatis +0 -7
  164. /data/{docs/GNU → GNU} +0 -0
  165. /data/{docs/COPYING → LICENSE} +0 -0
  166. /data/docs/{ChangeLog → old/ChangeLog} +0 -0
  167. /data/docs/{EPOLL → old/EPOLL} +0 -0
  168. /data/docs/{INSTALL → old/INSTALL} +0 -0
  169. /data/docs/{LEGAL → old/LEGAL} +0 -0
  170. /data/docs/{PURE_RUBY → old/PURE_RUBY} +0 -0
  171. /data/docs/{RELEASE_NOTES → old/RELEASE_NOTES} +0 -0
  172. /data/docs/{TODO → old/TODO} +0 -0
  173. /data/examples/{ex_queue.rb → old/ex_queue.rb} +0 -0
  174. /data/examples/{helper.rb → old/helper.rb} +0 -0
metadata CHANGED
@@ -1,16 +1,50 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eventmachine-maglev-
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.10
5
- prerelease:
4
+ version: 1.0.0.beta.4
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Francis Cianfrocca
9
+ - Aman Gupta
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2009-10-24 00:00:00.000000000 Z
13
- dependencies: []
13
+ date: 2012-07-29 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake-compiler
17
+ requirement: &69825862374080 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - =
21
+ - !ruby/object:Gem::Version
22
+ version: 0.7.6
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *69825862374080
26
+ - !ruby/object:Gem::Dependency
27
+ name: yard
28
+ requirement: &69825862373380 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.7.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *69825862373380
37
+ - !ruby/object:Gem::Dependency
38
+ name: bluecloth
39
+ requirement: &69825862372800 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *69825862372800
14
48
  description: ! 'EventMachine implements a fast, single-threaded engine for arbitrary
15
49
  network
16
50
 
@@ -30,66 +64,85 @@ description: ! 'EventMachine implements a fast, single-threaded engine for arbit
30
64
 
31
65
  of EventMachine is to enable programs to easily interface with other programs
32
66
 
33
- using TCP/IP, especially if custom protocols are required.
34
-
35
- '
36
- email: garbagecat10@gmail.com
67
+ using TCP/IP, especially if custom protocols are required.'
68
+ email:
69
+ - garbagecat10@gmail.com
70
+ - aman@tmm1.net
37
71
  executables: []
38
72
  extensions:
39
73
  - ext/extconf.rb
40
74
  - ext/fastfilereader/extconf.rb
41
- extra_rdoc_files: []
75
+ extra_rdoc_files:
76
+ - README.md
77
+ - docs/DocumentationGuidesIndex.md
78
+ - docs/GettingStarted.md
79
+ - docs/old/ChangeLog
80
+ - docs/old/DEFERRABLES
81
+ - docs/old/EPOLL
82
+ - docs/old/INSTALL
83
+ - docs/old/KEYBOARD
84
+ - docs/old/LEGAL
85
+ - docs/old/LIGHTWEIGHT_CONCURRENCY
86
+ - docs/old/PURE_RUBY
87
+ - docs/old/RELEASE_NOTES
88
+ - docs/old/SMTP
89
+ - docs/old/SPAWNED_PROCESSES
90
+ - docs/old/TODO
42
91
  files:
43
92
  - .gitignore
44
- - README
93
+ - .yardopts
94
+ - GNU
95
+ - Gemfile
96
+ - LICENSE
97
+ - README.md
45
98
  - Rakefile
46
- - docs/COPYING
47
- - docs/ChangeLog
48
- - docs/DEFERRABLES
49
- - docs/EPOLL
50
- - docs/GNU
51
- - docs/INSTALL
52
- - docs/KEYBOARD
53
- - docs/LEGAL
54
- - docs/LIGHTWEIGHT_CONCURRENCY
55
- - docs/PURE_RUBY
56
- - docs/RELEASE_NOTES
57
- - docs/SMTP
58
- - docs/SPAWNED_PROCESSES
59
- - docs/TODO
99
+ - docs/DocumentationGuidesIndex.md
100
+ - docs/GettingStarted.md
101
+ - docs/old/ChangeLog
102
+ - docs/old/DEFERRABLES
103
+ - docs/old/EPOLL
104
+ - docs/old/INSTALL
105
+ - docs/old/KEYBOARD
106
+ - docs/old/LEGAL
107
+ - docs/old/LIGHTWEIGHT_CONCURRENCY
108
+ - docs/old/PURE_RUBY
109
+ - docs/old/RELEASE_NOTES
110
+ - docs/old/SMTP
111
+ - docs/old/SPAWNED_PROCESSES
112
+ - docs/old/TODO
60
113
  - eventmachine.gemspec
61
- - examples/ex_channel.rb
62
- - examples/ex_queue.rb
63
- - examples/helper.rb
114
+ - examples/guides/getting_started/01_eventmachine_echo_server.rb
115
+ - examples/guides/getting_started/02_eventmachine_echo_server_that_recognizes_exit_command.rb
116
+ - examples/guides/getting_started/03_simple_chat_server.rb
117
+ - examples/guides/getting_started/04_simple_chat_server_step_one.rb
118
+ - examples/guides/getting_started/05_simple_chat_server_step_two.rb
119
+ - examples/guides/getting_started/06_simple_chat_server_step_three.rb
120
+ - examples/guides/getting_started/07_simple_chat_server_step_four.rb
121
+ - examples/guides/getting_started/08_simple_chat_server_step_five.rb
122
+ - examples/old/ex_channel.rb
123
+ - examples/old/ex_queue.rb
124
+ - examples/old/ex_tick_loop_array.rb
125
+ - examples/old/ex_tick_loop_counter.rb
126
+ - examples/old/helper.rb
64
127
  - ext/binder.cpp
65
128
  - ext/binder.h
66
129
  - ext/cmain.cpp
67
- - ext/cplusplus.cpp
68
130
  - ext/ed.cpp
69
131
  - ext/ed.h
70
132
  - ext/em.cpp
71
133
  - ext/em.h
72
- - ext/emwin.cpp
73
- - ext/emwin.h
74
- - ext/epoll.cpp
75
- - ext/epoll.h
76
134
  - ext/eventmachine.h
77
- - ext/eventmachine_cpp.h
78
135
  - ext/extconf.rb
79
136
  - ext/fastfilereader/extconf.rb
80
137
  - ext/fastfilereader/mapper.cpp
81
138
  - ext/fastfilereader/mapper.h
82
139
  - ext/fastfilereader/rubymain.cpp
83
- - ext/files.cpp
84
- - ext/files.h
85
140
  - ext/kb.cpp
86
141
  - ext/page.cpp
87
142
  - ext/page.h
88
143
  - ext/pipe.cpp
89
144
  - ext/project.h
90
145
  - ext/rubymain.cpp
91
- - ext/sigs.cpp
92
- - ext/sigs.h
93
146
  - ext/ssl.cpp
94
147
  - ext/ssl.h
95
148
  - java/.classpath
@@ -99,26 +152,18 @@ files:
99
152
  - java/src/com/rubyeventmachine/EventableChannel.java
100
153
  - java/src/com/rubyeventmachine/EventableDatagramChannel.java
101
154
  - java/src/com/rubyeventmachine/EventableSocketChannel.java
102
- - java/src/com/rubyeventmachine/application/Application.java
103
- - java/src/com/rubyeventmachine/application/Connection.java
104
- - java/src/com/rubyeventmachine/application/ConnectionFactory.java
105
- - java/src/com/rubyeventmachine/application/DefaultConnectionFactory.java
106
- - java/src/com/rubyeventmachine/application/PeriodicTimer.java
107
- - java/src/com/rubyeventmachine/application/Timer.java
108
- - java/src/com/rubyeventmachine/tests/ApplicationTest.java
109
- - java/src/com/rubyeventmachine/tests/ConnectTest.java
110
- - java/src/com/rubyeventmachine/tests/EMTest.java
111
- - java/src/com/rubyeventmachine/tests/TestDatagrams.java
112
- - java/src/com/rubyeventmachine/tests/TestServers.java
113
- - java/src/com/rubyeventmachine/tests/TestTimers.java
114
155
  - lib/em/buftok.rb
115
156
  - lib/em/callback.rb
116
157
  - lib/em/channel.rb
158
+ - lib/em/completion.rb
117
159
  - lib/em/connection.rb
118
160
  - lib/em/deferrable.rb
161
+ - lib/em/deferrable/pool.rb
119
162
  - lib/em/file_watch.rb
120
163
  - lib/em/future.rb
164
+ - lib/em/iterator.rb
121
165
  - lib/em/messages.rb
166
+ - lib/em/pool.rb
122
167
  - lib/em/process_watch.rb
123
168
  - lib/em/processes.rb
124
169
  - lib/em/protocols.rb
@@ -126,6 +171,7 @@ files:
126
171
  - lib/em/protocols/httpclient.rb
127
172
  - lib/em/protocols/httpclient2.rb
128
173
  - lib/em/protocols/line_and_text.rb
174
+ - lib/em/protocols/line_protocol.rb
129
175
  - lib/em/protocols/linetext2.rb
130
176
  - lib/em/protocols/memcache.rb
131
177
  - lib/em/protocols/object_protocol.rb
@@ -136,32 +182,32 @@ files:
136
182
  - lib/em/protocols/socks4.rb
137
183
  - lib/em/protocols/stomp.rb
138
184
  - lib/em/protocols/tcptest.rb
185
+ - lib/em/pure_ruby.rb
139
186
  - lib/em/queue.rb
187
+ - lib/em/resolver.rb
140
188
  - lib/em/spawnable.rb
141
189
  - lib/em/streamer.rb
190
+ - lib/em/threaded_resource.rb
191
+ - lib/em/tick_loop.rb
142
192
  - lib/em/timers.rb
143
193
  - lib/em/version.rb
144
194
  - lib/eventmachine.rb
145
- - lib/evma.rb
146
- - lib/evma/callback.rb
147
- - lib/evma/container.rb
148
- - lib/evma/factory.rb
149
- - lib/evma/protocol.rb
150
- - lib/evma/reactor.rb
151
195
  - lib/jeventmachine.rb
152
- - lib/pr_eventmachine.rb
153
- - setup.rb
154
196
  - tasks/cpp.rake_example
197
+ - tasks/package.rake
198
+ - tasks/test.rake
155
199
  - tests/client.crt
156
200
  - tests/client.key
201
+ - tests/em_test_helper.rb
157
202
  - tests/test_attach.rb
158
203
  - tests/test_basic.rb
159
204
  - tests/test_channel.rb
205
+ - tests/test_completion.rb
160
206
  - tests/test_connection_count.rb
161
207
  - tests/test_defer.rb
208
+ - tests/test_deferrable.rb
162
209
  - tests/test_epoll.rb
163
210
  - tests/test_error_handler.rb
164
- - tests/test_errors.rb
165
211
  - tests/test_exc.rb
166
212
  - tests/test_file_watch.rb
167
213
  - tests/test_futures.rb
@@ -178,25 +224,29 @@ files:
178
224
  - tests/test_object_protocol.rb
179
225
  - tests/test_pause.rb
180
226
  - tests/test_pending_connect_timeout.rb
227
+ - tests/test_pool.rb
181
228
  - tests/test_process_watch.rb
182
229
  - tests/test_processes.rb
183
230
  - tests/test_proxy_connection.rb
184
231
  - tests/test_pure.rb
185
232
  - tests/test_queue.rb
233
+ - tests/test_resolver.rb
186
234
  - tests/test_running.rb
187
235
  - tests/test_sasl.rb
188
236
  - tests/test_send_file.rb
189
237
  - tests/test_servers.rb
238
+ - tests/test_shutdown_hooks.rb
190
239
  - tests/test_smtpclient.rb
191
240
  - tests/test_smtpserver.rb
192
241
  - tests/test_spawn.rb
193
242
  - tests/test_ssl_args.rb
194
243
  - tests/test_ssl_methods.rb
195
244
  - tests/test_ssl_verify.rb
245
+ - tests/test_threaded_resource.rb
246
+ - tests/test_tick_loop.rb
196
247
  - tests/test_timers.rb
197
248
  - tests/test_ud.rb
198
- - tests/testem.rb
199
- - web/whatis
249
+ - tests/test_unbind_reason.rb
200
250
  homepage: http://rubyeventmachine.com
201
251
  licenses: []
202
252
  post_install_message:
@@ -204,17 +254,10 @@ rdoc_options:
204
254
  - --title
205
255
  - EventMachine
206
256
  - --main
207
- - README
208
- - --line-numbers
257
+ - README.md
209
258
  - -x
210
259
  - lib/em/version
211
260
  - -x
212
- - lib/emva
213
- - -x
214
- - lib/evma/
215
- - -x
216
- - lib/pr_eventmachine
217
- - -x
218
261
  - lib/jeventmachine
219
262
  require_paths:
220
263
  - lib
@@ -227,9 +270,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
227
270
  required_rubygems_version: !ruby/object:Gem::Requirement
228
271
  none: false
229
272
  requirements:
230
- - - ! '>='
273
+ - - ! '>'
231
274
  - !ruby/object:Gem::Version
232
- version: '0'
275
+ version: 1.3.1
233
276
  requirements: []
234
277
  rubyforge_project: eventmachine
235
278
  rubygems_version: 1.8.11
data/README DELETED
@@ -1,82 +0,0 @@
1
- = RUBY/EventMachine
2
-
3
- Homepage:: http://rubyeventmachine.com
4
- Rubyforge Page:: http://rubyforge.org/projects/eventmachine
5
- Google Group:: http://groups.google.com/group/eventmachine
6
- Mailing List:: http://rubyforge.org/pipermail/eventmachine-talk
7
- RDoc:: http://eventmachine.rubyforge.org
8
- IRC:: ##eventmachine on irc.freenode.net
9
- Copyright:: (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
10
- Email:: gmail address: garbagecat10
11
-
12
- EventMachine is copyrighted free software made available under the terms
13
- of either the GPL or Ruby's License. See the file COPYING for full licensing
14
- information.
15
- See EventMachine and EventMachine::Connection for documentation and
16
- usage examples.
17
-
18
- EventMachine implements a fast, single-threaded engine for arbitrary network
19
- communications. It's extremely easy to use in Ruby. EventMachine wraps all
20
- interactions with IP sockets, allowing programs to concentrate on the
21
- implementation of network protocols. It can be used to create both network
22
- servers and clients. To create a server or client, a Ruby program only needs
23
- to specify the IP address and port, and provide a Module that implements the
24
- communications protocol. Implementations of several standard network protocols
25
- are provided with the package, primarily to serve as examples. The real goal
26
- of EventMachine is to enable programs to easily interface with other programs
27
- using TCP/IP, especially if custom protocols are required.
28
-
29
- A Ruby program uses EventMachine by registering the addresses and ports of
30
- network servers and clients, and then entering an event-handling loop.
31
- EventMachine contains glue code in Ruby which will execute callbacks to
32
- user-supplied code for all significant events occurring in the clients
33
- and servers. These events include connection acceptance, startup, data-receipt,
34
- shutdown, and timer events. Arbitrary processing can be performed by user code
35
- during event callbacks, including sending data to one or more remote network
36
- peers, startup and shutdown of network connections, and installation of new
37
- event handlers.
38
-
39
- The EventMachine implements a very familiar model for network programming.
40
- It emphasizes: 1) the maximum possible isolation of user code from network
41
- objects like sockets; 2) maximum performance and scalability; and 3) extreme
42
- ease-of-use for user code. It attempts to provide a higher-level interface
43
- than similar projects which expose a variety of low-level event-handling
44
- and networking objects to Ruby programs.
45
-
46
- The design and implementation of EventMachine grows out of nearly ten years
47
- of experience writing high-performance, high-scaling network server applications.
48
- We have taken particular account of the challenges and lessons described as
49
- the "C10K problem" by Dan Kegel and others.
50
-
51
- EventMachine consists of an extension library written in C++ (which can be
52
- accessed from languages other than Ruby), and a Ruby module which can be dropped
53
- into user programs. On most platforms, EventMachine uses the
54
- <tt>select(2)</tt> system call,
55
- so it will run on a large range of Unix-like systems and on Microsoft
56
- Windows with good performance and scalability. On Linux 2.6 kernels, EventMachine
57
- automatically configures itself to use <tt>epoll(4)</tt> instead of
58
- <tt>select(2),</tt> so scalability on that platform can be significantly
59
- improved.
60
-
61
- Here's a fully-functional echo server written with EventMachine:
62
-
63
- require 'eventmachine'
64
-
65
- module EchoServer
66
- def post_init
67
- puts "-- someone connected to the echo server!"
68
- end
69
-
70
- def receive_data data
71
- send_data ">>>you sent: #{data}"
72
- close_connection if data =~ /quit/i
73
- end
74
-
75
- def unbind
76
- puts "-- someone disconnected from the echo server!"
77
- end
78
- end
79
-
80
- EventMachine::run {
81
- EventMachine::start_server "127.0.0.1", 8081, EchoServer
82
- }
data/docs/DEFERRABLES DELETED
@@ -1,133 +0,0 @@
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 deferrables. For more information, see the separate document LIGHTWEIGHT_CONCURRENCY.
2
-
3
- === What are Deferrables?
4
-
5
- EventMachine's Deferrable borrows heavily from the "deferred" object in Python's "Twisted" event-handling framework. Here's a minimal example that illustrates Deferrable:
6
-
7
- require 'eventmachine'
8
-
9
- class MyClass
10
- include EM::Deferrable
11
-
12
- def print_value x
13
- puts "MyClass instance received #{x}"
14
- end
15
- end
16
-
17
- EM.run {
18
- df = MyClass.new
19
- df.callback {|x|
20
- df.print_value(x)
21
- EM.stop
22
- }
23
-
24
- EM::Timer.new(2) {
25
- df.set_deferred_status :succeeded, 100
26
- }
27
- }
28
-
29
-
30
- This program will spin for two seconds, print out the string "MyClass instance received 100" and then exit. The Deferrable pattern relies on an unusual metaphor that may be unfamiliar to you, unless you've used Python's Twisted. You may need to read the following material through more than once before you get the idea.
31
-
32
- EventMachine::Deferrable is simply a Ruby Module that you can include in your own classes. (There also is a class named EventMachine::DefaultDeferrable for when you want to create one without including it in code of your own.)
33
-
34
- An object that includes EventMachine::Deferrable is like any other Ruby object: it can be created whenever you want, returned from your functions, or passed as an argument to other functions.
35
-
36
- The Deferrable pattern allows you to specify any number of Ruby code blocks (callbacks or errbacks) that will be executed at some future time when the status of the Deferrable object changes.
37
-
38
- How might that be useful? Well, imagine that you're implementing an HTTP server, but you need to make a call to some other server in order to fulfill a client request.
39
-
40
- When you receive a request from one of your clients, you can create and return a Deferrable object. Some other section of your program can add a callback to the Deferrable that will cause the client's request to be fulfilled. Simultaneously, you initiate an event-driven or threaded client request to some different server. And then your EM program will continue to process other events and service other client requests.
41
-
42
- When your client request to the other server completes some time later, you will call the #set_deferred_status method on the Deferrable object, passing either a success or failure status, and an arbitrary number of parameters (which might include the data you received from the other server).
43
-
44
- At that point, the status of the Deferrable object becomes known, and its callback or errback methods are immediately executed. Callbacks and errbacks are code blocks that are attached to Deferrable objects at any time through the methods #callback and #errback.
45
-
46
- The deep beauty of this pattern is that it decouples the disposition of one operation (such as a client request to an outboard server) from the subsequent operations that depend on that disposition (which may include responding to a different client or any other operation).
47
-
48
- The code which invokes the deferred operation (that will eventually result in a success or failure status together with associated data) is completely separate from the code which depends on that status and data. This achieves one of the primary goals for which threading is typically used in sophisticated applications, with none of the nondeterminacy or debugging difficulties of threads.
49
-
50
- As soon as the deferred status of a Deferrable becomes known by way of a call to #set_deferred_status, the Deferrable will IMMEDIATELY execute all of its callbacks or errbacks in the order in which they were added to the Deferrable.
51
-
52
- Callbacks and errbacks can be added to a Deferrable object at any time, not just when the object is created. They can even be added after the status of the object has been determined! (In this case, they will be executed immediately when they are added.)
53
-
54
- A call to Deferrable#set_deferred_status takes :succeeded or :failed as its first argument. (This determines whether the object will call its callbacks or its errbacks.) #set_deferred_status also takes zero or more additional parameters, that will in turn be passed as parameters to the callbacks or errbacks.
55
-
56
- In general, you can only call #set_deferred_status ONCE on a Deferrable object. A call to #set_deferred_status will not return until all of the associated callbacks or errbacks have been called. If you add callbacks or errbacks AFTER making a call to #set_deferred_status, those additional callbacks or errbacks will execute IMMEDIATELY. Any given callback or errback will be executed AT MOST once.
57
-
58
- It's possible to call #set_deferred_status AGAIN, during the execution a callback or errback. This makes it possible to change the parameters which will be sent to the callbacks or errbacks farther down the chain, enabling some extremely elegant use-cases. You can transform the data returned from a deferred operation in arbitrary ways as needed by subsequent users, without changing any of the code that generated the original data.
59
-
60
- A call to #set_deferred_status will not return until all of the associated callbacks or errbacks have been called. If you add callbacks or errbacks AFTER making a call to #set_deferred_status, those additional callbacks or errbacks will execute IMMEDIATELY.
61
-
62
- Let's look at some more sample code. It turns out that many of the internal protocol implementations in the EventMachine package rely on Deferrable. One of these is EM::Protocols::HttpClient.
63
-
64
- To make an evented HTTP request, use the module function EM::Protocols::HttpClient#request, which returns a Deferrable object. Here's how:
65
-
66
- require 'eventmachine'
67
-
68
- EM.run {
69
- df = EM::Protocols::HttpClient.request( :host=>"www.example.com", :request=>"/index.html" )
70
-
71
- df.callback {|response|
72
- puts "Succeeded: #{response[:content]}"
73
- EM.stop
74
- }
75
-
76
- df.errback {|response|
77
- puts "ERROR: #{response[:status]}"
78
- EM.stop
79
- }
80
- }
81
-
82
- (See the documentation of EventMachine::Protocols::HttpClient for information on the object returned by #request.)
83
-
84
- In this code, we make a call to HttpClient#request, which immediately returns a Deferrable object. In the background, an HTTP client request is being made to www.example.com, although your code will continue to run concurrently.
85
-
86
- At some future point, the HTTP client request will complete, and the code in EM::Protocols::HttpClient will process either a valid HTTP response (including returned content), or an error.
87
-
88
- At that point, EM::Protocols::HttpClient will call EM::Deferrable#set_deferred_status on the Deferrable object that was returned to your program, as the return value from EM::Protocols::HttpClient.request. You don't have to do anything to make this happen. All you have to do is tell the Deferrable what to do in case of either success, failure, or both.
89
-
90
- In our code sample, we set one callback and one errback. The former will be called if the HTTP call succeeds, and the latter if it fails. (For simplicity, we have both of them calling EM#stop to end the program, although real programs would be very unlikely to do this.)
91
-
92
- Setting callbacks and errbacks is optional. They are handlers to defined events in the lifecycle of the Deferrable event. It's not an error if you fail to set either a callback, an errback, or both. But of course your program will then fail to receive those notifications.
93
-
94
- If through some bug it turns out that #set_deferred_status is never called on a Deferrable object, then that object's callbacks or errbacks will NEVER be called. It's also possible to set a timeout on a Deferrable. If the timeout elapses before any other call to #set_deferred_status, the Deferrable object will behave as is you had called set_deferred_status(:failed) on it.
95
-
96
-
97
- Now let's modify the example to illustrate some additional points:
98
-
99
- require 'eventmachine'
100
-
101
- EM.run {
102
- df = EM::Protocols::HttpClient.request( :host=>"www.example.com", :request=>"/index.html" )
103
-
104
- df.callback {|response|
105
- df.set_deferred_status :succeeded, response[:content]
106
- }
107
-
108
- df.callback {|string|
109
- puts "Succeeded: #{string}"
110
- EM.stop
111
- }
112
-
113
- df.errback {|response|
114
- puts "ERROR: #{response[:status]}"
115
- EM.stop
116
- }
117
- }
118
-
119
-
120
- Just for the sake of illustration, we've now set two callbacks instead of one. If the deferrable operation (the HTTP client-request) succeeds, then both of the callbacks will be executed in order.
121
-
122
- But notice that we've also made our own call to #set_deferred_status in the first callback. This isn't required, because the HttpClient implementation already made a call to #set_deferred_status. (Otherwise, of course, the callback would not be executing.)
123
-
124
- But we used #set_deferred_status in the first callback in order to change the parameters that will be sent to subsequent callbacks in the chain. In this way, you can construct powerful sequences of layered functionality. If you want, you can even change the status of the Deferrable from :succeeded to :failed, which would abort the chain of callback calls, and invoke the chain of errbacks instead.
125
-
126
- Now of course it's somewhat trivial to define two callbacks in the same method, even with the parameter-changing effect we just described. It would be much more interesting to pass the Deferrable to some other function (for example, a function defined in another module or a different gem), that would in turn add callbacks and/or errbacks of its own. That would illustrate the true power of the Deferrable pattern: to isolate the HTTP client-request from other functions that use the data that it returns without caring where those data came from.
127
-
128
- Remember that you can add a callback or an errback to a Deferrable at any point in time, regardless of whether the status of the deferred operation is known (more precisely, regardless of when #set_deferred_status is called on the object). Even hours or days later.
129
-
130
- When you add a callback or errback to a Deferrable object on which #set_deferred_status has not yet been called, the callback/errback is queued up for future execution, inside the Deferrable object. When you add a callback or errback to a Deferrable on which #set_deferred_status has already been called, the callback/errback will be executed immediately. Your code doesn't have to worry about the ordering, and there are no timing issues, as there would be with a threaded approach.
131
-
132
- For more information on Deferrables and their typical usage patterns, look in the EM unit tests. There are also quite a few sugarings (including EM::Deferrable#future) that make typical Deferrable usages syntactically easier to work with.
133
-
@@ -1,70 +0,0 @@
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/SMTP DELETED
@@ -1,2 +0,0 @@
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
-