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,81 @@
1
+ # $Id: test_smtpclient.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 TestSmtpClient < Test::Unit::TestCase
32
+
33
+ Localhost = "127.0.0.1"
34
+ Localport = 9801
35
+
36
+ def setup
37
+ end
38
+
39
+ def teardown
40
+ end
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:
45
+
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
80
+
81
+ end
@@ -0,0 +1,93 @@
1
+ # $Id: test_smtpserver.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 TestSmtpServer < Test::Unit::TestCase
32
+
33
+ # Don't test on port 25. It requires superuser and there's probably
34
+ # a mail server already running there anyway.
35
+ Localhost = "127.0.0.1"
36
+ Localport = 25001
37
+
38
+ # This class is an example of what you need to write in order
39
+ # to implement a mail server. You override the methods you are
40
+ # interested in. Some, but not all, of these are illustrated here.
41
+ #
42
+ class Mailserver < EM::Protocols::SmtpServer
43
+
44
+ attr_reader :my_msg_body, :my_sender, :my_recipients
45
+
46
+ def initialize *args
47
+ super
48
+ end
49
+ def receive_sender sender
50
+ @my_sender = sender
51
+ #p sender
52
+ true
53
+ end
54
+ def receive_recipient rcpt
55
+ @my_recipients ||= []
56
+ @my_recipients << rcpt
57
+ true
58
+ end
59
+ def receive_data_chunk c
60
+ @my_msg_body = c.last
61
+ end
62
+ def connection_ended
63
+ EM.stop
64
+ end
65
+ end
66
+
67
+
68
+ def setup
69
+ end
70
+
71
+ def teardown
72
+ end
73
+
74
+ def test_mail
75
+ c = nil
76
+ EM.run {
77
+ EM.start_server( Localhost, Localport, Mailserver ) {|conn| c = conn}
78
+ EM::Timer.new(2) {EM.stop} # prevent hanging the test suite in case of error
79
+ EM::Protocols::SmtpClient.send :host=>Localhost,
80
+ :port=>Localport,
81
+ :domain=>"bogus",
82
+ :from=>"me@example.com",
83
+ :to=>"you@example.com",
84
+ :header=> {"Subject"=>"Email subject line", "Reply-to"=>"me@example.com"},
85
+ :body=>"Not much of interest here."
86
+
87
+ }
88
+ assert_equal( "Not much of interest here.", c.my_msg_body )
89
+ assert_equal( "<me@example.com>", c.my_sender )
90
+ assert_equal( ["<you@example.com>"], c.my_recipients )
91
+ end
92
+ end
93
+
@@ -0,0 +1,329 @@
1
+ # $Id: test_spawn.rb 668 2008-01-04 23:00:34Z blackhedd $
2
+ #
3
+ # Author:: Francis Cianfrocca (gmail: blackhedd)
4
+ # Homepage:: http://rubyeventmachine.com
5
+ # Date:: 25 Aug 2007
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
+ $:.unshift "../lib"
30
+ require 'eventmachine'
31
+ require 'test/unit'
32
+
33
+
34
+
35
+ class TestSpawn < Test::Unit::TestCase
36
+
37
+ def setup
38
+ end
39
+
40
+ def teardown
41
+ end
42
+
43
+
44
+ # Spawn a process that simply stops the reactor.
45
+ # Assert that the notification runs after the block that calls it.
46
+ #
47
+ def test_stop
48
+ x = nil
49
+ EM.run {
50
+ s = EM.spawn {EM.stop}
51
+ s.notify
52
+ x = true
53
+ }
54
+ assert x
55
+ end
56
+
57
+
58
+ # Pass a parameter to a spawned process.
59
+ #
60
+ def test_parms
61
+ val = 5
62
+ EM.run {
63
+ s = EM.spawn {|v| val *= v; EM.stop}
64
+ s.notify 3
65
+ }
66
+ assert_equal( 15, val )
67
+ end
68
+
69
+ # Pass multiple parameters to a spawned process.
70
+ #
71
+ def test_multiparms
72
+ val = 5
73
+ EM.run {
74
+ s = EM.spawn {|v1,v2| val *= (v1 + v2); EM.stop}
75
+ s.notify 3,4
76
+ }
77
+ assert_equal( 35, val )
78
+ end
79
+
80
+
81
+ # This test demonstrates that a notification does not happen immediately,
82
+ # but rather is scheduled sometime after the current code path completes.
83
+ #
84
+ def test_race
85
+ x = 0
86
+ EM.run {
87
+ s = EM.spawn {x *= 2; EM.stop}
88
+ s.notify
89
+ x = 2
90
+ }
91
+ assert_equal( 4, x)
92
+ end
93
+
94
+
95
+ # Spawn a process and notify it 25 times to run fibonacci
96
+ # on a pair of global variables.
97
+ #
98
+ def test_fibonacci
99
+ x = 1
100
+ y = 1
101
+ EM.run {
102
+ s = EM.spawn {x,y = y,x+y}
103
+ 25.times {s.notify}
104
+
105
+ t = EM.spawn {EM.stop}
106
+ t.notify
107
+ }
108
+ assert_equal( 121393, x)
109
+ assert_equal( 196418, y)
110
+ end
111
+
112
+ # This one spawns 25 distinct processes, and notifies each one once,
113
+ # rather than notifying a single process 25 times.
114
+ #
115
+ def test_another_fibonacci
116
+ x = 1
117
+ y = 1
118
+ EM.run {
119
+ 25.times {
120
+ s = EM.spawn {x,y = y,x+y}
121
+ s.notify
122
+ }
123
+
124
+ t = EM.spawn {EM.stop}
125
+ t.notify
126
+ }
127
+ assert_equal( 121393, x)
128
+ assert_equal( 196418, y)
129
+ end
130
+
131
+
132
+ # Make a chain of processes that notify each other in turn
133
+ # with intermediate fibonacci results. The final process in
134
+ # the chain stops the loop and returns the result.
135
+ #
136
+ def test_fibonacci_chain
137
+ a,b = nil
138
+
139
+ EM.run {
140
+ nextpid = EM.spawn {|x,y|
141
+ a,b = x,y
142
+ EM.stop
143
+ }
144
+
145
+ 25.times {
146
+ n = nextpid
147
+ nextpid = EM.spawn {|x,y| n.notify( y, x+y )}
148
+ }
149
+
150
+ nextpid.notify( 1, 1 )
151
+ }
152
+
153
+ assert_equal( 121393, a)
154
+ assert_equal( 196418, b)
155
+ end
156
+
157
+
158
+ # EM#yield gives a spawed process to yield control to other processes
159
+ # (in other words, to stop running), and to specify a different code block
160
+ # that will run on its next notification.
161
+ #
162
+ def test_yield
163
+ a = 0
164
+ EM.run {
165
+ n = EM.spawn {
166
+ a += 10
167
+ EM.yield {
168
+ a += 20
169
+ EM.yield {
170
+ a += 30
171
+ EM.stop
172
+ }
173
+ }
174
+ }
175
+ n.notify
176
+ n.notify
177
+ n.notify
178
+ }
179
+ assert_equal( 60, a )
180
+ end
181
+
182
+ # EM#yield_and_notify behaves like EM#yield, except that it also notifies the
183
+ # yielding process. This may sound trivial, since the yield block will run very
184
+ # shortly after with no action by the program, but this actually can be very useful,
185
+ # because it causes the reactor core to execute once before the yielding process
186
+ # gets control back. So it can be used to allow heavily-used network connections
187
+ # to clear buffers, or allow other processes to process their notifications.
188
+ #
189
+ # Notice in this test code that only a simple notify is needed at the bottom
190
+ # of the initial block. Even so, all of the yielded blocks will execute.
191
+ #
192
+ def test_yield_and_notify
193
+ a = 0
194
+ EM.run {
195
+ n = EM.spawn {
196
+ a += 10
197
+ EM.yield_and_notify {
198
+ a += 20
199
+ EM.yield_and_notify {
200
+ a += 30
201
+ EM.stop
202
+ }
203
+ }
204
+ }
205
+ n.notify
206
+ }
207
+ assert_equal( 60, a )
208
+ end
209
+
210
+ # resume is an alias for notify.
211
+ #
212
+ def test_resume
213
+ EM.run {
214
+ n = EM.spawn {EM.stop}
215
+ n.resume
216
+ }
217
+ assert true
218
+ end
219
+
220
+ # run is an idiomatic alias for notify.
221
+ #
222
+ def test_run
223
+ EM.run {
224
+ (EM.spawn {EM.stop}).run
225
+ }
226
+ assert true
227
+ end
228
+
229
+
230
+ # Clones the ping-pong example from the Erlang tutorial, in much less code.
231
+ # Illustrates that a spawned block executes in the context of a SpawnableObject.
232
+ # (Meaning, we can pass self as a parameter to another process that can then
233
+ # notify us.)
234
+ #
235
+ def test_ping_pong
236
+ n_pongs = 0
237
+ EM.run {
238
+ pong = EM.spawn {|x, ping|
239
+ n_pongs += 1
240
+ ping.notify( x-1 )
241
+ }
242
+ ping = EM.spawn {|x|
243
+ if x > 0
244
+ pong.notify x, self
245
+ else
246
+ EM.stop
247
+ end
248
+ }
249
+ ping.notify 3
250
+ }
251
+ assert_equal( 3, n_pongs )
252
+ end
253
+
254
+ # Illustrates that you can call notify inside a notification, and it will cause
255
+ # the currently-executing process to be re-notified. Of course, the new notification
256
+ # won't run until sometime after the current one completes.
257
+ #
258
+ def test_self_notify
259
+ n = 0
260
+ EM.run {
261
+ pid = EM.spawn {|x|
262
+ if x > 0
263
+ n += x
264
+ notify( x-1 )
265
+ else
266
+ EM.stop
267
+ end
268
+ }
269
+ pid.notify 3
270
+ }
271
+ assert_equal( 6, n )
272
+ end
273
+
274
+
275
+ # Illustrates that the block passed to #spawn executes in the context of a
276
+ # SpawnedProcess object, NOT in the local context. This can often be deceptive.
277
+ #
278
+ class BlockScopeTest
279
+ attr_reader :var
280
+ def run
281
+ # The following line correctly raises a NameError.
282
+ # The problem is that the programmer expected the spawned block to
283
+ # execute in the local context, but it doesn't.
284
+ #
285
+ # (EM.spawn { do_something }).notify ### NO! BAD!
286
+
287
+
288
+
289
+ # The following line correctly passes self as a parameter to the
290
+ # notified process.
291
+ #
292
+ (EM.spawn {|obj| obj.do_something }).notify(self)
293
+
294
+
295
+
296
+ # Here's another way to do it. This works because "myself" is bound
297
+ # in the local scope, unlike "self," so the spawned block sees it.
298
+ #
299
+ myself = self
300
+ (EM.spawn { myself.do_something }).notify
301
+
302
+
303
+
304
+ # And we end the loop.
305
+ # This is a tangential point, but observe that #notify never blocks.
306
+ # It merely appends a message to the internal queue of a spawned process
307
+ # and returns. As it turns out, the reactor processes notifications for ALL
308
+ # spawned processes in the order that #notify is called. So there is a
309
+ # reasonable expectation that the process which stops the reactor will
310
+ # execute after the previous ones in this method. HOWEVER, this is NOT
311
+ # a documented behavior and is subject to change.
312
+ #
313
+ (EM.spawn {EM.stop}).notify
314
+ end
315
+ def do_something
316
+ @var ||= 0
317
+ @var += 100
318
+ end
319
+ end
320
+
321
+ def test_block_scope
322
+ bs = BlockScopeTest.new
323
+ EM.run {
324
+ bs.run
325
+ }
326
+ assert_equal( 200, bs.var )
327
+ end
328
+
329
+ end