eventmachine-eventmachine 0.12.3 → 0.12.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/eventmachine.rb CHANGED
@@ -384,7 +384,6 @@ module EventMachine
384
384
  def EventMachine::cancel_timer signature
385
385
  @timers[signature] = proc{} if @timers.has_key?(signature)
386
386
  end
387
- private_class_method :cancel_timer
388
387
 
389
388
 
390
389
  # stop_event_loop may called from within a callback method
@@ -1105,7 +1104,7 @@ module EventMachine
1105
1104
  #--
1106
1105
  # Perhaps misnamed since the underlying function uses socketpair and is full-duplex.
1107
1106
  #
1108
- def self::popen cmd, handler=nil
1107
+ def self::popen cmd, handler=nil, *args
1109
1108
  klass = if (handler and handler.is_a?(Class))
1110
1109
  handler
1111
1110
  else
@@ -1115,7 +1114,7 @@ module EventMachine
1115
1114
  w = Shellwords::shellwords( cmd )
1116
1115
  w.unshift( w.first ) if w.first
1117
1116
  s = invoke_popen( w )
1118
- c = klass.new s
1117
+ c = klass.new s, *args
1119
1118
  @conns[s] = c
1120
1119
  yield(c) if block_given?
1121
1120
  c
@@ -1382,6 +1381,10 @@ class Connection
1382
1381
  def initialize(*args) #:nodoc:
1383
1382
  end
1384
1383
 
1384
+ def associate_callback_target(sig) #:nodoc:
1385
+ # no-op for the time being, to match similar no-op in rubymain.cpp
1386
+ end
1387
+
1385
1388
  # EventMachine::Connection#post_init is called by the event loop
1386
1389
  # immediately after the network connection has been established,
1387
1390
  # and before resumption of the network loop.
@@ -1500,7 +1503,9 @@ class Connection
1500
1503
  # connection objects. (Need an example to make that clear.)
1501
1504
  #
1502
1505
  def send_data data
1503
- EventMachine::send_data @signature, data, data.length
1506
+ size = data.bytesize if data.respond_to?(:bytesize)
1507
+ size ||= data.size
1508
+ EventMachine::send_data @signature, data, size
1504
1509
  end
1505
1510
 
1506
1511
  # Returns true if the connection is in an error state, false otherwise.
@@ -25,7 +25,7 @@
25
25
 
26
26
  module EventMachine
27
27
 
28
- VERSION = "0.12.3"
28
+ VERSION = "0.12.4"
29
29
 
30
30
  end
31
31
 
@@ -129,12 +129,12 @@ module Protocols
129
129
  if chunksize > 0
130
130
  @conn.set_text_mode(ln.to_i(16))
131
131
  else
132
- @content = @content.join
132
+ @content = @content ? @content.join : ''
133
133
  @chunk_trailer = true
134
134
  end
135
135
  else
136
136
  # We correctly come here after each chunk gets read.
137
- p "Got A BLANK chunk line"
137
+ # p "Got A BLANK chunk line"
138
138
  end
139
139
 
140
140
  end
@@ -144,7 +144,7 @@ module Protocols
144
144
  # We get a single chunk. Append it to the incoming content and switch back to line mode.
145
145
  #
146
146
  def receive_chunked_text text
147
- p "RECEIVED #{text.length} CHUNK"
147
+ # p "RECEIVED #{text.length} CHUNK"
148
148
  (@content ||= []) << text
149
149
  end
150
150
 
@@ -234,7 +234,7 @@ module Protocols
234
234
 
235
235
  h,prt,ssl = args[:host], Integer(args[:port]), (args[:tls] || args[:ssl])
236
236
  conn = EM.connect( h, prt, self )
237
- # TODO, start_tls if necessary
237
+ conn.start_tls if ssl
238
238
  conn.set_default_host_header( h, prt, ssl )
239
239
  conn
240
240
  end
@@ -27,7 +27,11 @@ require File.dirname(__FILE__) + '/buftok'
27
27
 
28
28
  module EventMachine
29
29
  module Protocols
30
-
30
+ # A protocol that handles line-oriented data with interspersed binary text.
31
+ #
32
+ # This version is optimized for performance. See EventMachine::Protocols::LineText2
33
+ # for a version which is optimized for correctness with regard to binary text blocks
34
+ # that can switch back to line mode.
31
35
  class LineAndTextProtocol < Connection
