eventmachine 0.12.2 → 0.12.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. data/Rakefile +191 -0
  2. data/{COPYING → docs/COPYING} +0 -0
  3. data/docs/ChangeLog +183 -0
  4. data/{DEFERRABLES → docs/DEFERRABLES} +1 -1
  5. data/{EPOLL → docs/EPOLL} +0 -0
  6. data/{GNU → docs/GNU} +0 -0
  7. data/docs/INSTALL +15 -0
  8. data/{KEYBOARD → docs/KEYBOARD} +0 -0
  9. data/{LEGAL → docs/LEGAL} +0 -0
  10. data/{LIGHTWEIGHT_CONCURRENCY → docs/LIGHTWEIGHT_CONCURRENCY} +1 -1
  11. data/{PURE_RUBY → docs/PURE_RUBY} +1 -1
  12. data/{README → docs/README} +1 -1
  13. data/{RELEASE_NOTES → docs/RELEASE_NOTES} +1 -1
  14. data/{SMTP → docs/SMTP} +1 -1
  15. data/{SPAWNED_PROCESSES → docs/SPAWNED_PROCESSES} +1 -1
  16. data/{TODO → docs/TODO} +1 -1
  17. data/ext/binder.cpp +1 -1
  18. data/ext/binder.h +1 -1
  19. data/ext/cmain.cpp +65 -74
  20. data/ext/cplusplus.cpp +1 -1
  21. data/ext/ed.cpp +41 -25
  22. data/ext/ed.h +10 -3
  23. data/ext/em.cpp +39 -12
  24. data/ext/em.h +13 -1
  25. data/ext/emwin.cpp +1 -1
  26. data/ext/emwin.h +1 -1
  27. data/ext/epoll.cpp +1 -1
  28. data/ext/epoll.h +1 -1
  29. data/ext/eventmachine.h +1 -1
  30. data/ext/eventmachine_cpp.h +1 -1
  31. data/ext/extconf.rb +86 -139
  32. data/ext/fastfilereader/extconf.rb +161 -0
  33. data/ext/fastfilereader/mapper.cpp +202 -0
  34. data/ext/fastfilereader/mapper.h +59 -0
  35. data/ext/fastfilereader/rubymain.cpp +127 -0
  36. data/ext/files.cpp +1 -1
  37. data/ext/files.h +1 -1
  38. data/ext/kb.cpp +1 -1
  39. data/ext/page.cpp +1 -1
  40. data/ext/page.h +1 -1
  41. data/ext/pipe.cpp +14 -7
  42. data/ext/project.h +1 -1
  43. data/ext/rubymain.cpp +56 -2
  44. data/ext/sigs.cpp +1 -1
  45. data/ext/sigs.h +1 -1
  46. data/ext/ssl.cpp +1 -1
  47. data/ext/ssl.h +1 -1
  48. data/java/src/com/rubyeventmachine/Application.java +196 -0
  49. data/java/src/com/rubyeventmachine/Connection.java +74 -0
  50. data/java/src/com/rubyeventmachine/ConnectionFactory.java +37 -0
  51. data/java/src/com/rubyeventmachine/DefaultConnectionFactory.java +46 -0
  52. data/java/src/com/rubyeventmachine/EmReactor.java +408 -0
  53. data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
  54. data/java/src/com/rubyeventmachine/EventableChannel.java +57 -0
  55. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +171 -0
  56. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +244 -0
  57. data/java/src/com/rubyeventmachine/PeriodicTimer.java +38 -0
  58. data/java/src/com/rubyeventmachine/Timer.java +54 -0
  59. data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +108 -0
  60. data/java/src/com/rubyeventmachine/tests/ConnectTest.java +124 -0
  61. data/java/src/com/rubyeventmachine/tests/EMTest.java +80 -0
  62. data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +53 -0
  63. data/java/src/com/rubyeventmachine/tests/TestServers.java +74 -0
  64. data/java/src/com/rubyeventmachine/tests/TestTimers.java +89 -0
  65. data/lib/em/deferrable.rb +1 -1
  66. data/lib/em/eventable.rb +1 -1
  67. data/lib/em/future.rb +1 -1
  68. data/lib/em/messages.rb +1 -1
  69. data/lib/em/processes.rb +1 -1
  70. data/lib/em/spawnable.rb +1 -1
  71. data/lib/em/streamer.rb +1 -1
  72. data/lib/eventmachine.rb +138 -116
  73. data/lib/eventmachine_version.rb +2 -2
  74. data/lib/evma.rb +1 -1
  75. data/lib/evma/callback.rb +1 -1
  76. data/lib/evma/container.rb +1 -1
  77. data/lib/evma/factory.rb +1 -1
  78. data/lib/evma/protocol.rb +1 -1
  79. data/lib/evma/reactor.rb +1 -1
  80. data/lib/jeventmachine.rb +7 -2
  81. data/lib/pr_eventmachine.rb +2 -2
  82. data/lib/protocols/buftok.rb +1 -1
  83. data/lib/protocols/header_and_content.rb +1 -1
  84. data/lib/protocols/httpcli2.rb +16 -6
  85. data/lib/protocols/httpclient.rb +7 -1
  86. data/lib/protocols/line_and_text.rb +6 -2
  87. data/lib/protocols/linetext2.rb +12 -14
  88. data/lib/protocols/postgres.rb +1 -1
  89. data/lib/protocols/saslauth.rb +1 -1
  90. data/lib/protocols/smtpclient.rb +1 -1
  91. data/lib/protocols/smtpserver.rb +36 -23
  92. data/lib/protocols/stomp.rb +24 -1
  93. data/lib/protocols/tcptest.rb +1 -1
  94. data/tasks/cpp.rake +77 -0
  95. data/tasks/project.rake +78 -0
  96. data/tasks/tests.rake +192 -0
  97. data/tests/test_attach.rb +1 -1
  98. data/tests/test_basic.rb +65 -12
  99. data/tests/test_defer.rb +13 -29
  100. data/tests/test_epoll.rb +16 -21
  101. data/tests/test_errors.rb +1 -1
  102. data/tests/test_eventables.rb +4 -5
  103. data/tests/test_exc.rb +1 -1
  104. data/tests/test_futures.rb +1 -1
  105. data/tests/test_hc.rb +185 -236
  106. data/tests/test_httpclient.rb +1 -1
  107. data/tests/test_httpclient2.rb +28 -6
  108. data/tests/test_kb.rb +2 -2
  109. data/tests/test_ltp.rb +139 -141
  110. data/tests/test_ltp2.rb +1 -1
  111. data/tests/test_next_tick.rb +1 -1
  112. data/tests/test_processes.rb +1 -1
  113. data/tests/test_pure.rb +3 -2
  114. data/tests/test_running.rb +1 -1
  115. data/tests/test_sasl.rb +1 -1
  116. data/tests/test_send_file.rb +56 -51
  117. data/tests/test_servers.rb +26 -36
  118. data/tests/test_smtpclient.rb +46 -44
  119. data/tests/test_smtpserver.rb +1 -1
  120. data/tests/test_spawn.rb +1 -1
  121. data/tests/test_ssl_args.rb +68 -0
  122. data/tests/test_timers.rb +15 -9
  123. data/tests/test_ud.rb +1 -1
  124. data/tests/testem.rb +30 -4
  125. metadata +69 -34
