eventmachine 0.12.6-x86-mswin32-60 → 0.12.8-x86-mswin32-60

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 (116) hide show
  1. data/{docs/README → README} +21 -13
  2. data/Rakefile +14 -4
  3. data/docs/DEFERRABLES +0 -5
  4. data/docs/INSTALL +2 -4
  5. data/docs/LEGAL +1 -1
  6. data/docs/LIGHTWEIGHT_CONCURRENCY +0 -2
  7. data/docs/PURE_RUBY +0 -2
  8. data/docs/RELEASE_NOTES +0 -2
  9. data/docs/SMTP +0 -7
  10. data/docs/SPAWNED_PROCESSES +0 -4
  11. data/docs/TODO +0 -2
  12. data/eventmachine.gemspec +41 -32
  13. data/examples/ex_channel.rb +43 -0
  14. data/examples/ex_queue.rb +2 -0
  15. data/examples/helper.rb +2 -0
  16. data/ext/cmain.cpp +685 -586
  17. data/ext/cplusplus.cpp +15 -6
  18. data/ext/ed.cpp +1732 -1522
  19. data/ext/ed.h +407 -380
  20. data/ext/em.cpp +2263 -1937
  21. data/ext/em.h +223 -186
  22. data/ext/eventmachine.h +111 -98
  23. data/ext/eventmachine_cpp.h +1 -0
  24. data/ext/extconf.rb +4 -0
  25. data/ext/kb.cpp +81 -82
  26. data/ext/pipe.cpp +349 -351
  27. data/ext/project.h +21 -0
  28. data/ext/rubymain.cpp +1047 -847
  29. data/ext/ssl.cpp +38 -1
  30. data/ext/ssl.h +5 -1
  31. data/java/src/com/rubyeventmachine/Application.java +7 -3
  32. data/java/src/com/rubyeventmachine/EmReactor.java +16 -1
  33. data/java/src/com/rubyeventmachine/tests/ConnectTest.java +25 -3
  34. data/lib/{protocols → em}/buftok.rb +16 -5
  35. data/lib/em/callback.rb +26 -0
  36. data/lib/em/channel.rb +57 -0
  37. data/lib/em/connection.rb +505 -0
  38. data/lib/em/deferrable.rb +144 -165
  39. data/lib/em/file_watch.rb +54 -0
  40. data/lib/em/future.rb +24 -25
  41. data/lib/em/messages.rb +1 -1
  42. data/lib/em/process_watch.rb +44 -0
  43. data/lib/em/processes.rb +119 -113
  44. data/lib/em/protocols.rb +35 -0
  45. data/lib/em/protocols/header_and_content.rb +138 -0
  46. data/lib/em/protocols/httpclient.rb +263 -0
  47. data/lib/em/protocols/httpclient2.rb +582 -0
  48. data/lib/{protocols → em/protocols}/line_and_text.rb +2 -2
  49. data/lib/em/protocols/linetext2.rb +160 -0
  50. data/lib/{protocols → em/protocols}/memcache.rb +37 -7
  51. data/lib/em/protocols/object_protocol.rb +39 -0
  52. data/lib/em/protocols/postgres3.rb +247 -0
  53. data/lib/em/protocols/saslauth.rb +175 -0
  54. data/lib/em/protocols/smtpclient.rb +331 -0
  55. data/lib/em/protocols/smtpserver.rb +547 -0
  56. data/lib/em/protocols/stomp.rb +200 -0
  57. data/lib/{protocols → em/protocols}/tcptest.rb +21 -25
  58. data/lib/em/queue.rb +61 -0
  59. data/lib/em/spawnable.rb +53 -56
  60. data/lib/em/streamer.rb +92 -74
  61. data/lib/em/timers.rb +55 -0
  62. data/lib/em/version.rb +3 -0
  63. data/lib/eventmachine.rb +1636 -1926
  64. data/lib/evma.rb +1 -1
  65. data/lib/jeventmachine.rb +106 -101
  66. data/lib/pr_eventmachine.rb +47 -36
  67. data/tasks/project.rake +2 -1
  68. data/tests/client.crt +31 -0
  69. data/tests/client.key +51 -0
  70. data/tests/test_attach.rb +18 -0
  71. data/tests/test_basic.rb +285 -231
  72. data/tests/test_channel.rb +63 -0
  73. data/tests/test_connection_count.rb +2 -2
  74. data/tests/test_epoll.rb +162 -163
  75. data/tests/test_errors.rb +36 -36
  76. data/tests/test_exc.rb +22 -25
  77. data/tests/test_file_watch.rb +49 -0
  78. data/tests/test_futures.rb +77 -93
  79. data/tests/test_hc.rb +2 -2
  80. data/tests/test_httpclient.rb +55 -52
  81. data/tests/test_httpclient2.rb +153 -155
  82. data/tests/test_inactivity_timeout.rb +30 -0
  83. data/tests/test_kb.rb +8 -9
  84. data/tests/test_ltp2.rb +274 -277
  85. data/tests/test_next_tick.rb +135 -109
  86. data/tests/test_object_protocol.rb +37 -0
  87. data/tests/test_process_watch.rb +48 -0
  88. data/tests/test_processes.rb +128 -95
  89. data/tests/test_proxy_connection.rb +92 -0
  90. data/tests/test_pure.rb +1 -5
  91. data/tests/test_queue.rb +44 -0
  92. data/tests/test_running.rb +9 -14
  93. data/tests/test_sasl.rb +32 -34
  94. data/tests/test_send_file.rb +175 -176
  95. data/tests/test_servers.rb +37 -41
  96. data/tests/test_smtpserver.rb +47 -55
  97. data/tests/test_spawn.rb +284 -291
  98. data/tests/test_ssl_args.rb +1 -1
  99. data/tests/test_ssl_methods.rb +1 -1
  100. data/tests/test_ssl_verify.rb +82 -0
  101. data/tests/test_timers.rb +81 -88
  102. data/tests/test_ud.rb +0 -7
  103. data/tests/testem.rb +1 -1
  104. metadata +52 -36
  105. data/lib/em/eventable.rb +0 -39
  106. data/lib/eventmachine_version.rb +0 -31
  107. data/lib/protocols/header_and_content.rb +0 -129
  108. data/lib/protocols/httpcli2.rb +0 -803
  109. data/lib/protocols/httpclient.rb +0 -270
  110. data/lib/protocols/linetext2.rb +0 -161
  111. data/lib/protocols/postgres.rb +0 -261
  112. data/lib/protocols/saslauth.rb +0 -179
  113. data/lib/protocols/smtpclient.rb +0 -308
  114. data/lib/protocols/smtpserver.rb +0 -556
  115. data/lib/protocols/stomp.rb +0 -153
  116. data/tests/test_eventables.rb +0 -77