32
36
  MaxLineLength = 16*1024
33
37
  MaxBinaryLength = 32*1024*1024
@@ -24,22 +24,20 @@
24
24
  #
25
25
  #
26
26
 
27
-
28
- # In the grand, time-honored tradition of re-inventing the wheel, we offer
29
- # here YET ANOTHER protocol that handles line-oriented data with interspersed
30
- # binary text. This one trades away some of the performance optimizations of
31
- # EventMachine::Protocols::LineAndTextProtocol in order to get better correctness
32
- # with regard to binary text blocks that can switch back to line mode. It also
33
- # permits the line-delimiter to change in midstream.
34
- # This was originally written to support Stomp.
35
-
36
- # TODO! We're not enforcing the limits on header lengths and text-lengths.
37
- # When we get around to that, call #receive_error if the user defined it, otherwise
38
- # throw exceptions.
39
-
40
27
  module EventMachine
41
28
  module Protocols
29
+ # In the grand, time-honored tradition of re-inventing the wheel, we offer
30
+ # here YET ANOTHER protocol that handles line-oriented data with interspersed
31
+ # binary text. This one trades away some of the performance optimizations of
32
+ # EventMachine::Protocols::LineAndTextProtocol in order to get better correctness
33
+ # with regard to binary text blocks that can switch back to line mode. It also
34
+ # permits the line-delimiter to change in midstream.
35
+ # This was originally written to support Stomp.
42
36
  module LineText2
37
+ # TODO! We're not enforcing the limits on header lengths and text-lengths.
38
+ # When we get around to that, call #receive_error if the user defined it, otherwise
39
+ # throw exceptions.
40
+
43
41
  MaxLineLength = 16*1024
44
42
  MaxBinaryLength = 32*1024*1024
45
43
 
@@ -31,6 +31,29 @@ module EventMachine
31
31
 
32
32
  # Implements Stomp (http://docs.codehaus.org/display/STOMP/Protocol).
33
33
  #
34
+ # == Usage example
35
+ #
36
+ # class StompClient < EM::Connection
37
+ # include EM::Protocols::Stomp
38
+ #
39
+ # def connection_completed
40
+ # connect :login => 'guest', :passcode => 'guest'
41
+ # end
42
+ #
43
+ # def receive_msg msg
44
+ # if msg.command == "CONNECTED"
45
+ # subscribe '/some/topic'
46
+ # else
47
+ # p ['got a message', msg]
48
+ # puts msg.body
49
+ # end
50
+ # end
51
+ # end
52
+ #
53
+ # EM.run{
54
+ # EM.connect 'localhost', 61613, StompClient
55
+ # }
56
+ #
34
57
  module Stomp
35
58
  include LineText2
36
59
 
data/tests/test_epoll.rb CHANGED
@@ -132,6 +132,7 @@ class TestEpoll < Test::Unit::TestCase
132
132
 
133
133
 
134
134
  def test_unix_domain
135
+ fn = "/tmp/xxx.chain"
135
136
  EM.epoll
136
137
  s = EM.set_descriptor_table_size 60000
137
138
  EM.run {
@@ -143,7 +144,6 @@ class TestEpoll < Test::Unit::TestCase
143
144
  # Let's not sweat the Unix-ness of the filename, since this test can't possibly
144
145
  # work on Windows anyway.
145
146
  #
146
- fn = "/tmp/xxx.chain"
147
147
  File.unlink(fn) if File.exist?(fn)
148
148
  EM.start_unix_domain_server fn, TestEchoServer
149
149
  $n = 0
@@ -155,6 +155,8 @@ class TestEpoll < Test::Unit::TestCase
155
155
  }
156
156
  assert_equal(0, $n)
157
157
  assert_equal(50, $max)
158
+ ensure
159
+ File.unlink(fn) if File.exist?(fn)
158
160
  end
159
161
 
160
162
  end
@@ -68,52 +68,61 @@ class TestHttpClient2 < Test::Unit::TestCase
68
68
  end
69
69
 
70
70
  def test_bad_server
71
+ err = nil
71
72
  EM.run {
72
73
  http = EM::P::HttpClient2.connect Localhost, 9999
73
74
  d = http.get "/"
74
- d.errback {p d.internal_error; EM.stop }
75
+ d.errback { err = true; d.internal_error; EM.stop }
75
76
  }
77
+ assert(err)
76
78
  end
77
79
 
78
80
  def test_get