@@ -1,4 +1,4 @@
1
- # $Id: test_httpclient.rb 786 2008-09-16 07:33:27Z francis $
1
+ # $Id$
2
2
  #
3
3
  # Author:: Francis Cianfrocca (gmail: blackhedd)
4
4
  # Homepage:: http://rubyeventmachine.com
@@ -1,4 +1,4 @@
1
- # $Id: test_httpclient2.rb 668 2008-01-04 23:00:34Z blackhedd $
1
+ # $Id$
2
2
  #
3
3
  # Author:: Francis Cianfrocca (gmail: blackhedd)
4
4
  # Homepage:: http://rubyeventmachine.com
@@ -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
@@ -1,4 +1,4 @@
1
- # $Id: test_kb.rb 668 2008-01-04 23:00:34Z blackhedd $
1
+ # $Id$
2
2
  #
3
3
  # Author:: Francis Cianfrocca (gmail: blackhedd)
4
4
  # Homepage:: http://rubyeventmachine.com
@@ -55,7 +55,7 @@ class TestKeyboardEvents < Test::Unit::TestCase
55
55
  EM.open_keyboard KbHandler
56
56
  EM::Timer.new(1) { EM.stop }
57
57
  }
58
- end
58
+ end if $stdout.tty? # don't run the test unless it stands a chance of validity.
59
59
 
