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
@@ -26,6 +26,8 @@
26
26
  module EventMachine
27
27
  module Protocols
28
28
 
29
+ # <b>Note:</b> This class is deprecated and will be removed. Please use EM-HTTP-Request instead.
30
+ #
29
31
  # === Usage
30
32
  #
31
33
  # EM.run{
@@ -42,12 +44,15 @@ module EventMachine
42
44
  include LineText2
43
45
 
44
46
  def initialize
47
+ warn "HttpClient2 is deprecated and will be removed. EM-Http-Request should be used instead."
48
+
45
49
  @authorization = nil
46
50
  @closed = nil
47
51
  @requests = nil
48
52
  end
49
53
 
50
- class Request # :nodoc:
54
+ # @private
55
+ class Request
51
56
  include Deferrable
52
57
 
53
58
  attr_reader :version
@@ -279,12 +284,12 @@ module EventMachine
279
284
  request args
280
285
  end
281
286
 
282
- # :stopdoc:
283
287
 
284
288
  #--
285
289
  # Compute and remember a string to be used as the host header in HTTP requests
286
290
  # unless the user overrides it with an argument to #request.
287
291
  #
292
+ # @private
288
293
  def set_default_host_header host, port, ssl
289
294
  if (ssl and port != 443) or (!ssl and port != 80)
290
295
  @host_header = "#{host}:#{port}"
@@ -294,11 +299,13 @@ module EventMachine
294
299
  end
295
300
 
296
301
 
302
+ # @private
297
303
  def post_init
298
304
  super
299
305
  @connected = EM::DefaultDeferrable.new
300
306
  end
301
307
 
308
+ # @private
302
309
  def connection_completed
303
310
  super
304
311
  @connected.succeed
@@ -316,12 +323,14 @@ module EventMachine
316
323
  # Set and remember a flag (@closed) so we can immediately fail any
317
324
  # subsequent requests.
318
325
  #
326
+ # @private
319
327
  def unbind
320
328
  super
321
329
  @closed = true
322
330
  (@requests || []).each {|r| r.fail}
323
331
  end
324
332
 
333
+ # @private
325
334
  def request args
326
335
  args[:host_header] = @host_header unless args.has_key?(:host_header)
327
336
  args[:authorization] = @authorization unless args.has_key?(:authorization)
@@ -335,6 +344,7 @@ module EventMachine
335
344
  r
336
345
  end
337
346
 
347
+ # @private
338
348
  def receive_line ln
339
349
  if req = @requests.last
340
350
  req.receive_line ln
@@ -342,8 +352,9 @@ module EventMachine
342
352
  p "??????????"
343
353
  p ln
344
354
  end
345
-
346
355
  end
356
+
357
+ # @private
347
358
  def receive_binary_data text
348
359
  @requests.last.receive_text text
349
360
  end
@@ -351,11 +362,10 @@ module EventMachine
351
362
  #--
352
363
  # Called by a Request object when it completes.
353
364
  #
365
+ # @private
354
366
  def pop_request
355
367
  @requests.pop
356
368
  end
357
-
358
- # :startdoc:
359
369
  end
360
370
 
361
371
 
@@ -0,0 +1,29 @@
1
+ module EventMachine
2
+ module Protocols
3
+ # LineProtocol will parse out newline terminated strings from a receive_data stream
4
+ #
5
+ # module Server
6
+ # include EM::P::LineProtocol
7
+ #
8
+ # def receive_line(line)
9
+ # send_data("you said: #{line}")
10
+ # end
11
+ # end
12
+ #
13
+ module LineProtocol
14
+ # @private
15
+ def receive_data data
16
+ (@buf ||= '') << data
17
+
18
+ while line = @buf.slice!(/(.*)\r?\n/)
19
+ receive_line(line)
20
+ end
21
+ end
22
+
23
+ # Invoked with lines received over the network
24
+ def receive_line(line)
25
+ # stub
26
+ end
27
+ end
28
+ end
29
+ end
@@ -32,18 +32,23 @@ module EventMachine
32
32
  ##
33
33
  # constants
34
34
 
35
- # :stopdoc:
36
35
  unless defined? Cempty
36
+ # @private
37
37
  Cstored = 'STORED'.freeze
38
+ # @private
38
39
  Cend = 'END'.freeze
