eventmachine 0.12.0-i386-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. data/COPYING +60 -0
  2. data/DEFERRABLES +138 -0
  3. data/EPOLL +141 -0
  4. data/GNU +281 -0
  5. data/KEYBOARD +38 -0
  6. data/LEGAL +25 -0
  7. data/LIGHTWEIGHT_CONCURRENCY +72 -0
  8. data/PURE_RUBY +77 -0
  9. data/README +74 -0
  10. data/RELEASE_NOTES +96 -0
  11. data/SMTP +9 -0
  12. data/SPAWNED_PROCESSES +93 -0
  13. data/TODO +10 -0
  14. data/ext/Makefile +180 -0
  15. data/ext/binder.cpp +126 -0
  16. data/ext/binder.h +48 -0
  17. data/ext/cmain.cpp +527 -0
  18. data/ext/cplusplus.cpp +172 -0
  19. data/ext/ed.cpp +1442 -0
  20. data/ext/ed.h +351 -0
  21. data/ext/em.cpp +1781 -0
  22. data/ext/em.h +167 -0
  23. data/ext/emwin.cpp +300 -0
  24. data/ext/emwin.h +94 -0
  25. data/ext/epoll.cpp +26 -0
  26. data/ext/epoll.h +25 -0
  27. data/ext/eventmachine.h +83 -0
  28. data/ext/eventmachine_cpp.h +94 -0
  29. data/ext/extconf.rb +203 -0
  30. data/ext/files.cpp +94 -0
  31. data/ext/files.h +65 -0
  32. data/ext/kb.cpp +368 -0
  33. data/ext/mkmf.log +129 -0
  34. data/ext/page.cpp +107 -0
  35. data/ext/page.h +51 -0
  36. data/ext/pipe.cpp +327 -0
  37. data/ext/project.h +119 -0
  38. data/ext/rubyeventmachine-i386-mswin32.def +2 -0
  39. data/ext/rubyeventmachine-i386-mswin32.exp +0 -0
  40. data/ext/rubyeventmachine-i386-mswin32.lib +0 -0
  41. data/ext/rubyeventmachine-i386-mswin32.pdb +0 -0
  42. data/ext/rubyeventmachine.so +0 -0
  43. data/ext/rubymain.cpp +630 -0
  44. data/ext/sigs.cpp +89 -0
  45. data/ext/sigs.h +32 -0
  46. data/ext/ssl.cpp +408 -0
  47. data/ext/ssl.h +86 -0
  48. data/ext/vc60.pdb +0 -0
  49. data/lib/em/deferrable.rb +208 -0
  50. data/lib/em/eventable.rb +39 -0
  51. data/lib/em/future.rb +62 -0
  52. data/lib/em/messages.rb +66 -0
  53. data/lib/em/processes.rb +68 -0
  54. data/lib/em/spawnable.rb +88 -0
  55. data/lib/em/streamer.rb +112 -0
  56. data/lib/eventmachine.rb +1621 -0
  57. data/lib/eventmachine_version.rb +31 -0
  58. data/lib/evma.rb +32 -0
  59. data/lib/evma/callback.rb +32 -0
  60. data/lib/evma/container.rb +75 -0
  61. data/lib/evma/factory.rb +77 -0
  62. data/lib/evma/protocol.rb +87 -0
  63. data/lib/evma/reactor.rb +48 -0
  64. data/lib/jeventmachine.rb +106 -0
  65. data/lib/pr_eventmachine.rb +1011 -0
  66. data/lib/protocols/buftok.rb +127 -0
  67. data/lib/protocols/header_and_content.rb +123 -0
  68. data/lib/protocols/httpcli2.rb +784 -0
  69. data/lib/protocols/httpclient.rb +253 -0
  70. data/lib/protocols/line_and_text.rb +122 -0
  71. data/lib/protocols/linetext2.rb +145 -0
  72. data/lib/protocols/saslauth.rb +179 -0
  73. data/lib/protocols/smtpclient.rb +308 -0
  74. data/lib/protocols/smtpserver.rb +543 -0
  75. data/lib/protocols/stomp.rb +127 -0
  76. data/lib/protocols/tcptest.rb +57 -0
  77. data/lib/rubyeventmachine.so +0 -0
  78. data/tests/test_basic.rb +142 -0
  79. data/tests/test_defer.rb +63 -0
  80. data/tests/test_epoll.rb +168 -0
  81. data/tests/test_errors.rb +82 -0
  82. data/tests/test_eventables.rb +78 -0
  83. data/tests/test_exc.rb +58 -0
  84. data/tests/test_futures.rb +214 -0
  85. data/tests/test_hc.rb +221 -0
  86. data/tests/test_httpclient.rb +194 -0
  87. data/tests/test_httpclient2.rb +133 -0
  88. data/tests/test_kb.rb +61 -0
  89. data/tests/test_ltp.rb +190 -0
  90. data/tests/test_ltp2.rb +261 -0
  91. data/tests/test_next_tick.rb +58 -0
  92. data/tests/test_processes.rb +56 -0
  93. data/tests/test_pure.rb +128 -0
  94. data/tests/test_running.rb +47 -0
  95. data/tests/test_sasl.rb +73 -0
  96. data/tests/test_send_file.rb +238 -0
  97. data/tests/test_servers.rb +90 -0
  98. data/tests/test_smtpclient.rb +81 -0
  99. data/tests/test_smtpserver.rb +93 -0
  100. data/tests/test_spawn.rb +329 -0
  101. data/tests/test_timers.rb +138 -0
  102. data/tests/test_ud.rb +43 -0
  103. data/tests/testem.rb +5 -0
  104. metadata +170 -0