81
+ content = nil
79
82
  EM.run {
80
83
  http = EM::P::HttpClient2.connect "www.bayshorenetworks.com", 80
81
84
  d = http.get "/"
82
85
  d.callback {
83
- p d.content
86
+ content = d.content
84
87
  EM.stop
85
88
  }
86
89
  }
90
+ assert(content)
87
91
  end
88
92
 
89
93
  # Not a pipelined request because we wait for one response before we request the next.
90
94
  def test_get_multiple
95
+ content = nil
91
96
  EM.run {
92
97
  http = EM::P::HttpClient2.connect "www.bayshorenetworks.com", 80
93
98
  d = http.get "/"
94
99
  d.callback {
95
100
  e = http.get "/"
96
101
  e.callback {
97
- p e.content
102
+ content = e.content
98
103
  EM.stop
99
104
  }
100
105
  }
101
106
  }
107
+ assert(content)
102
108
  end
103
109
 
104
110
  def test_get_pipeline
111
+ headers, headers2 = nil, nil
105
112
  EM.run {
106
113
  http = EM::P::HttpClient2.connect "www.microsoft.com", 80
107
114
  d = http.get("/")
108
115
  d.callback {
109
- p d.headers
116
+ headers = d.headers
110
117
  }
111
118
  e = http.get("/")
112
119
  e.callback {
113
- p e.headers
120
+ headers2 = e.headers
114
121
  }
115
122
  EM::Timer.new(1) {EM.stop}
116
123
  }
124
+ assert(headers)
125
+ assert(headers2)
117
126
  end
118
127
 
119
128
 
@@ -126,6 +135,19 @@ class TestHttpClient2 < Test::Unit::TestCase
126
135
  d.errback {EM.stop}
127
136
  }
128
137
  end
138
+
139
+ def test_https_get
140
+ d = nil
141
+ EM.run {
142
+ http = EM::P::HttpClient2.connect :host => 'www.amazon.com', :port => 443, :ssl => true
143
+ d = http.get "/"
144
+ d.callback {
145
+ EM.stop
146
+ }
147
+ }
148
+ assert_equal(200, d.status)
149
+ end
150
+
129
151
 
130
152
 
131
153
  end
data/tests/test_ltp.rb CHANGED
@@ -62,7 +62,6 @@ class TestLineAndTextProtocol < Test::Unit::TestCase
62
62
  assert( RUBY_PLATFORM !~ /java/ )
63
63
 
64
64
  lines_received = []