40
+ # @private
39
41
  Cdeleted = 'DELETED'.freeze
42
+ # @private
40
43
  Cunknown = 'NOT_FOUND'.freeze
44
+ # @private
41
45
  Cerror = 'ERROR'.freeze
42
46
 
47
+ # @private
43
48
  Cempty = ''.freeze
49
+ # @private
44
50
  Cdelimiter = "\r\n".freeze
45
51
  end
46
- # :startdoc:
47
52
 
48
53
  ##
49
54
  # commands
@@ -110,9 +115,7 @@ module EventMachine
110
115
  EM.connect host, port, self, host, port
111
116
  end
112
117
 
113
- # :stopdoc:
114
-
115
- def send_cmd cmd, key, flags = 0, exptime = 0, bytes = 0, noreply = false # :nodoc:
118
+ def send_cmd cmd, key, flags = 0, exptime = 0, bytes = 0, noreply = false
116
119
  send_data "#{cmd} #{key} #{flags} #{exptime} #{bytes}#{noreply ? ' noreply' : ''}\r\n"
117
120
  end
118
121
  private :send_cmd
@@ -120,16 +123,19 @@ module EventMachine
120
123
  ##
121
124
  # errors
122
125
 
126
+ # @private
123
127
  class ParserError < StandardError
124
128
  end
125
129
 
126
130
  ##
127
131
  # em hooks
128
132
 
133
+ # @private
129
134
  def initialize host, port = 11211
130
135
  @host, @port = host, port
131
136
  end
132
137
 
138
+ # @private
133
139
  def connection_completed
134
140
  @get_cbs = []
135
141
  @set_cbs = []
@@ -148,6 +154,7 @@ module EventMachine
148
154
  # 19Feb09 Switched to a custom parser, LineText2 is recursive and can cause
149
155
  # stack overflows when there is too much data.
150
156
  # include EM::P::LineText2
157
+ # @private
151
158
  def receive_data data
152
159
  (@buffer||='') << data
153
160
 
@@ -164,6 +171,7 @@ module EventMachine
164
171
 
165
172
  #--
166
173
  # def receive_line line
174
+ # @private
167
175
  def process_cmd line
168
176
  case line.strip
169
177
  when /^VALUE\s+(.+?)\s+(\d+)\s+(\d+)/ # VALUE <key> <flags> <bytes>
@@ -209,6 +217,7 @@ module EventMachine
209
217
  # @values[@cur_key] = data[0..-3]
210
218
  # end
211
219
 
220
+ # @private
212
221
  def unbind
213
222
  if @connected or @reconnecting
214
223
  EM.add_timer(1){ reconnect @host, @port }
@@ -219,8 +228,6 @@ module EventMachine
219
228
  raise 'Unable to connect to memcached server'
220
229
  end
221
230
  end
222
-
223
- # :startdoc:
224
231
  end
225
232
  end
226
233
  end
@@ -229,7 +236,8 @@ if __FILE__ == $0
229
236
  # ruby -I ext:lib -r eventmachine -rubygems lib/protocols/memcache.rb
230
237
  require 'em/spec'
231
238
 
232
- class TestConnection # :nodoc:
239
+ # @private
240
+ class TestConnection
233
241
  include EM::P::Memcache
234
242
  def send_data data
235
243
  sent_data << data
@@ -320,4 +328,4 @@ if __FILE__ == $0
320
328
  end
321
329
 
322
330
  end
323
- end
331
+ end
@@ -17,7 +17,8 @@ module EventMachine
17
17
  Marshal
18
18
  end
19
19
 
20
- def receive_data data # :nodoc:
20
+ # @private
21
+ def receive_data data
21
22
  (@buf ||= '') << data
22
23
 
23
24
  while @buf.size >= 4
@@ -29,7 +29,8 @@ require 'postgres-pr/message'
29
29
  require 'postgres-pr/connection'
30
30
  require 'stringio'
31
31
 
32
- class StringIO # :nodoc:
32
+ # @private
33
+ class StringIO
33
34
  # Reads exactly +n+ bytes.
34
35
  #
35
36
  # If the data read is nil an EOFError is raised.
@@ -3,7 +3,7 @@
3
3
  # Author:: Francis Cianfrocca (gmail: blackhedd)