@@ -0,0 +1,63 @@
1
+ $:.unshift "../lib"
2
+ require 'eventmachine'
3
+ require 'test/unit'
4
+
5
+ class TestEventMachineChannel < Test::Unit::TestCase
6
+ def test_channel_subscribe
7
+ s = 0
8
+ EM.run do
9
+ c = EM::Channel.new
10
+ c.subscribe { |v| s = v; EM.stop }
11
+ c << 1
12
+ end
13
+ assert_equal 1, s
14
+ end
15
+
16
+ def test_channel_unsubscribe
17
+ s = 0
18
+ EM.run do
19
+ c = EM::Channel.new
20
+ subscription = c.subscribe { |v| s = v }
21
+ c.unsubscribe(subscription)
22
+ c << 1
23
+ EM.next_tick { EM.stop }
24
+ end
25
+ assert_not_equal 1, s
26
+ end
27
+
28
+ def test_channel_pop
29
+ s = 0
30
+ EM.run do
31
+ c = EM::Channel.new
32
+ c.pop{ |v| s = v }
33
+ c << 1
34
+ c << 2
35
+ EM.next_tick { EM.stop }
36
+ end
37
+ assert_equal 1, s
38
+ end
39
+
40
+ def test_channel_reactor_thread_push
41
+ out = []
42
+ c = EM::Channel.new
43
+ c.subscribe { |v| out << v }
44
+ Thread.new { c.push(1,2,3) }.join
45
+ assert out.empty?
46
+
47
+ EM.run { EM.next_tick { EM.stop } }
48
+
49
+ assert_equal [1,2,3], out
50
+ end
51
+
52
+ def test_channel_reactor_thread_callback
53
+ out = []
54
+ c = EM::Channel.new
55
+ Thread.new { c.subscribe { |v| out << v } }.join
56
+ c.push(1,2,3)
57
+ assert out.empty?
58
+
59
+ EM.run { EM.next_tick { EM.stop } }
60
+
61
+ assert_equal [1,2,3], out
62
+ end
63
+ end
@@ -29,10 +29,10 @@ class TestConnectionCount < Test::Unit::TestCase
29
29
 
