eventmachine 0.10.0 → 0.12.0
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.
- data/DEFERRABLES +1 -1
- data/LIGHTWEIGHT_CONCURRENCY +1 -1
- data/PURE_RUBY +1 -1
- data/README +1 -1
- data/RELEASE_NOTES +1 -1
- data/SMTP +1 -1
- data/SPAWNED_PROCESSES +1 -1
- data/TODO +1 -1
- data/ext/binder.cpp +1 -1
- data/ext/binder.h +1 -1
- data/ext/cmain.cpp +29 -1
- data/ext/cplusplus.cpp +1 -1
- data/ext/ed.cpp +79 -1
- data/ext/ed.h +6 -1
- data/ext/em.cpp +343 -27
- data/ext/em.h +25 -1
- data/ext/emwin.cpp +1 -1
- data/ext/emwin.h +1 -1
- data/ext/epoll.cpp +1 -1
- data/ext/epoll.h +1 -1
- data/ext/eventmachine.h +3 -1
- data/ext/eventmachine_cpp.h +1 -1
- data/ext/extconf.rb +31 -1
- data/ext/files.cpp +1 -1
- data/ext/files.h +1 -1
- data/ext/kb.cpp +4 -1
- data/ext/page.cpp +1 -1
- data/ext/page.h +1 -1
- data/ext/pipe.cpp +4 -1
- data/ext/project.h +8 -2
- data/ext/rubymain.cpp +73 -2
- data/ext/sigs.cpp +1 -1
- data/ext/sigs.h +1 -1
- data/ext/ssl.cpp +4 -1
- data/ext/ssl.h +1 -1
- data/lib/em/deferrable.rb +1 -1
- data/lib/em/eventable.rb +1 -1
- data/lib/em/future.rb +1 -1
- data/lib/em/messages.rb +1 -1
- data/lib/em/processes.rb +68 -0
- data/lib/em/spawnable.rb +1 -1
- data/lib/em/streamer.rb +1 -1
- data/lib/eventmachine.rb +113 -66
- data/lib/eventmachine_version.rb +2 -2
- data/lib/evma.rb +1 -1
- data/lib/evma/callback.rb +1 -1
- data/lib/evma/container.rb +1 -1
- data/lib/evma/factory.rb +1 -1
- data/lib/evma/protocol.rb +1 -1
- data/lib/evma/reactor.rb +1 -1
- data/lib/jeventmachine.rb +1 -1
- data/lib/pr_eventmachine.rb +35 -8
- data/lib/protocols/header_and_content.rb +1 -1
- data/lib/protocols/httpcli2.rb +1 -1
- data/lib/protocols/httpclient.rb +1 -1
- data/lib/protocols/line_and_text.rb +1 -1
- data/lib/protocols/linetext2.rb +1 -1
- data/lib/protocols/saslauth.rb +59 -1
- data/lib/protocols/smtpclient.rb +4 -3
- data/lib/protocols/smtpserver.rb +3 -3
- data/lib/protocols/stomp.rb +1 -1
- data/lib/protocols/tcptest.rb +1 -1
- data/tests/test_basic.rb +2 -1
- data/tests/test_defer.rb +63 -0
- data/tests/test_epoll.rb +10 -5
- data/tests/test_errors.rb +13 -3
- data/tests/test_eventables.rb +1 -1
- data/tests/test_exc.rb +2 -1
- data/tests/test_futures.rb +2 -1
- data/tests/test_hc.rb +26 -2
- data/tests/test_httpclient.rb +2 -1
- data/tests/test_httpclient2.rb +2 -1
- data/tests/test_kb.rb +2 -1
- data/tests/test_ltp.rb +3 -1
- data/tests/test_ltp2.rb +2 -1
- data/tests/test_next_tick.rb +2 -1
- data/tests/test_processes.rb +56 -0
- data/tests/test_pure.rb +2 -1
- data/tests/test_running.rb +2 -1
- data/tests/test_sasl.rb +73 -0
- data/tests/test_send_file.rb +3 -1
- data/tests/test_servers.rb +4 -1
- data/tests/test_smtpclient.rb +2 -1
- data/tests/test_smtpserver.rb +3 -2
- data/tests/test_spawn.rb +2 -1
- data/tests/test_timers.rb +2 -2
- data/tests/test_ud.rb +2 -1
- data/tests/testem.rb +1 -1
- metadata +115 -104
data/ext/ssl.cpp
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/*****************************************************************************
|
2
2
|
|
3
|
-
$Id: ssl.cpp
|
3
|
+
$Id: ssl.cpp 673 2008-01-05 04:33:01Z blackhedd $
|
4
4
|
|
5
5
|
File: ssl.cpp
|
6
6
|
Date: 30Apr06
|
@@ -370,6 +370,9 @@ int SslBox_t::PutPlaintext (const char *buf, int bufsize)
|
|
370
370
|
|
371
371
|
OutboundQ.Push (buf, bufsize);
|
372
372
|
|
373
|
+
if (!SSL_is_init_finished (pSSL))
|
374
|
+
return 0;
|
375
|
+
|
373
376
|
bool fatal = false;
|
374
377
|
bool did_work = false;
|
375
378
|
|
data/ext/ssl.h
CHANGED
data/lib/em/deferrable.rb
CHANGED
data/lib/em/eventable.rb
CHANGED
data/lib/em/future.rb
CHANGED
data/lib/em/messages.rb
CHANGED
data/lib/em/processes.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# $Id: processes.rb 668 2008-01-04 23:00:34Z blackhedd $
|
2
|
+
#
|
3
|
+
# Author:: Francis Cianfrocca (gmail: blackhedd)
|
4
|
+
# Homepage:: http://rubyeventmachine.com
|
5
|
+
# Date:: 13 Dec 07
|
6
|
+
#
|
7
|
+
# See EventMachine and EventMachine::Connection for documentation and
|
8
|
+
# usage examples.
|
9
|
+
#
|
10
|
+
#----------------------------------------------------------------------------
|
11
|
+
#
|
12
|
+
# Copyright (C) 2006-08 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
|
+
module EventMachine
|
28
|
+
|
29
|
+
# EM::DeferrableChildProcess is a sugaring of a common use-case
|
30
|
+
# involving EM::popen.
|
31
|
+
# Call the #open method on EM::DeferrableChildProcess, passing
|
32
|
+
# a command-string. #open immediately returns an EM::Deferrable
|
33
|
+
# object. It also schedules the forking of a child process, which
|
34
|
+
# will execute the command passed to #open.
|
35
|
+
# When the forked child terminates, the Deferrable will be signalled
|
36
|
+
# and execute its callbacks, passing the data that the child process
|
37
|
+
# wrote to stdout.
|
38
|
+
#
|
39
|
+
class DeferrableChildProcess < EventMachine::Connection
|
40
|
+
include EventMachine::Deferrable
|
41
|
+
|
42
|
+
# Sugars a common use-case involving forked child processes.
|
43
|
+
# #open takes a String argument containing an shell command
|
44
|
+
# string (including arguments if desired). #open immediately
|
45
|
+
# returns an EventMachine::Deferrable object, without blocking.
|
46
|
+
#
|
47
|
+
# It also invokes EventMachine#popen to run the passed-in
|
48
|
+
# command in a forked child process.
|
49
|
+
#
|
50
|
+
# When the forked child terminates, the Deferrable that
|
51
|
+
# #open calls its callbacks, passing the data returned
|
52
|
+
# from the child process.
|
53
|
+
#
|
54
|
+
def self.open cmd
|
55
|
+
EventMachine.popen( cmd, DeferrableChildProcess )
|
56
|
+
end
|
57
|
+
|
58
|
+
def receive_data data
|
59
|
+
(@data ||= []) << data
|
60
|
+
end
|
61
|
+
|
62
|
+
def unbind
|
63
|
+
succeed( @data.join )
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
|
data/lib/em/spawnable.rb
CHANGED
data/lib/em/streamer.rb
CHANGED
data/lib/eventmachine.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: eventmachine.rb
|
1
|
+
# $Id: eventmachine.rb 688 2008-05-15 23:44:39Z francis $
|
2
2
|
#
|
3
3
|
# Author:: Francis Cianfrocca (gmail: blackhedd)
|
4
4
|
# Homepage:: http://rubyeventmachine.com
|
@@ -173,60 +173,60 @@ require 'shellwords'
|
|
173
173
|
module EventMachine
|
174
174
|
|
175
175
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
176
|
+
# EventMachine::run initializes and runs an event loop.
|
177
|
+
# This method only returns if user-callback code calls stop_event_loop.
|
178
|
+
# Use the supplied block to define your clients and servers.
|
179
|
+
# The block is called by EventMachine::run immediately after initializing
|
180
|
+
# its internal event loop but <i>before</i> running the loop.
|
181
|
+
# Therefore this block is the right place to call start_server if you
|
182
|
+
# want to accept connections from remote clients.
|
183
|
+
#
|
184
|
+
# For programs that are structured as servers, it's usually appropriate
|
185
|
+
# to start an event loop by calling EventMachine::run, and let it
|
186
|
+
# run forever. It's also possible to use EventMachine::run to make a single
|
187
|
+
# client-connection to a remote server, process the data flow from that
|
188
|
+
# single connection, and then call stop_event_loop to force EventMachine::run
|
189
|
+
# to return. Your program will then continue from the point immediately
|
190
|
+
# following the call to EventMachine::run.
|
191
|
+
#
|
192
|
+
# You can of course do both client and servers simultaneously in the same program.
|
193
|
+
# One of the strengths of the event-driven programming model is that the
|
194
|
+
# handling of network events on many different connections will be interleaved,
|
195
|
+
# and scheduled according to the actual events themselves. This maximizes
|
196
|
+
# efficiency.
|
197
|
+
#
|
198
|
+
# === Server usage example
|
199
|
+
#
|
200
|
+
# See the text at the top of this file for an example of an echo server.
|
201
|
+
#
|
202
|
+
# === Client usage example
|
203
|
+
#
|
204
|
+
# See the description of stop_event_loop for an extremely simple client example.
|
205
|
+
#
|
206
|
+
#--
|
207
|
+
# Obsoleted the use_threads mechanism.
|
208
|
+
# 25Nov06: Added the begin/ensure block. We need to be sure that release_machine
|
209
|
+
# gets called even if an exception gets thrown within any of the user code
|
210
|
+
# that the event loop runs. The best way to see this is to run a unit
|
211
|
+
# test with two functions, each of which calls EventMachine#run and each of
|
212
|
+
# which throws something inside of #run. Without the ensure, the second test
|
213
|
+
# will start without release_machine being called and will immediately throw
|
214
|
+
# a C++ runtime error.
|
215
|
+
#
|
216
|
+
def EventMachine::run &block
|
217
|
+
@conns = {}
|
218
|
+
@acceptors = {}
|
219
|
+
@timers = {}
|
220
|
+
begin
|
221
|
+
@reactor_running = true
|
222
|
+
initialize_event_machine
|
223
|
+
block and add_timer 0, block
|
224
|
+
run_machine
|
225
|
+
ensure
|
226
|
+
release_machine
|
227
|
+
@reactor_running = false
|
228
|
+
end
|
228
229
|
end
|
229
|
-
end
|
230
230
|
|
231
231
|
|
232
232
|
# Sugars a common use case. Will pass the given block to #run, but will terminate
|
@@ -919,6 +919,7 @@ module EventMachine
|
|
919
919
|
@threadqueue << [op,callback]
|
920
920
|
end
|
921
921
|
|
922
|
+
|
922
923
|
# Schedules a proc for execution immediately after the next "turn" through the reactor
|
923
924
|
# core. An advanced technique, this can be useful for improving memory management and/or
|
924
925
|
# application responsiveness, especially when scheduling large amounts of data for
|
@@ -1027,15 +1028,21 @@ module EventMachine
|
|
1027
1028
|
# (Experimental)
|
1028
1029
|
#
|
1029
1030
|
#
|
1030
|
-
def EventMachine::open_keyboard handler=nil
|
1031
|
+
def EventMachine::open_keyboard handler=nil, *args
|
1031
1032
|
klass = if (handler and handler.is_a?(Class))
|
1032
1033
|
handler
|
1033
1034
|
else
|
1034
1035
|
Class.new( Connection ) {handler and include handler}
|
1035
1036
|
end
|
1036
1037
|
|
1038
|
+
arity = klass.instance_method(:initialize).arity
|
1039
|
+
expected = arity >= 0 ? arity : -(arity + 1)
|
1040
|
+
if (arity >= 0 and args.size != expected) or (arity < 0 and args.size < expected)
|
1041
|
+
raise ArgumentError, "wrong number of arguments for #{klass}#initialize (#{args.size} for #{expected})"
|
1042
|
+
end
|
1043
|
+
|
1037
1044
|
s = read_keyboard
|
1038
|
-
c = klass.new s
|
1045
|
+
c = klass.new s, *args
|
1039
1046
|
@conns[s] = c
|
1040
1047
|
block_given? and yield c
|
1041
1048
|
c
|
@@ -1045,6 +1052,42 @@ module EventMachine
|
|
1045
1052
|
|
1046
1053
|
private
|
1047
1054
|
def EventMachine::event_callback conn_binding, opcode, data
|
1055
|
+
#
|
1056
|
+
# Changed 27Dec07: Eliminated the hookable error handling.
|
1057
|
+
# No one was using it, and it degraded performance significantly.
|
1058
|
+
# It's in original_event_callback, which is dead code.
|
1059
|
+
#
|
1060
|
+
if opcode == ConnectionData
|
1061
|
+
c = @conns[conn_binding] or raise ConnectionNotBound
|
1062
|
+
c.receive_data data
|
1063
|
+
elsif opcode == ConnectionUnbound
|
1064
|
+
if c = @conns.delete( conn_binding )
|
1065
|
+
c.unbind
|
1066
|
+
elsif c = @acceptors.delete( conn_binding )
|
1067
|
+
# no-op
|
1068
|
+
else
|
1069
|
+
raise ConnectionNotBound
|
1070
|
+
end
|
1071
|
+
elsif opcode == ConnectionAccepted
|
1072
|
+
accep,args,blk = @acceptors[conn_binding]
|
1073
|
+
raise NoHandlerForAcceptedConnection unless accep
|
1074
|
+
c = accep.new data, *args
|
1075
|
+
@conns[data] = c
|
1076
|
+
blk and blk.call(c)
|
1077
|
+
c # (needed?)
|
1078
|
+
elsif opcode == TimerFired
|
1079
|
+
t = @timers.delete( data ) or raise UnknownTimerFired
|
1080
|
+
t.call
|
1081
|
+
elsif opcode == ConnectionCompleted
|
1082
|
+
c = @conns[conn_binding] or raise ConnectionNotBound
|
1083
|
+
c.connection_completed
|
1084
|
+
elsif opcode == LoopbreakSignalled
|
1085
|
+
run_deferred_callbacks
|
1086
|
+
end
|
1087
|
+
end
|
1088
|
+
|
1089
|
+
private
|
1090
|
+
def EventMachine::original_event_callback conn_binding, opcode, data
|
1048
1091
|
#
|
1049
1092
|
# Added 03Oct07: Any code path that invokes user-written code must
|
1050
1093
|
# wrap itself in a begin/rescue for RuntimeErrors, that calls the
|
@@ -1195,11 +1238,8 @@ class Connection
|
|
1195
1238
|
|
1196
1239
|
# Store signature and run #post_init
|
1197
1240
|
@signature = sig
|
1198
|
-
|
1199
|
-
|
1200
|
-
rescue
|
1201
|
-
EventMachine::handle_runtime_error
|
1202
|
-
end
|
1241
|
+
associate_callback_target sig
|
1242
|
+
post_init
|
1203
1243
|
|
1204
1244
|
self
|
1205
1245
|
end
|
@@ -1421,6 +1461,15 @@ class Connection
|
|
1421
1461
|
EventMachine::get_peername @signature
|
1422
1462
|
end
|
1423
1463
|
|
1464
|
+
# #get_sockname is used with stream-connections to obtain the identity
|
1465
|
+
# of the local side of the connection. If a local name is available, this method
|
1466
|
+
# returns a sockaddr structure. The method returns nil if no local name is available.
|
1467
|
+
# You can use Socket#unpack_sockaddr_in and its variants to obtain the
|
1468
|
+
# values contained in the local-name structure returned from #get_sockname.
|
1469
|
+
def get_sockname
|
1470
|
+
EventMachine::get_sockname @signature
|
1471
|
+
end
|
1472
|
+
|
1424
1473
|
# Returns the PID (kernel process identifier) of a subprocess
|
1425
1474
|
# associated with this Connection object. For use with EventMachine#popen
|
1426
1475
|
# and similar methods. Returns nil when there is no meaningful subprocess.
|
@@ -1503,6 +1552,7 @@ class Connection
|
|
1503
1552
|
#
|
1504
1553
|
#
|
1505
1554
|
class EventMachine::PeriodicTimer
|
1555
|
+
attr_accessor :interval
|
1506
1556
|
def initialize *args, &block
|
1507
1557
|
@interval = args.shift
|
1508
1558
|
@code = args.shift || block
|
@@ -1512,11 +1562,7 @@ class Connection
|
|
1512
1562
|
EventMachine::add_timer @interval, proc {self.fire}
|
1513
1563
|
end
|
1514
1564
|
def fire
|
1515
|
-
|
1516
|
-
@code.call
|
1517
|
-
rescue
|
1518
|
-
EventMachine::handle_runtime_error
|
1519
|
-
end
|
1565
|
+
@code.call
|
1520
1566
|
schedule unless @cancelled
|
1521
1567
|
end
|
1522
1568
|
def cancel
|
@@ -1571,5 +1617,6 @@ require 'protocols/smtpclient'
|
|
1571
1617
|
require 'protocols/smtpserver'
|
1572
1618
|
require 'protocols/saslauth'
|
1573
1619
|
|
1620
|
+
require 'em/processes'
|
1574
1621
|
|
1575
1622
|
|
data/lib/eventmachine_version.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: eventmachine_version.rb
|
1
|
+
# $Id: eventmachine_version.rb 686 2008-05-14 21:21:10Z francis $
|
2
2
|
#
|
3
3
|
# Author:: Francis Cianfrocca (gmail: blackhedd)
|
4
4
|
# Homepage:: http://rubyeventmachine.com
|
@@ -25,7 +25,7 @@
|
|
25
25
|
|
26
26
|
module EventMachine
|
27
27
|
|
28
|
-
VERSION = "0.
|
28
|
+
VERSION = "0.12.0"
|
29
29
|
|
30
30
|
end
|
31
31
|
|
data/lib/evma.rb
CHANGED
data/lib/evma/callback.rb
CHANGED
data/lib/evma/container.rb
CHANGED
data/lib/evma/factory.rb
CHANGED
data/lib/evma/protocol.rb
CHANGED
data/lib/evma/reactor.rb
CHANGED