60
60
  end
61
61
 
@@ -1,4 +1,4 @@
1
- # $Id: test_ltp.rb 668 2008-01-04 23:00:34Z blackhedd $
1
+ # $Id$
2
2
  #
3
3
  # Author:: Francis Cianfrocca (gmail: blackhedd)
4
4
  # Homepage:: http://rubyeventmachine.com
@@ -25,166 +25,164 @@
25
25
  #
26
26
  #
27
27
 
28
- $:.unshift "../lib"
29
28
  require 'eventmachine'
30
- require 'socket'
31
29
  require 'test/unit'
32
30
 
33
31
  class TestLineAndTextProtocol < Test::Unit::TestCase
34
32
 
35
- TestHost = "127.0.0.1"
36
- TestPort = 8905
33
+ TestHost = "127.0.0.1"
34
+ TestPort = 8905
37
35
 
38
36
 
39
- #--------------------------------------------------------------------
37
+ #--------------------------------------------------------------------
40
38
 
41
- class SimpleLineTest < EventMachine::Protocols::LineAndTextProtocol
42
- def receive_line line
43
- @line_buffer << line
44
- end
39
+ class SimpleLineTest < EventMachine::Protocols::LineAndTextProtocol
40
+ def receive_line line
41
+ @line_buffer << line
45
42
  end
43
+ end
46
44
 
47
- def test_simple_lines
48
- # THIS TEST CURRENTLY FAILS IN JRUBY.
49
- assert( RUBY_PLATFORM !~ /java/ )
50
-
51
- lines_received = []
52
- Thread.abort_on_exception = true
53
- EventMachine.run {
54
- EventMachine.start_server( TestHost, TestPort, SimpleLineTest ) do |conn|
55
- conn.instance_eval "@line_buffer = lines_received"
56
- end
57
- EventMachine.add_timer(4) {raise "test timed out"}
58
- EventMachine.defer proc {
59
- t = TCPSocket.new TestHost, TestPort
60
- t.write [
61
- "aaa\n", "bbb\r\n", "ccc\n"
62
- ].join
63
- t.close
64
- }, proc {
65
- EventMachine.stop
66
- }
67
- }
68
- assert_equal( %w(aaa bbb ccc), lines_received )
45
+ module StopClient
46
+ def set_receive_data(&blk)
47
+ @rdb = blk
69
48
  end
49
+
50
+ def receive_data data
51
+ @rdb.call(data) if @rdb
52
+ end
53
+
54
+ def unbind
55
+ EM.add_timer(0.1) { EM.stop }
56
+ end
57
+ end
70
58
 
71
- #--------------------------------------------------------------------
72
59
 
73
- class SimpleLineTest < EventMachine::Protocols::LineAndTextProtocol
74
- def receive_error text
75
- @error_message << text
76
- end
77
- end
60
+ def test_simple_lines
61
+ # THIS TEST CURRENTLY FAILS IN JRUBY.
62
+ assert( RUBY_PLATFORM !~ /java/ )
78
63
 
79
- def test_overlength_lines
80
- # THIS TEST CURRENTLY FAILS IN JRUBY.
81
- assert( RUBY_PLATFORM !~ /java/ )
82
-
83
- lines_received = []
84
- Thread.abort_on_exception = true
85
- EventMachine.run {
86
- EventMachine.start_server( TestHost, TestPort, SimpleLineTest ) do |conn|
87
- conn.instance_eval "@error_message = lines_received"
88
- end
89
- EventMachine.add_timer(4) {raise "test timed out"}
90
- EventMachine.defer proc {
91
- t = TCPSocket.new TestHost, TestPort
92
- t.write "a" * (16*1024 + 1)
93
- t.write "\n"
94
- t.close
95
- }, proc {
96
- EventMachine.stop
97
- }
98
- }
99
- assert_equal( ["overlength line"], lines_received )
100
- end
64
+ lines_received = []
65
+ EventMachine.run {
66
+ EventMachine.start_server( TestHost, TestPort, SimpleLineTest ) do |conn|
67
+ conn.instance_eval "@line_buffer = lines_received"
68
+ end
69
+ EventMachine.add_timer(4) {assert(false, "test timed out")}
101
70
 
71
+ EventMachine.connect TestHost, TestPort, StopClient do |c|
72
+ c.send_data "aaa\nbbb\r\nccc\n"
73
+ c.close_connection_after_writing
74
+ end
75
+ }
76
+ assert_equal( %w(aaa bbb ccc), lines_received )
77
+ end
102
78
 