30
30
  def test_with_some_connections
31
31
  EM.run {
32
- EM.start_server("127.0.0.1", 9999, Server)
33
32
  $initial = EM.connection_count
33
+ EM.start_server("127.0.0.1", 9999, Server)
34
+ $server_started = EM.connection_count
34
35
  EM.next_tick{
35
- $server_started = EM.connection_count
36
36
  EM.connect("127.0.0.1", 9999, Client)
37
37
  }
38
38
  }
data/tests/test_epoll.rb CHANGED
@@ -1,163 +1,162 @@
1
- # $Id$
2
- #
3
- # Author:: Francis Cianfrocca (gmail: blackhedd)
4
- # Homepage:: http://rubyeventmachine.com
5
- # Date:: 8 April 2006
6
- #
7
- # See EventMachine and EventMachine::Connection for documentation and
8
- # usage examples.
9
- #
10
- #----------------------------------------------------------------------------
11
- #
12
- # Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
13
- # Gmail: blackhedd
14
- #
15
- # This program is free software; you can redistribute it and/or modify
16
- # it under the terms of either: 1) the GNU General Public License
17
- # as published by the Free Software Foundation; either version 2 of the
18
- # License, or (at your option) any later version; or 2) Ruby's License.
19
- #
20
- # See the file COPYING for complete licensing information.
21
- #
22
- #---------------------------------------------------------------------------
23
- #
24
- #
25
- #
26
- # TODO, and I know this doesn't belong here, but if a datagram calls
27
- # send_data outside of a receive_data, there is no return address, and
28
- # the result is a very confusing error message.
29
- #
30
-
31
- require 'eventmachine'
32
- require 'test/unit'
33
-
34
-
35
- class TestEpoll < Test::Unit::TestCase
36
-
37
- module TestEchoServer
38
- def receive_data data
39
- send_data data
40
- close_connection_after_writing
41
- end
42
- end
43
-
44
- module TestEchoClient
45
- def connection_completed
46
- send_data "ABCDE"
47
- $max += 1
48
- end
49
- def receive_data data
50
- raise "bad response" unless data == "ABCDE"
51
- end
52
- def unbind
53
- $n -= 1
54
- EM.stop if $n == 0
55
- end
56
- end
57
-
58
-
59
- # We can set the rlimit/nofile of a process but we can only set it
60
- # higher if we're running as root.
61
- # On most systems, the default value is 1024.
62
- # Java doesn't (currently) implement this.
63
- def test_rlimit
64
- unless RUBY_PLATFORM =~ /java/ or EM.set_descriptor_table_size >= 1024
65
- a = EM.set_descriptor_table_size
66
- assert( a <= 1024 )
67
- a = EM.set_descriptor_table_size( 1024 )
68
- assert( a == 1024 )
69
- end
70
- end
71
-
72
- # Run a high-volume version of this test by kicking the number of connections
73
- # up past 512. (Each connection uses two sockets, a client and a server.)
74
- # (Will require running the test as root)
75
- # This test exercises TCP clients and servers.
76
- #
77
- def test_descriptors
78
- EM.epoll
79
- s = EM.set_descriptor_table_size 60000
80
- EM.run {
81
- EM.start_server "127.0.0.1", 9800, TestEchoServer
82
- $n = 0
83
- $max = 0
84
- 100.times {
85
- EM.connect("127.0.0.1", 9800, TestEchoClient) {$n += 1}
86
- }
87
- }
88
- assert_equal(0, $n)
89
- assert_equal(100, $max)
90
- end
91
-
92
- def test_defer
93
- n = 0
94
- work_proc = proc {n += 1}
95
- callback_proc = proc {EM.stop}
96
- EM.epoll
97
- EM.run {
98
- EM.defer work_proc, callback_proc
99
- }
100
- assert_equal( 1, n )
101
- end unless RUBY_VERSION >= '1.9.0'
102
-
103
-
104
- module TestDatagramServer
105
- def receive_data dgm
106
- $in = dgm
107
- send_data "abcdefghij"
108
- end
109
- end
110
- module TestDatagramClient
111
- def post_init
112
- send_datagram "1234567890", "127.0.0.1", 9500
113
- end
114
- def receive_data dgm
115
- $out = dgm
116
- EM.stop
117
- end
118
- end
119
-
120
- def test_datagrams
121
- $in = $out = ""
122
- EM.epoll
123
- EM.run {
124
- EM.open_datagram_socket "127.0.0.1", 9500, TestDatagramServer
125
- EM.open_datagram_socket "127.0.0.1", 0, TestDatagramClient
126
- }
127
- assert_equal( "1234567890", $in )
128
- assert_equal( "abcdefghij", $out )
129
- end
130
-
131
-
132
-
133
-
134
- def test_unix_domain
135
- fn = "/tmp/xxx.chain"
136
- EM.epoll
137
- s = EM.set_descriptor_table_size 60000
138
- EM.run {
139
- # The pure-Ruby version won't let us open the socket if the node already exists.
140
- # Not sure, that actually may be correct and the compiled version is wrong.
141
- # Pure Ruby also oddly won't let us make that many connections. This test used
142
- # to run 100 times. Not sure where that lower connection-limit is coming from in
143
- # pure Ruby.
144
- # Let's not sweat the Unix-ness of the filename, since this test can't possibly
145
- # work on Windows anyway.
146
- #
147
- File.unlink(fn) if File.exist?(fn)
148
- EM.start_unix_domain_server fn, TestEchoServer
149
- $n = 0
150
- $max = 0
151
- 50.times {
152
- EM.connect_unix_domain(fn, TestEchoClient) {$n += 1}
153
- }
154
- EM::add_timer(1) { $stderr.puts("test_unix_domain timed out!"); EM::stop }
155
- }
156
- assert_equal(0, $n)
157
- assert_equal(50, $max)
158
- ensure
159
- File.unlink(fn) if File.exist?(fn)
160
- end
161
-
162
- end
163
-
1
+ # $Id$
2
+ #
3
+ # Author:: Francis Cianfrocca (gmail: blackhedd)
4
+ # Homepage:: http://rubyeventmachine.com
5
+ # Date:: 8 April 2006
6
+ #
7
+ # See EventMachine and EventMachine::Connection for documentation and
8
+ # usage examples.
9
+ #
10
+ #----------------------------------------------------------------------------
11
+ #
12
+ # Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
13
+ # Gmail: blackhedd
14
+ #
15
+ # This program is free software; you can redistribute it and/or modify
16
+ # it under the terms of either: 1) the GNU General Public License
17
+ # as published by the Free Software Foundation; either version 2 of the
18
+ # License, or (at your option) any later version; or 2) Ruby's License.
19
+ #
20
+ # See the file COPYING for complete licensing information.
21
+ #
22
+ #---------------------------------------------------------------------------
23
+ #
24
+ #
25
+ #
26
+ # TODO, and I know this doesn't belong here, but if a datagram calls
27
+ # send_data outside of a receive_data, there is no return address, and
28
+ # the result is a very confusing error message.
29
+ #
30
+
31
+ require 'eventmachine'
32
+ require 'test/unit'
33
+
34
+
35
+ class TestEpoll < Test::Unit::TestCase
36
+
37
+ module TestEchoServer
38
+ def receive_data data
39
+ send_data data
40
+ close_connection_after_writing
41
+ end
42
+ end
43
+
44
+ module TestEchoClient
45
+ def connection_completed
46
+ send_data "ABCDE"
47
+ $max += 1
48
+ end
49
+ def receive_data data
50
+ raise "bad response" unless data == "ABCDE"
51
+ end
52
+ def unbind
53
+ $n -= 1
54
+ EM.stop if $n == 0
55
+ end
56
+ end
57
+
58
+
59
+ # We can set the rlimit/nofile of a process but we can only set it
60
+ # higher if we're running as root.
61
+ # On most systems, the default value is 1024.
62
+ # Java doesn't (currently) implement this.
63
+ def test_rlimit
64
+ unless RUBY_PLATFORM =~ /java/ or EM.set_descriptor_table_size >= 1024
65
+ a = EM.set_descriptor_table_size
66
+ assert( a <= 1024 )
67
+ a = EM.set_descriptor_table_size( 1024 )
68
+ assert( a == 1024 )
69
+ end
70
+ end
71
+
72
+ # Run a high-volume version of this test by kicking the number of connections
73
+ # up past 512. (Each connection uses two sockets, a client and a server.)
74
+ # (Will require running the test as root)
75
+ # This test exercises TCP clients and servers.
76
+ #
77
+ # XXX this test causes all sort of weird issues on OSX (when run as part of the suite)
78
+ def _test_descriptors
79
+ EM.epoll
80
+ s = EM.set_descriptor_table_size 60000
81
+ EM.run {
82
+ EM.start_server "127.0.0.1", 9800, TestEchoServer
83
+ $n = 0
84
+ $max = 0
85
+ 100.times {
86
+ EM.connect("127.0.0.1", 9800, TestEchoClient) {$n += 1}
87
+ }
88
+ }
89
+ assert_equal(0, $n)
90
+ assert_equal(100, $max)
91
+ end
92
+
93
+ def test_defer
94
+ n = 0
95
+ work_proc = proc {n += 1}
96
+ callback_proc = proc {EM.stop}
97
+ EM.epoll
98
+ EM.run {
99
+ EM.defer work_proc, callback_proc
100
+ }
101
+ assert_equal( 1, n )
102
+ end unless RUBY_VERSION >= '1.9.0'
103
+
104
+
105
+ module TestDatagramServer
106
+ def receive_data dgm
107
+ $in = dgm
108
+ send_data "abcdefghij"
109
+ end
110
+ end
111
+ module TestDatagramClient
112
+ def post_init
113
+ send_datagram "1234567890", "127.0.0.1", 9500
114
+ end
115
+ def receive_data dgm
116
+ $out = dgm
117
+ EM.stop
118
+ end
119
+ end
120
+
121
+ def test_datagrams
122
+ $in = $out = ""
123
+ EM.epoll
124
+ EM.run {
125
+ EM.open_datagram_socket "127.0.0.1", 9500, TestDatagramServer
126
+ EM.open_datagram_socket "127.0.0.1", 0, TestDatagramClient
127
+ }
128
+ assert_equal( "1234567890", $in )
129
+ assert_equal( "abcdefghij", $out )
130
+ end
131
+
132
+ # XXX this test fails randomly..
133
+ def _test_unix_domain
134
+ fn = "/tmp/xxx.chain"
135
+ EM.epoll
136
+ s = EM.set_descriptor_table_size 60000
137
+ EM.run {
138
+ # The pure-Ruby version won't let us open the socket if the node already exists.
139
+ # Not sure, that actually may be correct and the compiled version is wrong.
140
+ # Pure Ruby also oddly won't let us make that many connections. This test used
141
+ # to run 100 times. Not sure where that lower connection-limit is coming from in
142
+ # pure Ruby.
143
+ # Let's not sweat the Unix-ness of the filename, since this test can't possibly
144
+ # work on Windows anyway.
145
+ #
146
+ File.unlink(fn) if File.exist?(fn)
147
+ EM.start_unix_domain_server fn, TestEchoServer
148
+ $n = 0
149
+ $max = 0
150
+ 50.times {
151
+ EM.connect_unix_domain(fn, TestEchoClient) {$n += 1}
152
+ }
153
+ EM::add_timer(1) { $stderr.puts("test_unix_domain timed out!"); EM::stop }
154
+ }
155
+ assert_equal(0, $n)
156
+ assert_equal(50, $max)
157
+ ensure
158
+ File.unlink(fn) if File.exist?(fn)
159
+ end
160
+
161
+ end
162
+
data/tests/test_errors.rb CHANGED
@@ -36,47 +36,47 @@ require 'test/unit'
36
36
 