65
- Thread.abort_on_exception = true
66
65
  EventMachine.run {
67
66
  EventMachine.start_server( TestHost, TestPort, SimpleLineTest ) do |conn|
68
67
  conn.instance_eval "@line_buffer = lines_received"
@@ -90,7 +89,6 @@ class TestLineAndTextProtocol < Test::Unit::TestCase
90
89
  assert( RUBY_PLATFORM !~ /java/ )
91
90
 
92
91
  lines_received = []
93
- Thread.abort_on_exception = true
94
92
  EventMachine.run {
95
93
  EventMachine.start_server( TestHost, TestPort, SimpleLineTest ) do |conn|
96
94
  conn.instance_eval "@error_message = lines_received"
@@ -130,7 +128,6 @@ class TestLineAndTextProtocol < Test::Unit::TestCase
130
128
  output = ''
131
129
  lines_received = []
132
130
  text_received = []
133
- Thread.abort_on_exception = true
134
131
  EventMachine.run {
135
132
  EventMachine.start_server( TestHost, TestPort, LineAndTextTest ) do |conn|
136
133
  conn.instance_eval "@lines = lines_received; @text = text_received"
@@ -171,7 +168,6 @@ class TestLineAndTextProtocol < Test::Unit::TestCase
171
168
  output = ''
172
169
  lines_received = []
173
170
  text_received = []
174
- Thread.abort_on_exception = true
175
171
  EventMachine.run {
176
172
  EventMachine.start_server( TestHost, TestPort, BinaryTextTest ) do |conn|
177
173
  conn.instance_eval "@lines = lines_received; @text = text_received"
@@ -188,7 +188,6 @@ class TestSendFile < Test::Unit::TestCase
188
188
  begin
189
189
  require 'fastfilereaderext'
190
190
  rescue LoadError
191
- $stderr.puts "no fastfilereaderext, not running test_stream_large_file_data"
192
191
  return
193
192
  end
194
193
  File.open( TestFilename, "w" ) {|f|
@@ -214,7 +213,6 @@ class TestSendFile < Test::Unit::TestCase
214
213
  begin
215
214
  require 'fastfilereaderext'
216
215
  rescue LoadError
217
- $stderr.puts "no fastfilereaderext, not running test_stream_large_chunked_file_data"
218
216
  return
219
217
  end
220
218
  File.open( TestFilename, "w" ) {|f|
@@ -30,52 +30,54 @@ require 'test/unit'
30
30
 
31
31
  class TestSmtpClient < Test::Unit::TestCase
32
32
 
33
- Localhost = "127.0.0.1"
34
- Localport = 9801
33
+ Localhost = "127.0.0.1"
34
+ Localport = 9801
35
35
 
36
- def setup
37
- end
36
+ def setup
37
+ end
38
38
 
39
- def teardown
40
- end
39
+ def teardown
40
+ end
41
41
 
42
- def test_a
43
- # No real tests until we have a server implementation to test against.
44
- # This is what the call looks like, though:
42
+ def test_a
43
+ # No real tests until we have a server implementation to test against.
44
+ # This is what the call looks like, though:
45
+ err = nil
46
+ EM.run {
47
+ d = EM::Protocols::SmtpClient.send :domain=>"example.com",
48
+ :host=>Localhost,
49
+ :port=>Localport, # optional, defaults 25
50
+ :starttls=>true,
51
+ :from=>"sender@example.com",
52
+ :to=> ["to_1@example.com", "to_2@example.com"],
53
+ :header=> {"Subject" => "This is a subject line"},
54
+ :body=> "This is the body of the email",
55
+ :verbose=>true
56
+ d.errback {|e|
57
+ err = e
58
+ EM.stop
59
+ }
60
+ }
61
+ assert(err)
62
+ end
45
63
 
46
- EM.run {
47
- d = EM::Protocols::SmtpClient.send :domain=>"example.com",
48
- :host=>Localhost,
49
- :port=>Localport, # optional, defaults 25
50
- :starttls=>true,
51
- :from=>"sender@example.com",
52
- :to=> ["to_1@example.com", "to_2@example.com"],
53
- :header=> {"Subject" => "This is a subject line"},
54
- :body=> "This is the body of the email",
55
- :verbose=>true
56
- d.errback {|e|
57
- p e
58
- EM.stop
59
- }
60
- }
61
- end
62
-
63
- def test_content
64
-
65
- EM.run {
66
- d = EM::Protocols::SmtpClient.send :domain=>"example.com",
67
- :host=>Localhost,
68
- :port=>Localport, # optional, defaults 25
69
- :starttls=>true,
70
- :from=>"sender@example.com",
71
- :to=> ["to_1@example.com", "to_2@example.com"],
72
- :content => ["Subject: xxx\r\n\r\ndata\r\n.\r\n"],
73
- :verbose=>true
74
- d.errback {|e|
75
- p e
76
- EM.stop
77
- }
78
- }
79
- end
64
+ def test_content
65
+ err = nil
66
+ EM.run {
67
+ d = EM::Protocols::SmtpClient.send :domain=>"example.com",
68
+ :host=>Localhost,
69
+ :port=>Localport, # optional, defaults 25
70
+ :starttls=>true,
71
+ :from=>"sender@example.com",
72
+ :to=> ["to_1@example.com", "to_2@example.com"],
73
+ :content => ["Subject: xxx\r\n\r\ndata\r\n.\r\n"],
74
+ :verbose=>true
75
+ d.errback {|e|
76
+ err = e
77
+ EM.stop
78
+ }
79
+ }
80
+ assert(err)
81
+ end
80
82
 
81
83
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eventmachine-eventmachine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.3
4
+ version: 0.12.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francis Cianfrocca
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-08 00:00:00 -08:00
12
+ date: 2009-02-08 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -112,6 +112,11 @@ files:
112
112
  - ext/eventmachine.h
113
113
  - ext/eventmachine_cpp.h
114
114
  - ext/extconf.rb
115
+ - ext/fastfilereader
116
+ - ext/fastfilereader/extconf.rb
117
+ - ext/fastfilereader/mapper.cpp
118
+ - ext/fastfilereader/mapper.h
119
+ - ext/fastfilereader/rubymain.cpp
115
120
  - ext/files.cpp
116
121
  - ext/files.h
117
122
  - ext/kb.cpp