103
- #--------------------------------------------------------------------
104
-
105
- class LineAndTextTest < EventMachine::Protocols::LineAndTextProtocol
106
- def post_init
107
- end
108
- def receive_line line
109
- if line =~ /content-length:\s*(\d+)/i
110
- @content_length = $1.to_i
111
- elsif line.length == 0
112
- set_binary_mode @content_length
113
- end
114
- end
115
- def receive_binary_data text
116
- send_data "received #{text.length} bytes"
117
- close_connection_after_writing
118
- end
119
- end
79
+ #--------------------------------------------------------------------
120
80
 
121
- def test_lines_and_text
122
- output = nil
123
- lines_received = []
124
- text_received = []
125
- Thread.abort_on_exception = true
126
- EventMachine.run {
127
- EventMachine.start_server( TestHost, TestPort, LineAndTextTest ) do |conn|
128
- conn.instance_eval "@lines = lines_received; @text = text_received"
129
- end
130
- EventMachine.add_timer(2) {raise "test timed out"}
131
- EventMachine.defer proc {
132
- t = TCPSocket.new TestHost, TestPort
133
- t.puts "Content-length: 400"
134
- t.puts
135
- t.write "A" * 400
136
- output = t.read
137
- t.close
138
- }, proc {
139
- EventMachine.stop
140
- }
141
- }
142
- assert_equal( "received 400 bytes", output )
81
+ class SimpleLineTest < EventMachine::Protocols::LineAndTextProtocol
82
+ def receive_error text
83
+ @error_message << text
143
84
  end
85
+ end
144
86
 
145
- #--------------------------------------------------------------------
146
-
147
-
148
- class BinaryTextTest < EventMachine::Protocols::LineAndTextProtocol
149
- def post_init
150
- end
151
- def receive_line line
152
- if line =~ /content-length:\s*(\d+)/i
153
- set_binary_mode $1.to_i
154
- else
155
- raise "protocol error"
156
- end
157
- end
158
- def receive_binary_data text
159
- send_data "received #{text.length} bytes"
160
- close_connection_after_writing
161
- end
162
- end
87
+ def test_overlength_lines
88
+ # THIS TEST CURRENTLY FAILS IN JRUBY.
89
+ assert( RUBY_PLATFORM !~ /java/ )
163
90
 
164
- def test_binary_text
165
- output = nil
166
- lines_received = []
167
- text_received = []
168
- Thread.abort_on_exception = true
169
- EventMachine.run {
170
- EventMachine.start_server( TestHost, TestPort, BinaryTextTest ) do |conn|
171
- conn.instance_eval "@lines = lines_received; @text = text_received"
172
- end
173
- EventMachine.add_timer(4) {raise "test timed out"}
174
- EventMachine.defer proc {
175
- t = TCPSocket.new TestHost, TestPort
176
- t.puts "Content-length: 10000"
177
- t.write "A" * 10000
178
- output = t.read
179
- t.close
180
- }, proc {
181
- EventMachine.stop
182
- }
183
- }
184
- assert_equal( "received 10000 bytes", output )
185
- end
91
+ lines_received = []
92
+ EventMachine.run {
93
+ EventMachine.start_server( TestHost, TestPort, SimpleLineTest ) do |conn|
94
+ conn.instance_eval "@error_message = lines_received"
95
+ end
96
+ EventMachine.add_timer(4) {assert(false, "test timed out")}
186
97
 
187
- #--------------------------------------------------------------------
188
- end
98
+ EventMachine.connect TestHost, TestPort, StopClient do |c|
99
+ c.send_data "a" * (16*1024 + 1)
100
+ c.send_data "\n"
101
+ c.close_connection_after_writing
102
+ end
103
+
104
+ }
105
+ assert_equal( ["overlength line"], lines_received )
106
+ end
189
107
 
190
108
 
