eventmachine 0.12.6-x86-mswin32-60 → 0.12.8-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/{docs/README → README} +21 -13
- data/Rakefile +14 -4
- data/docs/DEFERRABLES +0 -5
- data/docs/INSTALL +2 -4
- data/docs/LEGAL +1 -1
- data/docs/LIGHTWEIGHT_CONCURRENCY +0 -2
- data/docs/PURE_RUBY +0 -2
- data/docs/RELEASE_NOTES +0 -2
- data/docs/SMTP +0 -7
- data/docs/SPAWNED_PROCESSES +0 -4
- data/docs/TODO +0 -2
- data/eventmachine.gemspec +41 -32
- data/examples/ex_channel.rb +43 -0
- data/examples/ex_queue.rb +2 -0
- data/examples/helper.rb +2 -0
- data/ext/cmain.cpp +685 -586
- data/ext/cplusplus.cpp +15 -6
- data/ext/ed.cpp +1732 -1522
- data/ext/ed.h +407 -380
- data/ext/em.cpp +2263 -1937
- data/ext/em.h +223 -186
- data/ext/eventmachine.h +111 -98
- data/ext/eventmachine_cpp.h +1 -0
- data/ext/extconf.rb +4 -0
- data/ext/kb.cpp +81 -82
- data/ext/pipe.cpp +349 -351
- data/ext/project.h +21 -0
- data/ext/rubymain.cpp +1047 -847
- data/ext/ssl.cpp +38 -1
- data/ext/ssl.h +5 -1
- data/java/src/com/rubyeventmachine/Application.java +7 -3
- data/java/src/com/rubyeventmachine/EmReactor.java +16 -1
- data/java/src/com/rubyeventmachine/tests/ConnectTest.java +25 -3
- data/lib/{protocols → em}/buftok.rb +16 -5
- data/lib/em/callback.rb +26 -0
- data/lib/em/channel.rb +57 -0
- data/lib/em/connection.rb +505 -0
- data/lib/em/deferrable.rb +144 -165
- data/lib/em/file_watch.rb +54 -0
- data/lib/em/future.rb +24 -25
- data/lib/em/messages.rb +1 -1
- data/lib/em/process_watch.rb +44 -0
- data/lib/em/processes.rb +119 -113
- data/lib/em/protocols.rb +35 -0
- data/lib/em/protocols/header_and_content.rb +138 -0
- data/lib/em/protocols/httpclient.rb +263 -0
- data/lib/em/protocols/httpclient2.rb +582 -0
- data/lib/{protocols → em/protocols}/line_and_text.rb +2 -2
- data/lib/em/protocols/linetext2.rb +160 -0
- data/lib/{protocols → em/protocols}/memcache.rb +37 -7
- data/lib/em/protocols/object_protocol.rb +39 -0
- data/lib/em/protocols/postgres3.rb +247 -0
- data/lib/em/protocols/saslauth.rb +175 -0
- data/lib/em/protocols/smtpclient.rb +331 -0
- data/lib/em/protocols/smtpserver.rb +547 -0
- data/lib/em/protocols/stomp.rb +200 -0
- data/lib/{protocols → em/protocols}/tcptest.rb +21 -25
- data/lib/em/queue.rb +61 -0
- data/lib/em/spawnable.rb +53 -56
- data/lib/em/streamer.rb +92 -74
- data/lib/em/timers.rb +55 -0
- data/lib/em/version.rb +3 -0
- data/lib/eventmachine.rb +1636 -1926
- data/lib/evma.rb +1 -1
- data/lib/jeventmachine.rb +106 -101
- data/lib/pr_eventmachine.rb +47 -36
- data/tasks/project.rake +2 -1
- data/tests/client.crt +31 -0
- data/tests/client.key +51 -0
- data/tests/test_attach.rb +18 -0
- data/tests/test_basic.rb +285 -231
- data/tests/test_channel.rb +63 -0
- data/tests/test_connection_count.rb +2 -2
- data/tests/test_epoll.rb +162 -163
- data/tests/test_errors.rb +36 -36
- data/tests/test_exc.rb +22 -25
- data/tests/test_file_watch.rb +49 -0
- data/tests/test_futures.rb +77 -93
- data/tests/test_hc.rb +2 -2
- data/tests/test_httpclient.rb +55 -52
- data/tests/test_httpclient2.rb +153 -155
- data/tests/test_inactivity_timeout.rb +30 -0
- data/tests/test_kb.rb +8 -9
- data/tests/test_ltp2.rb +274 -277
- data/tests/test_next_tick.rb +135 -109
- data/tests/test_object_protocol.rb +37 -0
- data/tests/test_process_watch.rb +48 -0
- data/tests/test_processes.rb +128 -95
- data/tests/test_proxy_connection.rb +92 -0
- data/tests/test_pure.rb +1 -5
- data/tests/test_queue.rb +44 -0
- data/tests/test_running.rb +9 -14
- data/tests/test_sasl.rb +32 -34
- data/tests/test_send_file.rb +175 -176
- data/tests/test_servers.rb +37 -41
- data/tests/test_smtpserver.rb +47 -55
- data/tests/test_spawn.rb +284 -291
- data/tests/test_ssl_args.rb +1 -1
- data/tests/test_ssl_methods.rb +1 -1
- data/tests/test_ssl_verify.rb +82 -0
- data/tests/test_timers.rb +81 -88
- data/tests/test_ud.rb +0 -7
- data/tests/testem.rb +1 -1
- metadata +52 -36
- data/lib/em/eventable.rb +0 -39
- data/lib/eventmachine_version.rb +0 -31
- data/lib/protocols/header_and_content.rb +0 -129
- data/lib/protocols/httpcli2.rb +0 -803
- data/lib/protocols/httpclient.rb +0 -270
- data/lib/protocols/linetext2.rb +0 -161
- data/lib/protocols/postgres.rb +0 -261
- data/lib/protocols/saslauth.rb +0 -179
- data/lib/protocols/smtpclient.rb +0 -308
- data/lib/protocols/smtpserver.rb +0 -556
- data/lib/protocols/stomp.rb +0 -153
- data/tests/test_eventables.rb +0 -77
data/lib/em/messages.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
module EventMachine
|
2
|
+
|
3
|
+
# This is subclassed from EventMachine::Connection for use with the process monitoring API. Read the
|
4
|
+
# documentation on the instance methods of this class, and for a full explanation see EventMachine.watch_process.
|
5
|
+
class ProcessWatch < Connection
|
6
|
+
# :stopdoc:
|
7
|
+
Cfork = 'fork'.freeze
|
8
|
+
Cexit = 'exit'.freeze
|
9
|
+
# :startdoc:
|
10
|
+
|
11
|
+
def receive_data(data) # :nodoc:
|
12
|
+
case data
|
13
|
+
when Cfork
|
14
|
+
process_forked
|
15
|
+
when Cexit
|
16
|
+
process_exited
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Returns the pid that EventMachine::watch_process was originally called with.
|
21
|
+
def pid
|
22
|
+
@pid
|
23
|
+
end
|
24
|
+
|
25
|
+
# Should be redefined with the user's custom callback that will be fired when the prcess is forked.
|
26
|
+
#
|
27
|
+
# There is currently not an easy way to get the pid of the forked child.
|
28
|
+
def process_forked
|
29
|
+
end
|
30
|
+
|
31
|
+
# Should be redefined with the user's custom callback that will be fired when the process exits.
|
32
|
+
#
|
33
|
+
# stop_watching is called automatically after this callback
|
34
|
+
def process_exited
|
35
|
+
end
|
36
|
+
|
37
|
+
# Discontinue monitoring of the process.
|
38
|
+
# This will be called automatically when a process dies. User code may call it as well.
|
39
|
+
def stop_watching
|
40
|
+
EventMachine::unwatch_pid(@signature)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/lib/em/processes.rb
CHANGED
@@ -1,113 +1,119 @@
|
|
1
|
-
|
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
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
88
|
-
#
|
89
|
-
#
|
90
|
-
#
|
91
|
-
#
|
92
|
-
#
|
93
|
-
#
|
94
|
-
#
|
95
|
-
#
|
96
|
-
#
|
97
|
-
#
|
98
|
-
#
|
99
|
-
#
|
100
|
-
#
|
101
|
-
#
|
102
|
-
#
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
1
|
+
#--
|
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
|
+
def initialize # :nodoc:
|
43
|
+
super
|
44
|
+
@data = []
|
45
|
+
end
|
46
|
+
|
47
|
+
# Sugars a common use-case involving forked child processes.
|
48
|
+
# #open takes a String argument containing an shell command
|
49
|
+
# string (including arguments if desired). #open immediately
|
50
|
+
# returns an EventMachine::Deferrable object, without blocking.
|
51
|
+
#
|
52
|
+
# It also invokes EventMachine#popen to run the passed-in
|
53
|
+
# command in a forked child process.
|
54
|
+
#
|
55
|
+
# When the forked child terminates, the Deferrable that
|
56
|
+
# #open calls its callbacks, passing the data returned
|
57
|
+
# from the child process.
|
58
|
+
#
|
59
|
+
def self.open cmd
|
60
|
+
EventMachine.popen( cmd, DeferrableChildProcess )
|
61
|
+
end
|
62
|
+
|
63
|
+
def receive_data data # :nodoc:
|
64
|
+
@data << data
|
65
|
+
end
|
66
|
+
|
67
|
+
def unbind # :nodoc:
|
68
|
+
succeed( @data.join )
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
class SystemCmd < EventMachine::Connection # :nodoc:
|
73
|
+
def initialize cb
|
74
|
+
@cb = cb
|
75
|
+
@output = []
|
76
|
+
end
|
77
|
+
def receive_data data
|
78
|
+
@output << data
|
79
|
+
end
|
80
|
+
def unbind
|
81
|
+
@cb.call @output.join(''), get_status if @cb
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# EM::system is a simple wrapper for EM::popen. It is similar to Kernel::system, but requires a
|
86
|
+
# single string argument for the command and performs no shell expansion.
|
87
|
+
#
|
88
|
+
# The block or proc passed to EM::system is called with two arguments: the output generated by the command,
|
89
|
+
# and a Process::Status that contains information about the command's execution.
|
90
|
+
#
|
91
|
+
# EM.run{
|
92
|
+
# EM.system('ls'){ |output,status| puts output if status.exitstatus == 0 }
|
93
|
+
# }
|
94
|
+
#
|
95
|
+
# You can also supply an additional proc to send some data to the process:
|
96
|
+
#
|
97
|
+
# EM.run{
|
98
|
+
# EM.system('sh', proc{ |process|
|
99
|
+
# process.send_data("echo hello\n")
|
100
|
+
# process.send_data("exit\n")
|
101
|
+
# }, proc{ |out,status|
|
102
|
+
# puts(out)
|
103
|
+
# })
|
104
|
+
# }
|
105
|
+
#
|
106
|
+
# Like EventMachine.popen, EventMachine.system currently does not work on windows.
|
107
|
+
# It returns the pid of the spawned process.
|
108
|
+
def EventMachine::system cmd, *args, &cb
|
109
|
+
cb ||= args.pop if args.last.is_a? Proc
|
110
|
+
init = args.pop if args.last.is_a? Proc
|
111
|
+
|
112
|
+
# merge remaining arguments into the command
|
113
|
+
cmd = ([cmd] + args.map{|a|a.to_s.dump}).join(' ')
|
114
|
+
|
115
|
+
EM.get_subprocess_pid(EM.popen(cmd, SystemCmd, cb) do |c|
|
116
|
+
init[c] if init
|
117
|
+
end.signature)
|
118
|
+
end
|
119
|
+
end
|
data/lib/em/protocols.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module EventMachine
|
2
|
+
# This module contains various protocol implementations, including:
|
3
|
+
# - HttpClient and HttpClient2
|
4
|
+
# - Stomp
|
5
|
+
# - Memcache
|
6
|
+
# - SmtpClient and SmtpServer
|
7
|
+
# - SASLauth and SASLauthclient
|
8
|
+
# - LineAndTextProtocol and LineText2
|
9
|
+
# - HeaderAndContentProtocol
|
10
|
+
# - Postgres3
|
11
|
+
# - ObjectProtocol
|
12
|
+
#
|
13
|
+
# The protocol implementations live in separate files in the protocols/ subdirectory,
|
14
|
+
# but are auto-loaded when they are first referenced in your application.
|
15
|
+
#
|
16
|
+
# EventMachine::Protocols is also aliased to EM::P for easier usage.
|
17
|
+
#
|
18
|
+
module Protocols
|
19
|
+
# TODO : various autotools are completely useless with the lack of naming
|
20
|
+
# convention, we need to correct that!
|
21
|
+
autoload :TcpConnectTester, 'em/protocols/tcptest'
|
22
|
+
autoload :HttpClient, 'em/protocols/httpclient'
|
23
|
+
autoload :HttpClient2, 'em/protocols/httpclient2'
|
24
|
+
autoload :LineAndTextProtocol, 'em/protocols/line_and_text'
|
25
|
+
autoload :HeaderAndContentProtocol, 'em/protocols/header_and_content'
|
26
|
+
autoload :LineText2, 'em/protocols/linetext2'
|
27
|
+
autoload :Stomp, 'em/protocols/stomp'
|
28
|
+
autoload :SmtpClient, 'em/protocols/smtpclient'
|
29
|
+
autoload :SmtpServer, 'em/protocols/smtpserver'
|
30
|
+
autoload :SASLauth, 'em/protocols/saslauth'
|
31
|
+
autoload :Memcache, 'em/protocols/memcache'
|
32
|
+
autoload :Postgres3, 'em/protocols/postgres3'
|
33
|
+
autoload :ObjectProtocol, 'em/protocols/object_protocol'
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
#--
|
2
|
+
#
|
3
|
+
# Author:: Francis Cianfrocca (gmail: blackhedd)
|
4
|
+
# Homepage:: http://rubyeventmachine.com
|
5
|
+
# Date:: 15 Nov 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
|
+
module EventMachine
|
27
|
+
module Protocols
|
28
|
+
|
29
|
+
# === Usage
|
30
|
+
#
|
31
|
+
# class RequestHandler < EM::P::HeaderAndContentProtocol
|
32
|
+
# def receive_request headers, content
|
33
|
+
# p [:request, headers, content]
|
34
|
+
# end
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# EM.run{
|
38
|
+
# EM.start_server 'localhost', 80, RequestHandler
|
39
|
+
# }
|
40
|
+
#
|
41
|
+
#--
|
42
|
+
# Originally, this subclassed LineAndTextProtocol, which in
|
43
|
+
# turn relies on BufferedTokenizer, which doesn't gracefully
|
44
|
+
# handle the transitions between lines and binary text.
|
45
|
+
# Changed 13Sep08 by FCianfrocca.
|
46
|
+
class HeaderAndContentProtocol < Connection
|
47
|
+
include LineText2
|
48
|
+
|
49
|
+
ContentLengthPattern = /Content-length:\s*(\d+)/i
|
50
|
+
|
51
|
+
def initialize *args
|
52
|
+
super
|
53
|
+
init_for_request
|
54
|
+
end
|
55
|
+
|
56
|
+
def receive_line line
|
57
|
+
case @hc_mode
|
58
|
+
when :discard_blanks
|
59
|
+
unless line == ""
|
60
|
+
@hc_mode = :headers
|
61
|
+
receive_line line
|
62
|
+
end
|
63
|
+
when :headers
|
64
|
+
if line == ""
|
65
|
+
raise "unrecognized state" unless @hc_headers.length > 0
|
66
|
+
if respond_to?(:receive_headers)
|
67
|
+
receive_headers @hc_headers
|
68
|
+
end
|
69
|
+
# @hc_content_length will be nil, not 0, if there was no content-length header.
|
70
|
+
if @hc_content_length.to_i > 0
|
71
|
+
set_binary_mode @hc_content_length
|
72
|
+
else
|
73
|
+
dispatch_request
|
74
|
+
end
|
75
|
+
else
|
76
|
+
@hc_headers << line
|
77
|
+
if ContentLengthPattern =~ line
|
78
|
+
# There are some attacks that rely on sending multiple content-length
|
79
|
+
# headers. This is a crude protection, but needs to become tunable.
|
80
|
+
raise "extraneous content-length header" if @hc_content_length
|
81
|
+
@hc_content_length = $1.to_i
|
82
|
+
end
|
83
|
+
if @hc_headers.length == 1 and respond_to?(:receive_first_header_line)
|
84
|
+
receive_first_header_line line
|
85
|
+
end
|
86
|
+
end
|
87
|
+
else
|
88
|
+
raise "internal error, unsupported mode"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def receive_binary_data text
|
93
|
+
@hc_content = text
|
94
|
+
dispatch_request
|
95
|
+
end
|
96
|
+
|
97
|
+
def dispatch_request
|
98
|
+
if respond_to?(:receive_request)
|
99
|
+
receive_request @hc_headers, @hc_content
|
100
|
+
end
|
101
|
+
init_for_request
|
102
|
+
end
|
103
|
+
private :dispatch_request
|
104
|
+
|
105
|
+
def init_for_request
|
106
|
+
@hc_mode = :discard_blanks
|
107
|
+
@hc_headers = []
|
108
|
+
# originally was @hc_headers ||= []; @hc_headers.clear to get a performance
|
109
|
+
# boost, but it's counterproductive because a subclassed handler will have to
|
110
|
+
# call dup to use the header array we pass in receive_headers.
|
111
|
+
|
112
|
+
@hc_content_length = nil
|
113
|
+
@hc_content = ""
|
114
|
+
end
|
115
|
+
private :init_for_request
|
116
|
+
|
117
|
+
# Basically a convenience method. We might create a subclass that does this
|
118
|
+
# automatically. But it's such a performance killer.
|
119
|
+
def headers_2_hash hdrs
|
120
|
+
self.class.headers_2_hash hdrs
|
121
|
+
end
|
122
|
+
|
123
|
+
class << self
|
124
|
+
def headers_2_hash hdrs
|
125
|
+
hash = {}
|
126
|
+
hdrs.each {|h|
|
127
|
+
if /\A([^\s:]+)\s*:\s*/ =~ h
|
128
|
+
tail = $'.dup
|
129
|
+
hash[ $1.downcase.gsub(/-/,"_").intern ] = tail
|
130
|
+
end
|
131
|
+
}
|
132
|
+
hash
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|