@@ -0,0 +1,127 @@
1
+ # $Id: stomp.rb 668 2008-01-04 23:00:34Z blackhedd $
2
+ #
3
+ # Author:: Francis Cianfrocca (gmail: blackhedd)
4
+ # Homepage:: http://rubyeventmachine.com
5
+ # Date:: 15 November 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
+
29
+ module EventMachine
30
+ module Protocols
31
+
32
+ # Implements Stomp (http://docs.codehaus.org/display/STOMP/Protocol).
33
+ #
34
+ module Stomp
35
+ include LineText2
36
+
37
+ class Message
38
+ attr_accessor :command, :header, :body
39
+ def initialize
40
+ @header = {}
41
+ @state = :precommand
42
+ @content_length = nil
43
+ end
44
+ def consume_line line
45
+ if @state == :precommand
46
+ unless line =~ /\A\s*\Z/
47
+ @command = line
48
+ @state = :headers
49
+ end
50
+ elsif @state == :headers
51
+ if line == ""
52
+ if @content_length
53
+ yield( [:sized_text, @content_length+1] )
54
+ else
55
+ @state = :body
56
+ yield( [:unsized_text] )
57
+ end
58
+ elsif line =~ /\A([^:]+):(.+)\Z/
59
+ k = $1.dup.strip
60
+ v = $2.dup.strip
61
+ @header[k] = v
62
+ if k == "content-length"
63
+ @content_length = v.to_i
64
+ end
65
+ else
66
+ # This is a protocol error. How to signal it?
67
+ end
68
+ elsif @state == :body
69
+ @body = line
70
+ yield( [:dispatch] )
71
+ end
72
+ end
73
+ end
74
+
75
+ def send_frame verb, headers={}, body=""
76
+ ary = [verb, "\n"]
77
+ headers.each {|k,v| ary << "#{k}:#{v}\n" }
78
+ ary << "content-length: #{body.to_s.length}\n"
79
+ ary << "content-type: text/plain; charset=UTF-8\n"
80
+ ary << "\n"
81
+ ary << body.to_s
82
+ ary << "\0"
83
+ send_data ary.join
84
+ end
85
+
86
+ def receive_line line
87
+ @stomp_initialized || init_message_reader
88
+ @stomp_message.consume_line(line) {|outcome|
89
+ if outcome.first == :sized_text
90
+ set_text_mode outcome[1]
91
+ elsif outcome.first == :unsized_text
92
+ set_delimiter "\0"
93
+ elsif outcome.first == :dispatch
94
+ receive_msg(@stomp_message) if respond_to?(:receive_msg)
95
+ init_message_reader
96
+ end
97
+ }
98
+ end
99
+ def receive_binary_data data
100
+ @stomp_message.body = data[0..-2]
101
+ receive_msg(@stomp_message) if respond_to?(:receive_msg)
102
+ init_message_reader
103
+ end
104
+
105
+ def init_message_reader
106
+ @stomp_initialized = true
107
+ set_delimiter "\n"
108
+ set_line_mode
109
+ @stomp_message = Message.new
110
+ end
111
+
112
+
113
+ # STOMP verbs
114
+ def connect parms={}
115
+ send_frame "CONNECT", parms
116
+ end
117
+ def send destination, body, parms={}
118
+ send_frame "SEND", parms.merge( :destination=>destination ), body.to_s
119
+ end
120
+ def subscribe dest, ack=false
121
+ send_frame "SUBSCRIBE", {:destination=>dest, :ack=>(ack ? "client" : "auto")}
122
+ end
123
+
124
+ end
125
+ end
126
+ end
127
+
@@ -0,0 +1,57 @@
1
+ # $Id: tcptest.rb 668 2008-01-04 23:00:34Z blackhedd $
2
+ #
3
+ # Author:: Francis Cianfrocca (gmail: blackhedd)
4
+ # Homepage:: http://rubyeventmachine.com
5
+ # Date:: 16 July 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
+
29
+ module EventMachine
30
+ module Protocols
31
+
32
+ class TcpConnectTester < Connection
33
+ include EventMachine::Deferrable
34
+
35
+ def self.test( host, port )
36
+ EventMachine.connect( host, port, self )
37
+ end
38
+
39
+ def post_init
40
+ @start_time = Time.now
41
+ end
42
+
43
+ def connection_completed
44
+ @completed = true
45
+ set_deferred_status :succeeded, (Time.now - @start_time)
46
+ close_connection
47
+ end
48
+
49
+ def unbind
50
+ set_deferred_status :failed, (Time.now - @start_time) unless @completed
51
+ end
52
+ end
53
+
54
+
55
+ end
56
+ end
57
+
Binary file
@@ -0,0 +1,142 @@
1
+ # $Id: test_basic.rb 668 2008-01-04 23:00:34Z blackhedd $
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 TestBasic < Test::Unit::TestCase
32
+
33
+ def setup
34
+ end
35
+
36
+ def teardown
37
+ end
38
+
39
+ #-------------------------------------
40
+
41
+ def test_libtype
42
+ lt = EventMachine.library_type
43
+ case (ENV["EVENTMACHINE_LIBRARY"] || $eventmachine_library || :xxx).to_sym
44
+ when :pure_ruby
45
+ assert_equal( :pure_ruby, lt )
46
+ when :extension
47
+ assert_equal( :extension, lt )
48
+ when :java
49
+ assert_equal( :java, lt )
50
+ else
51
+ assert_equal( :extension, lt )
52
+ end
53
+ end
54
+
55
+ #-------------------------------------
56
+
57
+
58
+ def test_em
59
+ EventMachine.run {
60
+ EventMachine.add_timer 0 do
61
+ EventMachine.stop
62
+ end
63
+ }
64
+ end
65
+
66
+ #-------------------------------------
67
+
68
+ def test_timer
69
+ n = 0
70
+ EventMachine.run {
71
+ EventMachine.add_periodic_timer(1) {
72
+ n += 1
73
+ EventMachine.stop if n == 2
74
+ }
75
+ }
76
+ end
77
+
78
+ #-------------------------------------
79
+
80
+ # This test once threw an already-running exception.
81
+ module Trivial
82
+ def post_init
83
+ EventMachine.stop
84
+ end
85
+ end
86
+
87
+ def test_server
88
+ EventMachine.run {
89
+ EventMachine.start_server "localhost", 9000, Trivial
90
+ EventMachine.connect "localhost", 9000
91
+ }
92
+ assert( true ) # make sure it halts
93
+ end
94
+
95
+ #--------------------------------------
96
+
97
+ # EventMachine#run_block starts the reactor loop, runs the supplied block, and then STOPS
98
+ # the loop automatically. Contrast with EventMachine#run, which keeps running the reactor
99
+ # even after the supplied block completes.
100
+ def test_run_block
101
+ a = nil
102
+ EM.run_block { a = "Worked" }
103
+ assert a
104
+ end
105
+
106
+
107
+ #--------------------------------------
108
+
109
+ # TODO! This is an unfinished edge case.
110
+ # EM mishandles uncaught Ruby exceptions that fire from within #unbind handlers.
111
+ # A uncaught Ruby exception results in a call to EM::release_machine (which is in an ensure
112
+ # block in EM::run). But if EM is processing an unbind request, the release_machine call
113
+ # will cause a segmentation fault.
114
+ #
115
+
116
+ TestHost = "127.0.0.1"
117
+ TestPort = 9070
118
+
119
+ class UnbindError < EM::Connection
120
+ def initialize *args
121
+ super
122
+ end
123
+ def connection_completed
124
+ close_connection_after_writing
125
+ end
126
+ def unbind
127
+ raise "Blooey"
128
+ end
129
+ end
130
+
131
+ def xxx_test_unbind_error
132
+ assert_raise( RuntimeError ) {
133
+ EM.run {
134
+ EM.start_server TestHost, TestPort
135
+ EM.connect TestHost, TestPort, UnbindError
136
+ }
137
+ }
138
+ end
139
+
140
+ end
141
+
142
+
@@ -0,0 +1,63 @@
1
+ # $Id: test_defer.rb 668 2008-01-04 23:00:34Z blackhedd $
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 setup
34
+ end
35
+
36
+ def teardown
37
+ end
38
+
39
+ def run_em_with_defers
40
+ n = 0
41
+ n_times = 20
42
+ EM.run {
43
+ n_times.times {
44
+ EM.defer proc {
45
+ sleep 0.1
46
+ }, proc {
47
+ n += 1
48
+ EM.stop if n == n_times
49
+ }
50
+ }
51
+ }
52
+ assert_equal( n, n_times )
53
+ end
54
+ def test_defers
55
+ 10.times {
56
+ run_em_with_defers {|n,ntimes|
57
+ assert_equal( n, ntimes )
58
+ }
59
+ }
60
+ end
61
+
62
+ end
63
+
@@ -0,0 +1,168 @@
1
+ # $Id: test_epoll.rb 668 2008-01-04 23:00:34Z blackhedd $
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
+ $:.unshift "../lib"
32
+ require 'eventmachine'
33
+ require 'test/unit'
34
+
35
+
36
+ class TestEpoll < Test::Unit::TestCase
37
+
38
+ def setup
39
+ end
40
+
41
+ def teardown
42
+ end
43
+
44
+
45
+ module TestEchoServer
46
+ def receive_data data
47
+ send_data data
48
+ close_connection_after_writing
49
+ end
50
+ end
51
+
52
+ module TestEchoClient
53
+ def connection_completed
54
+ send_data "ABCDE"
55
+ $max += 1
56
+ end
57
+ def receive_data data
58
+ raise "bad response" unless data == "ABCDE"
59
+ end
60
+ def unbind
61
+ $n -= 1
62
+ EM.stop if $n == 0
63
+ end
64
+ end
65
+
66
+
67
+ # We can set the rlimit/nofile of a process but we can only set it
68
+ # higher if we're running as root.
69
+ # On most systems, the default value is 1024.
70
+ # Java doesn't (currently) implement this.
71
+ def test_rlimit
72
+ unless RUBY_PLATFORM =~ /java/
73
+ a = EM.set_descriptor_table_size
74
+ assert( a <= 1024 )
75
+ a = EM.set_descriptor_table_size( 1024 )
76
+ assert( a == 1024 )
77
+ end
78
+ end
79
+
80
+ # Run a high-volume version of this test by kicking the number of connections
81
+ # up past 512. (Each connection uses two sockets, a client and a server.)
82
+ # (Will require running the test as root)
83
+ # This test exercises TCP clients and servers.
84
+ #
85
+ def test_descriptors
86
+ EM.epoll
87
+ s = EM.set_descriptor_table_size 60000
88
+ EM.run {
89
+ EM.start_server "127.0.0.1", 9800, TestEchoServer
90
+ $n = 0
91
+ $max = 0
92
+ 100.times {
93
+ EM.connect("127.0.0.1", 9800, TestEchoClient) {$n += 1}
94
+ }
95
+ }
96
+ assert_equal(0, $n)
97
+ assert_equal(100, $max)
98
+ end
99
+
100
+ def test_defer
101
+ $n = 0
102
+ EM.epoll
103
+ EM.run {
104
+ sleep_proc = proc {sleep 1}
105
+ return_proc = proc {$n += 1; EM.stop}
106
+ EM.defer sleep_proc, return_proc
107
+ }
108
+ assert_equal( 1, $n )
109
+ end
110
+
111
+
112
+ module TestDatagramServer
113
+ def receive_data dgm
114
+ $in = dgm
115
+ send_data "abcdefghij"
116
+ end
117
+ end
118
+ module TestDatagramClient
119
+ def post_init
120
+ send_datagram "1234567890", "127.0.0.1", 9500
121
+ end
122
+ def receive_data dgm
123
+ $out = dgm
124
+ EM.stop
125
+ end
126
+ end
127
+
128
+ def test_datagrams
129
+ $in = $out = ""
130
+ EM.epoll
131
+ EM.run {
132
+ EM.open_datagram_socket "127.0.0.1", 9500, TestDatagramServer
133
+ EM.open_datagram_socket "127.0.0.1", 0, TestDatagramClient
134
+ }
135
+ assert_equal( "1234567890", $in )
136
+ assert_equal( "abcdefghij", $out )
137
+ end
138
+
139
+
140
+
141
+
142
+ def test_unix_domain
143
+ EM.epoll
144
+ s = EM.set_descriptor_table_size 60000
145
+ EM.run {
146
+ # The pure-Ruby version won't let us open the socket if the node already exists.
147
+ # Not sure, that actually may be correct and the compiled version is wrong.
148
+ # Pure Ruby also oddly won't let us make that many connections. This test used
149
+ # to run 100 times. Not sure where that lower connection-limit is coming from in
150
+ # pure Ruby.
151
+ # Let's not sweat the Unix-ness of the filename, since this test can't possibly
152
+ # work on Windows anyway.
153
+ #
154
+ fn = "/tmp/xxx.chain"
155
+ File.unlink(fn) if File.exist?(fn)
156
+ EM.start_unix_domain_server fn, TestEchoServer
157
+ $n = 0
158
+ $max = 0
159
+ 50.times {
160
+ EM.connect_unix_domain(fn, TestEchoClient) {$n += 1}
161
+ }
162
+ }
163
+ assert_equal(0, $n)
164
+ assert_equal(50, $max)
165
+ end
166
+
167
+ end
168
+