37
37
  class TestErrors < Test::Unit::TestCase
38
38
 
39
- Localhost = "127.0.0.1"
40
- Localport = 9801
39
+ Localhost = "127.0.0.1"
40
+ Localport = 9801
41
41
 
42
- def setup
43
- end
42
+ def setup
43
+ end
44
44
 
45
- def obsolete_teardown
46
- # Calling #set_runtime_error_hook with no block restores the
47
- # default handling of runtime_errors.
48
- #
49
- EM.set_runtime_error_hook
50
- end
45
+ def obsolete_teardown
46
+ # Calling #set_runtime_error_hook with no block restores the
47
+ # default handling of runtime_errors.
48
+ #
49
+ EM.set_runtime_error_hook
50
+ end
51
51
 
52
- def test_no_tests_stub
53
- end
52
+ def test_no_tests_stub
53
+ end
54
54
 
55
- # EM has a default handler for RuntimeErrors that are emitted from
56
- # user written code. You can override the handler if you wish, but it's
57
- # easier to call #set_runtime_error_hook.
58
- # Ordinarily, an error in user code invoked by the reactor aborts the
59
- # run.
60
- #
61
- def obsolete_test_unhandled_error
62
- assert_raises( RuntimeError ) {
63
- EM.run {
64
- EM.add_timer(0) {raise "AAA"}
65
- }
66
- }
55
+ # EM has a default handler for RuntimeErrors that are emitted from
56
+ # user written code. You can override the handler if you wish, but it's
57
+ # easier to call #set_runtime_error_hook.
58
+ # Ordinarily, an error in user code invoked by the reactor aborts the
59
+ # run.
60
+ #
61
+ def obsolete_test_unhandled_error
62
+ assert_raises( RuntimeError ) {
63
+ EM.run {
64
+ EM.add_timer(0) {raise "AAA"}
65
+ }
66
+ }
67
67
 
68
- end
68
+ end
69
69
 
70
- def obsolete_test_handled_error
71
- err = nil
72
- EM.run {
73
- EM.set_runtime_error_hook {
74
- err = true
75
- EM.stop
76
- }
77
- EM.add_timer(0) {raise "AAA"}
78
- }
79
- assert err
80
- end
70
+ def obsolete_test_handled_error
71
+ err = nil
72
+ EM.run {
73
+ EM.set_runtime_error_hook {
74
+ err = true
75
+ EM.stop
76
+ }
77
+ EM.add_timer(0) {raise "AAA"}
78
+ }
79
+ assert err
80
+ end
81
81
  end
82
82