4
4
  # Homepage:: http://rubyeventmachine.com
5
5
  # Date:: 16 July 2006
6
- #
6
+ #
7
7
  # See EventMachine and EventMachine::Connection for documentation and
8
8
  # usage examples.
9
9
  #
@@ -11,17 +11,17 @@
11
11
  #
12
12
  # Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
13
13
  # Gmail: blackhedd
14
- #
14
+ #
15
15
  # This program is free software; you can redistribute it and/or modify
16
16
  # it under the terms of either: 1) the GNU General Public License
17
17
  # as published by the Free Software Foundation; either version 2 of the
18
18
  # License, or (at your option) any later version; or 2) Ruby's License.
19
- #
19
+ #
20
20
  # See the file COPYING for complete licensing information.
21
21
  #
22
22
  #---------------------------------------------------------------------------
23
23
  #
24
- #
24
+ #
25
25
 
26
26
  require 'ostruct'
27
27
 
@@ -30,6 +30,7 @@ module EventMachine
30
30
 
31
31
  # Simple SMTP client
32
32
  #
33
+ # @example
33
34
  # email = EM::Protocols::SmtpClient.send(
34
35
  # :domain=>"example.com",
35
36
  # :host=>'localhost',
@@ -66,7 +67,7 @@ module EventMachine
66
67
  class SmtpClient < Connection
67
68
  include EventMachine::Deferrable
68
69
  include EventMachine::Protocols::LineText2
69
-
70
+
70
71
  def initialize
71
72
  @succeeded = nil
72
73
  @responder = nil
@@ -91,7 +92,10 @@ module EventMachine
91
92
  # depending on the type.
92
93
  # Currently only :type => :plain is supported. Pass additional parameters :username (String),
93
94
  # and :password (either a String or a Proc that will be called at auth-time).
94
- # Example: :auth => {:type=>:plain, :username=>"mickey@disney.com", :password=>"mouse"}
95
+ #
96
+ # @example
97
+ # :auth => {:type=>:plain, :username=>"mickey@disney.com", :password=>"mouse"}
98
+ #
95
99
  # :from => required String
96
100
  # Specifies the sender of the message. Will be passed as the argument
97
101
  # to the MAIL FROM. Do NOT enclose the argument in angle-bracket (<>) characters.
@@ -109,7 +113,9 @@ module EventMachine
109
113
  # containing the header values. TODO, support Arrays of header values, which would cause us to
110
114
  # send that specific header line more than once.
111
115
  #
112
- # Example: :header => {"Subject" => "Bogus", "CC" => "myboss@example.com"}
116
+ # @example
117
+ # :header => {"Subject" => "Bogus", "CC" => "myboss@example.com"}
118
+ #
113
119
  # :body => Optional string, defaults blank.
114
120
  # This will be passed as the body of the email message.
115
121
  # TODO, this needs to be significantly beefed up. As currently written, this requires the caller
@@ -156,15 +162,15 @@ module EventMachine
156
162
  }
157
163
  end
158
164
 
159
- # :stopdoc:
160
-
161
165
  attr_writer :args
162
166
 
167
+ # @private
163
168
  def post_init
164
169
  @return_values = OpenStruct.new
165
170
  @return_values.start_time = Time.now
166
171
  end
167
172
 
173
+ # @private
168
174
  def connection_completed
169
175
  @responder = :receive_signon
170
176
  @msg = []
@@ -175,6 +181,7 @@ module EventMachine
175
181
  # set a deferred success because the caller will already have done it
176
182
  # (no need to wait until the connection closes to invoke the callbacks).
177
183
  #
184
+ # @private
178
185
  def unbind
179
186
  unless @succeeded
180
187
  @return_values.elapsed_time = Time.now - @return_values.start_time
@@ -185,6 +192,7 @@ module EventMachine
185
192
  end
186
193
  end
187
194
 
195
+ # @private
188
196
  def receive_line ln
189
197
  $>.puts ln if @args[:verbose]
190
198
  @range = ln[0...1].to_i
@@ -197,6 +205,8 @@ module EventMachine
197
205
  end
198
206
  end
199
207
 
208
+ private
209
+
200
210
  # We encountered an error from the server and will close the connection.
201
211
  # Use the error and message the server returned.
202
212
  #