109
+ #--------------------------------------------------------------------
110
+
111
+ class LineAndTextTest < EventMachine::Protocols::LineAndTextProtocol
112
+ def post_init
113
+ end
114
+ def receive_line line
115
+ if line =~ /content-length:\s*(\d+)/i
116
+ @content_length = $1.to_i
117
+ elsif line.length == 0
118
+ set_binary_mode @content_length
119
+ end
120
+ end
121
+ def receive_binary_data text
122
+ send_data "received #{text.length} bytes"
123
+ close_connection_after_writing
124
+ end
125
+ end
126
+
127
+ def test_lines_and_text
128
+ output = ''
129
+ lines_received = []
130
+ text_received = []
131
+ EventMachine.run {
132
+ EventMachine.start_server( TestHost, TestPort, LineAndTextTest ) do |conn|
133
+ conn.instance_eval "@lines = lines_received; @text = text_received"
134
+ end
135
+ EventMachine.add_timer(4) {assert(false, "test timed out")}
136
+
137
+ EventMachine.connect TestHost, TestPort, StopClient do |c|
138
+ c.set_receive_data { |data| output << data }
139
+ c.send_data "Content-length: 400\n"
140
+ c.send_data "\n"
141
+ c.send_data "A" * 400
142
+ EM.add_timer(0.1) { c.close_connection_after_writing }
143
+ end
144
+ }
145
+ assert_equal( "received 400 bytes", output )
146
+ end
147
+
148
+ #--------------------------------------------------------------------
149
+
150
+
151
+ class BinaryTextTest < EventMachine::Protocols::LineAndTextProtocol
152
+ def post_init
153
+ end
154
+ def receive_line line
155
+ if line =~ /content-length:\s*(\d+)/i
156
+ set_binary_mode $1.to_i
157
+ else
158
+ raise "protocol error"
159
+ end
160
+ end
161
+ def receive_binary_data text
162
+ send_data "received #{text.length} bytes"
163
+ close_connection_after_writing
164
+ end
165
+ end
166
+
167
+ def test_binary_text
168
+ output = ''
169
+ lines_received = []
170
+ text_received = []
171
+ EventMachine.run {
172
+ EventMachine.start_server( TestHost, TestPort, BinaryTextTest ) do |conn|
173
+ conn.instance_eval "@lines = lines_received; @text = text_received"
174
+ end
175
+ EventMachine.add_timer(4) {assert(false, "test timed out")}
176
+
177
+ EventMachine.connect TestHost, TestPort, StopClient do |c|
178
+ c.set_receive_data { |data| output << data }
179
+ c.send_data "Content-length: 10000\n"
180
+ c.send_data "A" * 10000
181
+ EM.add_timer(0.2) { c.close_connection_after_writing }
182
+ end
183
+ }
184
+ assert_equal( "received 10000 bytes", output )
185
+ end
186
+
187
+ #--------------------------------------------------------------------
188
+ end
@@ -1,4 +1,4 @@
1
- # $Id: test_ltp2.rb 725 2008-06-29 23:04:48Z francis $
1
+ # $Id$
2
2
  #
3
3
  # Author:: Francis Cianfrocca (gmail: blackhedd)
4
4
  # Homepage:: http://rubyeventmachine.com
@@ -1,4 +1,4 @@
1
- # $Id: test_next_tick.rb 697 2008-06-15 22:00:00Z francis $
1
+ # $Id$
2
2
  #
3
3
  # Author:: Francis Cianfrocca (gmail: blackhedd)
4
4
  # Homepage:: http://rubyeventmachine.com
@@ -1,4 +1,4 @@
1
- # $Id: test_processes.rb 668 2008-01-04 23:00:34Z blackhedd $
1
+ # $Id$
2
2
  #
3
3
  # Author:: Francis Cianfrocca (gmail: blackhedd)
4
4
  # Homepage:: http://rubyeventmachine.com
@@ -1,4 +1,4 @@
1
- # $Id: test_pure.rb 668 2008-01-04 23:00:34Z blackhedd $
1
+ # $Id$
2
2
  #
3
3
  # Author:: Francis Cianfrocca (gmail: blackhedd)
4
4
  # Homepage:: http://rubyeventmachine.com
@@ -67,7 +67,8 @@ class TestPure < Test::Unit::TestCase
67
67
  assert_raise( RuntimeError ) { run_exception }
68
68
  end
69
69
  def test_exception_2
70
- assert_raise( RuntimeError ) { run_exception }
70
+ ex_class = RUBY_PLATFORM == 'java' ? NativeException : RuntimeError
71
+ assert_raise( ex_class ) { run_exception }
71
72
  end
72
73
 
73
74