eventmachine 0.12.6-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. data/.gitignore +13 -0
  2. data/Rakefile +262 -0
  3. data/docs/COPYING +60 -0
  4. data/docs/ChangeLog +211 -0
  5. data/docs/DEFERRABLES +138 -0
  6. data/docs/EPOLL +141 -0
  7. data/docs/GNU +281 -0
  8. data/docs/INSTALL +15 -0
  9. data/docs/KEYBOARD +38 -0
  10. data/docs/LEGAL +25 -0
  11. data/docs/LIGHTWEIGHT_CONCURRENCY +72 -0
  12. data/docs/PURE_RUBY +77 -0
  13. data/docs/README +74 -0
  14. data/docs/RELEASE_NOTES +96 -0
  15. data/docs/SMTP +9 -0
  16. data/docs/SPAWNED_PROCESSES +93 -0
  17. data/docs/TODO +10 -0
  18. data/eventmachine.gemspec +32 -0
  19. data/ext/binder.cpp +126 -0
  20. data/ext/binder.h +48 -0
  21. data/ext/cmain.cpp +586 -0
  22. data/ext/cplusplus.cpp +193 -0
  23. data/ext/ed.cpp +1522 -0
  24. data/ext/ed.h +380 -0
  25. data/ext/em.cpp +1937 -0
  26. data/ext/em.h +186 -0
  27. data/ext/emwin.cpp +300 -0
  28. data/ext/emwin.h +94 -0
  29. data/ext/epoll.cpp +26 -0
  30. data/ext/epoll.h +25 -0
  31. data/ext/eventmachine.h +98 -0
  32. data/ext/eventmachine_cpp.h +95 -0
  33. data/ext/extconf.rb +129 -0
  34. data/ext/fastfilereader/extconf.rb +77 -0
  35. data/ext/fastfilereader/mapper.cpp +214 -0
  36. data/ext/fastfilereader/mapper.h +59 -0
  37. data/ext/fastfilereader/rubymain.cpp +127 -0
  38. data/ext/files.cpp +94 -0
  39. data/ext/files.h +65 -0
  40. data/ext/kb.cpp +82 -0
  41. data/ext/page.cpp +107 -0
  42. data/ext/page.h +51 -0
  43. data/ext/pipe.cpp +351 -0
  44. data/ext/project.h +119 -0
  45. data/ext/rubymain.cpp +847 -0
  46. data/ext/sigs.cpp +89 -0
  47. data/ext/sigs.h +32 -0
  48. data/ext/ssl.cpp +423 -0
  49. data/ext/ssl.h +90 -0
  50. data/java/.classpath +8 -0
  51. data/java/.project +17 -0
  52. data/java/src/com/rubyeventmachine/Application.java +196 -0
  53. data/java/src/com/rubyeventmachine/Connection.java +74 -0
  54. data/java/src/com/rubyeventmachine/ConnectionFactory.java +37 -0
  55. data/java/src/com/rubyeventmachine/DefaultConnectionFactory.java +46 -0
  56. data/java/src/com/rubyeventmachine/EmReactor.java +408 -0
  57. data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
  58. data/java/src/com/rubyeventmachine/EventableChannel.java +57 -0
  59. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +171 -0
  60. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +244 -0
  61. data/java/src/com/rubyeventmachine/PeriodicTimer.java +38 -0
  62. data/java/src/com/rubyeventmachine/Timer.java +54 -0
  63. data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +108 -0
  64. data/java/src/com/rubyeventmachine/tests/ConnectTest.java +124 -0
  65. data/java/src/com/rubyeventmachine/tests/EMTest.java +80 -0
  66. data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +53 -0
  67. data/java/src/com/rubyeventmachine/tests/TestServers.java +74 -0
  68. data/java/src/com/rubyeventmachine/tests/TestTimers.java +89 -0
  69. data/lib/em/deferrable.rb +208 -0
  70. data/lib/em/eventable.rb +39 -0
  71. data/lib/em/future.rb +62 -0
  72. data/lib/em/messages.rb +66 -0
  73. data/lib/em/processes.rb +113 -0
  74. data/lib/em/spawnable.rb +88 -0
  75. data/lib/em/streamer.rb +112 -0
  76. data/lib/eventmachine.rb +1926 -0
  77. data/lib/eventmachine_version.rb +31 -0
  78. data/lib/evma.rb +32 -0
  79. data/lib/evma/callback.rb +32 -0
  80. data/lib/evma/container.rb +75 -0
  81. data/lib/evma/factory.rb +77 -0
  82. data/lib/evma/protocol.rb +87 -0
  83. data/lib/evma/reactor.rb +48 -0
  84. data/lib/jeventmachine.rb +137 -0
  85. data/lib/pr_eventmachine.rb +1011 -0
  86. data/lib/protocols/buftok.rb +127 -0
  87. data/lib/protocols/header_and_content.rb +129 -0
  88. data/lib/protocols/httpcli2.rb +803 -0
  89. data/lib/protocols/httpclient.rb +270 -0
  90. data/lib/protocols/line_and_text.rb +126 -0
  91. data/lib/protocols/linetext2.rb +161 -0
  92. data/lib/protocols/memcache.rb +293 -0
  93. data/lib/protocols/postgres.rb +261 -0
  94. data/lib/protocols/saslauth.rb +179 -0
  95. data/lib/protocols/smtpclient.rb +308 -0
  96. data/lib/protocols/smtpserver.rb +556 -0
  97. data/lib/protocols/stomp.rb +153 -0
  98. data/lib/protocols/tcptest.rb +57 -0
  99. data/setup.rb +1585 -0
  100. data/tasks/cpp.rake +77 -0
  101. data/tasks/project.rake +78 -0
  102. data/tasks/tests.rake +193 -0
  103. data/tests/test_attach.rb +83 -0
  104. data/tests/test_basic.rb +231 -0
  105. data/tests/test_connection_count.rb +45 -0
  106. data/tests/test_defer.rb +47 -0
  107. data/tests/test_epoll.rb +163 -0
  108. data/tests/test_error_handler.rb +35 -0
  109. data/tests/test_errors.rb +82 -0
  110. data/tests/test_eventables.rb +77 -0
  111. data/tests/test_exc.rb +58 -0
  112. data/tests/test_futures.rb +214 -0
  113. data/tests/test_handler_check.rb +37 -0
  114. data/tests/test_hc.rb +218 -0
  115. data/tests/test_httpclient.rb +215 -0
  116. data/tests/test_httpclient2.rb +155 -0
  117. data/tests/test_kb.rb +61 -0
  118. data/tests/test_ltp.rb +188 -0
  119. data/tests/test_ltp2.rb +320 -0
  120. data/tests/test_next_tick.rb +109 -0
  121. data/tests/test_processes.rb +95 -0
  122. data/tests/test_pure.rb +129 -0
  123. data/tests/test_running.rb +47 -0
  124. data/tests/test_sasl.rb +74 -0
  125. data/tests/test_send_file.rb +243 -0
  126. data/tests/test_servers.rb +80 -0
  127. data/tests/test_smtpclient.rb +83 -0
  128. data/tests/test_smtpserver.rb +93 -0
  129. data/tests/test_spawn.rb +329 -0
  130. data/tests/test_ssl_args.rb +68 -0
  131. data/tests/test_ssl_methods.rb +50 -0
  132. data/tests/test_timers.rb +148 -0
  133. data/tests/test_ud.rb +43 -0
  134. data/tests/testem.rb +31 -0
  135. data/web/whatis +7 -0
  136. metadata +214 -0