@@ -350,8 +360,6 @@ module EventMachine
350
360
  @return_values.message = @msg
351
361
  set_deferred_status :succeeded, @return_values
352
362
  end
353
-
354
- # :startdoc:
355
363
  end
356
364
  end
357
365
  end
@@ -32,6 +32,86 @@ module EventMachine
32
32
  # and data to user code. User code is responsible for doing the right things with the
33
33
  # data in order to get complete and correct SMTP server behavior.
34
34
  #
35
+ # Simple SMTP server example:
36
+ #
37
+ # class EmailServer < EM::P::SmtpServer
38
+ # def receive_plain_auth(user, pass)
39
+ # true
40
+ # end
41
+ #
42
+ # def get_server_domain
43
+ # "mock.smtp.server.local"
44
+ # end
45
+ #
46
+ # def get_server_greeting
47
+ # "mock smtp server greets you with impunity"
48
+ # end
49
+ #
50
+ # def receive_sender(sender)
51
+ # current.sender = sender
52
+ # true
53
+ # end
54
+ #
55
+ # def receive_recipient(recipient)
56
+ # current.recipient = recipient
57
+ # true
58
+ # end
59
+ #
60
+ # def receive_message
61
+ # current.received = true
62
+ # current.completed_at = Time.now
63
+ #
64
+ # p [:received_email, current]
65
+ # @current = OpenStruct.new
66
+ # true
67
+ # end
68
+ #
69
+ # def receive_ehlo_domain(domain)
70
+ # @ehlo_domain = domain
71
+ # true
72
+ # end
73
+ #
74
+ # def receive_data_command
75
+ # current.data = ""
76
+ # true
77
+ # end
78
+ #
79
+ # def receive_data_chunk(data)
80
+ # current.data << data.join("\n")
81
+ # true
82
+ # end
83
+ #
84
+ # def receive_transaction
85
+ # if @ehlo_domain
86
+ # current.ehlo_domain = @ehlo_domain
87
+ # @ehlo_domain = nil
88
+ # end
89
+ # true
90
+ # end
91
+ #
92
+ # def current
93
+ # @current ||= OpenStruct.new
94
+ # end
95
+ #
96
+ # def self.start(host = 'localhost', port = 1025)
97
+ # require 'ostruct'
98
+ # @server = EM.start_server host, port, self
99
+ # end
100
+ #
101
+ # def self.stop
102
+ # if @server
103
+ # EM.stop_server @server
104
+ # @server = nil
105
+ # end
106
+ # end
107
+ #
108
+ # def self.running?
109
+ # !!@server
110
+ # end
111
+ # end
112
+ #
113
+ # EM.run{ EmailServer.start }
114
+ #
35
115
  #--
36
116
  # Useful paragraphs in RFC-2821:
37
117
  # 4.3.2: Concise list of command-reply sequences, in essence a text representation
@@ -114,6 +194,7 @@ module EventMachine
114
194
  @@parms[:verbose] and $>.puts ">>> #{ln}"
115
195
 
116
196
  return process_data_line(ln) if @state.include?(:data)
197
+ return process_auth_line(ln) if @state.include?(:auth_incomplete)
117
198
 
118
199
  case ln
119
200
  when EhloRegex
@@ -216,7 +297,7 @@ module EventMachine
216
297
  send_data "250-STARTTLS\r\n"
217
298
  end
218
299
  if @@parms[:auth]
219
- send_data "250-AUTH PLAIN LOGIN\r\n"
300
+ send_data "250-AUTH PLAIN\r\n"
220
301
  end
221
302
  send_data "250-NO-SOLICITING\r\n"
222
303
  # TODO, size needs to be configurable.
@@ -259,14 +340,14 @@ module EventMachine
259
340
  def process_auth str
260
341
  if @state.include?(:auth)
261
342
  send_data "503 auth already issued\r\n"
262
- elsif str =~ /\APLAIN\s+/i
263
- plain = ($'.dup).unpack("m").first # Base64::decode64($'.dup)
264
- discard,user,psw = plain.split("\000")
265
- if receive_plain_auth user,psw
266
- send_data "235 authentication ok\r\n"
267
- @state << :auth
343
+ elsif str =~ /\APLAIN\s?/i
344
+ if $'.length == 0
345
+ # we got a partial response, so let the client know to send the rest
346
+ @state << :auth_incomplete
347
+ send_data("334 \r\n")
268
348
  else
269
- send_data "535 invalid authentication\r\n"
349
+ # we got the initial response, so go ahead & process it
350
+ process_auth_line($')
270
351
  end
271
352
  #elsif str =~ /\ALOGIN\s+/i
272
353
  else
@@ -274,6 +355,18 @@ module EventMachine
274
355
  end
275
356
  end
276
357
 
358
+ def process_auth_line(line)
359
+ plain = line.unpack("m").first
360
+ _,user,psw = plain.split("\000")
361
+ if receive_plain_auth user,psw
362
+ send_data "235 authentication ok\r\n"
363
+ @state << :auth
364
+ else
365
+ send_data "535 invalid authentication\r\n"
366
+ end
367
+ @state.delete :auth_incomplete
368
+ end
369
+
277
370
  #--
278
371
  # Unusually, we can deal with a Deferrable returned from the user application.
279
372
  # This was added to deal with a special case in a particular application, but
@@ -64,12 +64,14 @@ module EventMachine
64
64
  # Body of the message
65
65
  attr_accessor :body
66
66
 
67
- def initialize # :nodoc:
67
+ # @private
68
+ def initialize
68
69
  @header = {}
69
70
  @state = :precommand
70
71
  @content_length = nil
71
72
  end
72
- def consume_line line # :nodoc:
73
+ # @private
74
+ def consume_line line
73
75
  if @state == :precommand
74
76
  unless line =~ /\A\s*\Z/
75
77
  @command = line
@@ -100,19 +102,19 @@ module EventMachine
100
102
  end
101
103
  end
102
104
 
103
- # :stopdoc:
104
-
105
+ # @private
105
106
  def send_frame verb, headers={}, body=""
106
107
  ary = [verb, "\n"]
107
108
  headers.each {|k,v| ary << "#{k}:#{v}\n" }
108
109
  ary << "content-length: #{body.to_s.length}\n"
109
- ary << "content-type: text/plain; charset=UTF-8\n"
110
+ ary << "content-type: text/plain; charset=UTF-8\n" unless headers.has_key? 'content-type'
110
111
  ary << "\n"
111
112
  ary << body.to_s
112
113
  ary << "\0"
113
114
  send_data ary.join
114
115
  end
115
116
 
117
+ # @private
116
118
  def receive_line line
117
119
  @stomp_initialized || init_message_reader
118
120
  @stomp_message.consume_line(line) {|outcome|
@@ -127,12 +129,14 @@ module EventMachine
127
129
  }
128
130
  end
129
131
 
132
+ # @private
130
133
  def receive_binary_data data
131
134
  @stomp_message.body = data[0..-2]
132
135
  receive_msg(@stomp_message) if respond_to?(:receive_msg)
133
136
  init_message_reader
134
137
  end
135
138
 
139
+ # @private
136
140
  def init_message_reader
137
141
  @stomp_initialized = true
138
142
  set_delimiter "\n"
@@ -140,8 +144,6 @@ module EventMachine
140
144
  @stomp_message = Message.new
141
145
  end
142
146
 
143
- # :startdoc:
144
-
145
147
  # Invoked with an incoming Stomp::Message received from the STOMP server
146
148
  def receive_msg msg
147
149
  # stub, overwrite this in your handler
@@ -27,7 +27,8 @@
27
27
  module EventMachine
28
28
  module Protocols
29
29
 
30
- class TcpConnectTester < Connection # :nodoc:
30
+ # @private
31
+ class TcpConnectTester < Connection
31
32
  include EventMachine::Deferrable
32
33
 
33
34
  def self.test( host, port )
@@ -50,4 +51,4 @@ module EventMachine
50
51
  end
51
52
 
52
53
  end
53
- end
54
+ end
data/lib/em/protocols.rb CHANGED
@@ -5,7 +5,7 @@ module EventMachine
5
5
  # - Memcache
6
6
  # - SmtpClient and SmtpServer
7
7
  # - SASLauth and SASLauthclient
8
- # - LineAndTextProtocol and LineText2
8
+ # - LineProtocol, LineAndTextProtocol and LineText2
9
9
  # - HeaderAndContentProtocol
10
10
  # - Postgres3
11
11
  # - ObjectProtocol