@@ -0,0 +1,45 @@
1
+ $:.unshift "../lib"
2
+ require 'eventmachine'
3
+ require 'test/unit'
4
+
5
+ class TestConnectionCount < Test::Unit::TestCase
6
+ def test_idle_connection_count
7
+ EM.run {
8
+ $count = EM.connection_count
9
+ EM.stop_event_loop
10
+ }
11
+
12
+ assert_equal(0, $count)
13
+ end
14
+
15
+ module Client
16
+ def connection_completed
17
+ EM.next_tick{
18
+ $client_connected = EM.connection_count
19
+ EM.stop
20
+ }
21
+ end
22
+ end
23
+
24
+ module Server
25
+ def post_init
26
+ $server_connected = EM.connection_count
27
+ end
28
+ end
29
+
30
+ def test_with_some_connections
31
+ EM.run {
32
+ EM.start_server("127.0.0.1", 9999, Server)
33
+ $initial = EM.connection_count
34
+ EM.next_tick{
35
+ $server_started = EM.connection_count
36
+ EM.connect("127.0.0.1", 9999, Client)
37
+ }
38
+ }
39
+
40
+ assert_equal(0, $initial)
41
+ assert_equal(1, $server_started)
42
+ assert_equal(2, $server_connected)
43
+ assert_equal(3, $client_connected)
44
+ end
45
+ end
@@ -0,0 +1,47 @@
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
+
27
+ $:.unshift "../lib"
28
+ require 'eventmachine'
29
+ require 'test/unit'
30
+
31
+ class TestDeferUsage < Test::Unit::TestCase
32
+
33
+ def test_defers
34
+ n = 0
35
+ n_times = 20
36
+ EM.run {
37
+ n_times.times {
38
+ work_proc = proc { n += 1 }
39
+ callback = proc { EM.stop if n == n_times }
40
+ EM.defer work_proc, callback
41
+ }
42
+ }
43
+ assert_equal( n, n_times )
44
+ end unless RUBY_VERSION >= '1.9.0'
45
+
46
+ end
47
+
@@ -0,0 +1,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
+ 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
+
@@ -0,0 +1,35 @@
1
+ $:.unshift "../lib"
2
+ require 'eventmachine'
3
+ require 'test/unit'
4
+
5
+ class TestErrorHandler < Test::Unit::TestCase
6
+ def test_error_handler
7
+ error = nil
8
+ EM.error_handler{ |e|
9
+ error = e
10
+ EM.error_handler(nil)
11
+ EM.stop
12
+ }
13
+
14
+ assert_nothing_raised do
15
+ EM.run{
16
+ EM.add_timer(0){
17
+ raise 'test'
18
+ }
19
+ }
20
+ end
21
+
22
+ assert_equal error.class, RuntimeError
23
+ assert_equal error.message, 'test'
24
+ end
25
+
26
+ def test_without_error_handler
27
+ assert_raise RuntimeError do
28
+ EM.run{
29
+ EM.add_timer(0){
30
+ raise 'test'
31
+ }
32
+ }
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,82 @@
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
+
27
+
28
+ ###### THIS TEST IS NOW OBSOLETE.
29
+ ###### As of 27Dec07, the hookable error handling is obsolete because
30
+ ###### of its performance impact.
31
+
32
+
33
+ $:.unshift "../lib"
34
+ require 'eventmachine'
35
+ require 'test/unit'
36
+
37
+ class TestErrors < Test::Unit::TestCase
38
+
39
+ Localhost = "127.0.0.1"
40
+ Localport = 9801
41
+
42
+ def setup
43
+ end
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
51
+
52
+ def test_no_tests_stub
53
+ end
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
+ }
67
+
68
+ end
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
81
+ end
82
+
@@ -0,0 +1,77 @@
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
+
27
+ $:.unshift "../lib"
28
+ require 'eventmachine'
29
+
30
+ class TestEventables < Test::Unit::TestCase
31
+
32
+ class EvTest
33
+ include EventMachine::Eventable
34
+ end
35
+
36
+ def setup
37
+ end
38
+
39
+ def teardown
40
+ end
41
+
42
+ def test_a; end # shut up rake until we define a test.
43
+
44
+ # TODO, this idea is still half-baked.
45
+ def xxx_test_a
46
+ n = 0
47
+ tester = EvTest.new
48
+ tester.listen_event( :fire1 ) {|arg|
49
+ n = 1 if arg == "$"
50
+ EventMachine.stop
51
+ }
52
+ tester.post_event( :fire1, "$" )
53
+
54
+ EventMachine.run {
55
+ EventMachine::add_timer(1) {EventMachine.stop}
56
+ }
57
+
58
+ assert_equal( 1, n )
59
+ end
60
+
61
+ end
62
+
63
+
64
+ #--------------------------------------
65
+
66
+ if __FILE__ == $0
67
+ require 'test/unit/testsuite'
68
+ require 'test/unit/ui/console/testrunner'
69
+
70
+ runner = Test::Unit::UI::Console::TestRunner
71
+ suite = Test::Unit::TestSuite.new("name")
72
+ ObjectSpace.each_object(Class) do |testcase|
73
+ suite << testcase.suite if testcase < Test::Unit::TestCase
74
+ end
75
+ runner.run(suite)
76
+ end
77
+