eventmachine 0.12.10-x86-mswin32-60 → 1.0.0.beta.2-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/Gemfile +1 -0
- data/README +80 -81
- data/Rakefile +7 -370
- data/docs/COPYING +60 -60
- data/docs/ChangeLog +211 -211
- data/docs/DEFERRABLES +246 -133
- data/docs/EPOLL +141 -141
- data/docs/GNU +281 -281
- data/docs/INSTALL +13 -13
- data/docs/KEYBOARD +42 -38
- data/docs/LEGAL +25 -25
- data/docs/LIGHTWEIGHT_CONCURRENCY +130 -70
- data/docs/PURE_RUBY +75 -75
- data/docs/RELEASE_NOTES +94 -94
- data/docs/SMTP +4 -2
- data/docs/SPAWNED_PROCESSES +148 -89
- data/docs/TODO +8 -8
- data/eventmachine.gemspec +19 -26
- data/examples/ex_channel.rb +42 -42
- data/examples/ex_queue.rb +2 -2
- data/examples/ex_tick_loop_array.rb +15 -0
- data/examples/ex_tick_loop_counter.rb +32 -0
- data/examples/helper.rb +1 -1
- data/ext/binder.cpp +0 -1
- data/ext/cmain.cpp +36 -25
- data/ext/ed.cpp +104 -113
- data/ext/ed.h +24 -30
- data/ext/em.cpp +349 -283
- data/ext/em.h +25 -29
- data/ext/eventmachine.h +5 -4
- data/ext/extconf.rb +58 -49
- data/ext/fastfilereader/extconf.rb +5 -3
- data/ext/fastfilereader/mapper.cpp +214 -214
- data/ext/fastfilereader/mapper.h +59 -59
- data/ext/fastfilereader/rubymain.cpp +127 -127
- data/ext/kb.cpp +1 -3
- data/ext/page.cpp +107 -107
- data/ext/page.h +51 -51
- data/ext/pipe.cpp +9 -11
- data/ext/project.h +12 -8
- data/ext/rubymain.cpp +138 -104
- data/java/.classpath +8 -8
- data/java/.project +17 -17
- data/java/src/com/rubyeventmachine/EmReactor.java +1 -0
- data/java/src/com/rubyeventmachine/EmReactorException.java +40 -40
- data/lib/em/buftok.rb +138 -138
- data/lib/em/callback.rb +25 -25
- data/lib/em/channel.rb +1 -1
- data/lib/em/connection.rb +6 -1
- data/lib/em/deferrable.rb +16 -2
- data/lib/em/file_watch.rb +53 -53
- data/lib/em/future.rb +61 -61
- data/lib/em/iterator.rb +270 -0
- data/lib/em/messages.rb +66 -66
- data/lib/em/process_watch.rb +43 -43
- data/lib/em/protocols.rb +1 -1
- data/lib/em/protocols/header_and_content.rb +138 -138
- data/lib/em/protocols/httpclient.rb +267 -262
- data/lib/em/protocols/line_protocol.rb +28 -0
- data/lib/em/protocols/memcache.rb +322 -322
- data/lib/em/protocols/postgres3.rb +247 -247
- data/lib/em/protocols/saslauth.rb +175 -175
- data/lib/em/protocols/smtpserver.rb +640 -547
- data/lib/em/protocols/stomp.rb +200 -200
- data/lib/em/protocols/tcptest.rb +52 -52
- data/lib/{pr_eventmachine.rb → em/pure_ruby.rb} +1013 -1022
- data/lib/em/queue.rb +1 -0
- data/lib/em/spawnable.rb +85 -85
- data/lib/em/streamer.rb +130 -130
- data/lib/em/tick_loop.rb +85 -0
- data/lib/em/timers.rb +2 -1
- data/lib/em/version.rb +1 -1
- data/lib/eventmachine.rb +40 -84
- data/lib/jeventmachine.rb +2 -1
- data/lib/rubyeventmachine.rb +2 -0
- data/setup.rb +1585 -1585
- data/tasks/doc.rake +30 -0
- data/tasks/package.rake +85 -0
- data/tasks/test.rake +6 -0
- data/tests/client.crt +31 -31
- data/tests/client.key +51 -51
- data/tests/test_attach.rb +13 -3
- data/tests/test_basic.rb +60 -95
- data/tests/test_channel.rb +3 -2
- data/tests/test_defer.rb +49 -47
- data/tests/test_deferrable.rb +35 -0
- data/tests/test_error_handler.rb +35 -35
- data/tests/test_errors.rb +82 -82
- data/tests/test_exc.rb +55 -55
- data/tests/test_file_watch.rb +49 -49
- data/tests/test_futures.rb +198 -198
- data/tests/test_handler_check.rb +36 -36
- data/tests/test_hc.rb +190 -218
- data/tests/test_httpclient.rb +227 -218
- data/tests/test_httpclient2.rb +3 -2
- data/tests/test_inactivity_timeout.rb +3 -3
- data/tests/test_kb.rb +60 -60
- data/tests/test_ltp.rb +13 -5
- data/tests/test_ltp2.rb +317 -317
- data/tests/test_next_tick.rb +1 -1
- data/tests/test_object_protocol.rb +36 -36
- data/tests/test_pending_connect_timeout.rb +2 -2
- data/tests/test_process_watch.rb +50 -48
- data/tests/test_proxy_connection.rb +52 -0
- data/tests/test_pure.rb +134 -125
- data/tests/test_queue.rb +44 -44
- data/tests/test_running.rb +42 -42
- data/tests/test_sasl.rb +72 -72
- data/tests/test_send_file.rb +251 -242
- data/tests/test_servers.rb +76 -76
- data/tests/test_smtpclient.rb +83 -83
- data/tests/test_smtpserver.rb +85 -85
- data/tests/test_spawn.rb +322 -322
- data/tests/test_ssl_methods.rb +49 -49
- data/tests/test_ssl_verify.rb +82 -82
- data/tests/test_tick_loop.rb +59 -0
- data/tests/test_timers.rb +13 -15
- data/tests/test_ud.rb +36 -36
- data/tests/testem.rb +31 -31
- metadata +66 -51
- data/ext/cplusplus.cpp +0 -202
- data/ext/emwin.cpp +0 -300
- data/ext/emwin.h +0 -94
- data/ext/epoll.cpp +0 -26
- data/ext/epoll.h +0 -25
- data/ext/eventmachine_cpp.h +0 -96
- data/ext/files.cpp +0 -94
- data/ext/files.h +0 -65
- data/ext/sigs.cpp +0 -89
- data/ext/sigs.h +0 -32
- data/java/src/com/rubyeventmachine/application/Application.java +0 -194
- data/java/src/com/rubyeventmachine/application/Connection.java +0 -74
- data/java/src/com/rubyeventmachine/application/ConnectionFactory.java +0 -37
- data/java/src/com/rubyeventmachine/application/DefaultConnectionFactory.java +0 -46
- data/java/src/com/rubyeventmachine/application/PeriodicTimer.java +0 -38
- data/java/src/com/rubyeventmachine/application/Timer.java +0 -54
- data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +0 -109
- data/java/src/com/rubyeventmachine/tests/ConnectTest.java +0 -148
- data/java/src/com/rubyeventmachine/tests/EMTest.java +0 -80
- data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +0 -53
- data/java/src/com/rubyeventmachine/tests/TestServers.java +0 -75
- data/java/src/com/rubyeventmachine/tests/TestTimers.java +0 -90
- data/lib/evma.rb +0 -32
- data/lib/evma/callback.rb +0 -32
- data/lib/evma/container.rb +0 -75
- data/lib/evma/factory.rb +0 -77
- data/lib/evma/protocol.rb +0 -87
- data/lib/evma/reactor.rb +0 -48
- data/web/whatis +0 -7
data/java/.classpath
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<classpath>
|
3
|
-
<classpathentry kind="src" path="src"/>
|
4
|
-
<classpathentry excluding="src/" kind="src" path=""/>
|
5
|
-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
6
|
-
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
|
7
|
-
<classpathentry kind="output" path="src"/>
|
8
|
-
</classpath>
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<classpath>
|
3
|
+
<classpathentry kind="src" path="src"/>
|
4
|
+
<classpathentry excluding="src/" kind="src" path=""/>
|
5
|
+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
6
|
+
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
|
7
|
+
<classpathentry kind="output" path="src"/>
|
8
|
+
</classpath>
|
data/java/.project
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<projectDescription>
|
3
|
-
<name>em_reactor</name>
|
4
|
-
<comment></comment>
|
5
|
-
<projects>
|
6
|
-
</projects>
|
7
|
-
<buildSpec>
|
8
|
-
<buildCommand>
|
9
|
-
<name>org.eclipse.jdt.core.javabuilder</name>
|
10
|
-
<arguments>
|
11
|
-
</arguments>
|
12
|
-
</buildCommand>
|
13
|
-
</buildSpec>
|
14
|
-
<natures>
|
15
|
-
<nature>org.eclipse.jdt.core.javanature</nature>
|
16
|
-
</natures>
|
17
|
-
</projectDescription>
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<projectDescription>
|
3
|
+
<name>em_reactor</name>
|
4
|
+
<comment></comment>
|
5
|
+
<projects>
|
6
|
+
</projects>
|
7
|
+
<buildSpec>
|
8
|
+
<buildCommand>
|
9
|
+
<name>org.eclipse.jdt.core.javabuilder</name>
|
10
|
+
<arguments>
|
11
|
+
</arguments>
|
12
|
+
</buildCommand>
|
13
|
+
</buildSpec>
|
14
|
+
<natures>
|
15
|
+
<nature>org.eclipse.jdt.core.javanature</nature>
|
16
|
+
</natures>
|
17
|
+
</projectDescription>
|
@@ -48,6 +48,7 @@ public class EmReactor {
|
|
48
48
|
public final int EM_SSL_HANDSHAKE_COMPLETED = 108;
|
49
49
|
public final int EM_SSL_VERIFY = 109;
|
50
50
|
public final int EM_PROXY_TARGET_UNBOUND = 110;
|
51
|
+
public final int EM_PROXY_COMPLETED = 111;
|
51
52
|
|
52
53
|
private Selector mySelector;
|
53
54
|
private TreeMap<Long, ArrayList<Long>> Timers;
|
@@ -1,40 +1,40 @@
|
|
1
|
-
/**
|
2
|
-
* $Id$
|
3
|
-
*
|
4
|
-
* Author:: Francis Cianfrocca (gmail: blackhedd)
|
5
|
-
* Homepage:: http://rubyeventmachine.com
|
6
|
-
* Date:: 15 Jul 2007
|
7
|
-
*
|
8
|
-
* See EventMachine and EventMachine::Connection for documentation and
|
9
|
-
* usage examples.
|
10
|
-
*
|
11
|
-
*
|
12
|
-
*----------------------------------------------------------------------------
|
13
|
-
*
|
14
|
-
* Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
|
15
|
-
* Gmail: blackhedd
|
16
|
-
*
|
17
|
-
* This program is free software; you can redistribute it and/or modify
|
18
|
-
* it under the terms of either: 1) the GNU General Public License
|
19
|
-
* as published by the Free Software Foundation; either version 2 of the
|
20
|
-
* License, or (at your option) any later version; or 2) Ruby's License.
|
21
|
-
*
|
22
|
-
* See the file COPYING for complete licensing information.
|
23
|
-
*
|
24
|
-
*---------------------------------------------------------------------------
|
25
|
-
*
|
26
|
-
*
|
27
|
-
*/
|
28
|
-
|
29
|
-
package com.rubyeventmachine;
|
30
|
-
|
31
|
-
/**
|
32
|
-
* @author francis
|
33
|
-
*
|
34
|
-
*/
|
35
|
-
public class EmReactorException extends Exception {
|
36
|
-
static final long serialVersionUID = 0;
|
37
|
-
public EmReactorException (String msg) {
|
38
|
-
super (msg);
|
39
|
-
}
|
40
|
-
}
|
1
|
+
/**
|
2
|
+
* $Id$
|
3
|
+
*
|
4
|
+
* Author:: Francis Cianfrocca (gmail: blackhedd)
|
5
|
+
* Homepage:: http://rubyeventmachine.com
|
6
|
+
* Date:: 15 Jul 2007
|
7
|
+
*
|
8
|
+
* See EventMachine and EventMachine::Connection for documentation and
|
9
|
+
* usage examples.
|
10
|
+
*
|
11
|
+
*
|
12
|
+
*----------------------------------------------------------------------------
|
13
|
+
*
|
14
|
+
* Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
|
15
|
+
* Gmail: blackhedd
|
16
|
+
*
|
17
|
+
* This program is free software; you can redistribute it and/or modify
|
18
|
+
* it under the terms of either: 1) the GNU General Public License
|
19
|
+
* as published by the Free Software Foundation; either version 2 of the
|
20
|
+
* License, or (at your option) any later version; or 2) Ruby's License.
|
21
|
+
*
|
22
|
+
* See the file COPYING for complete licensing information.
|
23
|
+
*
|
24
|
+
*---------------------------------------------------------------------------
|
25
|
+
*
|
26
|
+
*
|
27
|
+
*/
|
28
|
+
|
29
|
+
package com.rubyeventmachine;
|
30
|
+
|
31
|
+
/**
|
32
|
+
* @author francis
|
33
|
+
*
|
34
|
+
*/
|
35
|
+
public class EmReactorException extends Exception {
|
36
|
+
static final long serialVersionUID = 0;
|
37
|
+
public EmReactorException (String msg) {
|
38
|
+
super (msg);
|
39
|
+
}
|
40
|
+
}
|
data/lib/em/buftok.rb
CHANGED
@@ -1,138 +1,138 @@
|
|
1
|
-
# BufferedTokenizer - Statefully split input data by a specifiable token
|
2
|
-
#
|
3
|
-
# Authors:: Tony Arcieri, Martin Emde
|
4
|
-
#
|
5
|
-
#----------------------------------------------------------------------------
|
6
|
-
#
|
7
|
-
# Copyright (C) 2006-07 by Tony Arcieri and Martin Emde
|
8
|
-
#
|
9
|
-
# Distributed under the Ruby license (http://www.ruby-lang.org/en/LICENSE.txt)
|
10
|
-
#
|
11
|
-
#---------------------------------------------------------------------------
|
12
|
-
#
|
13
|
-
|
14
|
-
# (C)2006 Tony Arcieri, Martin Emde
|
15
|
-
# Distributed under the Ruby license (http://www.ruby-lang.org/en/LICENSE.txt)
|
16
|
-
|
17
|
-
# BufferedTokenizer takes a delimiter upon instantiation, or acts line-based
|
18
|
-
# by default. It allows input to be spoon-fed from some outside source which
|
19
|
-
# receives arbitrary length datagrams which may-or-may-not contain the token
|
20
|
-
# by which entities are delimited.
|
21
|
-
#
|
22
|
-
# Commonly used to parse lines out of incoming data:
|
23
|
-
#
|
24
|
-
# module LineBufferedConnection
|
25
|
-
# def receive_data(data)
|
26
|
-
# (@buffer ||= BufferedTokenizer.new).extract(data).each do |line|
|
27
|
-
# receive_line(line)
|
28
|
-
# end
|
29
|
-
# end
|
30
|
-
# end
|
31
|
-
|
32
|
-
class BufferedTokenizer
|
33
|
-
# New BufferedTokenizers will operate on lines delimited by "\n" by default
|
34
|
-
# or allow you to specify any delimiter token you so choose, which will then
|
35
|
-
# be used by String#split to tokenize the input data
|
36
|
-
def initialize(delimiter = "\n", size_limit = nil)
|
37
|
-
# Store the specified delimiter
|
38
|
-
@delimiter = delimiter
|
39
|
-
|
40
|
-
# Store the specified size limitation
|
41
|
-
@size_limit = size_limit
|
42
|
-
|
43
|
-
# The input buffer is stored as an array. This is by far the most efficient
|
44
|
-
# approach given language constraints (in C a linked list would be a more
|
45
|
-
# appropriate data structure). Segments of input data are stored in a list
|
46
|
-
# which is only joined when a token is reached, substantially reducing the
|
47
|
-
# number of objects required for the operation.
|
48
|
-
@input = []
|
49
|
-
|
50
|
-
# Size of the input buffer
|
51
|
-
@input_size = 0
|
52
|
-
end
|
53
|
-
|
54
|
-
# Extract takes an arbitrary string of input data and returns an array of
|
55
|
-
# tokenized entities, provided there were any available to extract. This
|
56
|
-
# makes for easy processing of datagrams using a pattern like:
|
57
|
-
#
|
58
|
-
# tokenizer.extract(data).map { |entity| Decode(entity) }.each do ...
|
59
|
-
def extract(data)
|
60
|
-
# Extract token-delimited entities from the input string with the split command.
|
61
|
-
# There's a bit of craftiness here with the -1 parameter. Normally split would
|
62
|
-
# behave no differently regardless of if the token lies at the very end of the
|
63
|
-
# input buffer or not (i.e. a literal edge case) Specifying -1 forces split to
|
64
|
-
# return "" in this case, meaning that the last entry in the list represents a
|
65
|
-
# new segment of data where the token has not been encountered
|
66
|
-
entities = data.split @delimiter, -1
|
67
|
-
|
68
|
-
# Check to see if the buffer has exceeded capacity, if we're imposing a limit
|
69
|
-
if @size_limit
|
70
|
-
raise 'input buffer full' if @input_size + entities.first.size > @size_limit
|
71
|
-
@input_size += entities.first.size
|
72
|
-
end
|
73
|
-
|
74
|
-
# Move the first entry in the resulting array into the input buffer. It represents
|
75
|
-
# the last segment of a token-delimited entity unless it's the only entry in the list.
|
76
|
-
@input << entities.shift
|
77
|
-
|
78
|
-
# If the resulting array from the split is empty, the token was not encountered
|
79
|
-
# (not even at the end of the buffer). Since we've encountered no token-delimited
|
80
|
-
# entities this go-around, return an empty array.
|
81
|
-
return [] if entities.empty?
|
82
|
-
|
83
|
-
# At this point, we've hit a token, or potentially multiple tokens. Now we can bring
|
84
|
-
# together all the data we've buffered from earlier calls without hitting a token,
|
85
|
-
# and add it to our list of discovered entities.
|
86
|
-
entities.unshift @input.join
|
87
|
-
|
88
|
-
=begin
|
89
|
-
# Note added by FC, 10Jul07. This paragraph contains a regression. It breaks
|
90
|
-
# empty tokens. Think of the empty line that delimits an HTTP header. It will have
|
91
|
-
# two "\n" delimiters in a row, and this code mishandles the resulting empty token.
|
92
|
-
# It someone figures out how to fix the problem, we can re-enable this code branch.
|
93
|
-
# Multi-character token support.
|
94
|
-
# Split any tokens that were incomplete on the last iteration buf complete now.
|
95
|
-
entities.map! do |e|
|
96
|
-
e.split @delimiter, -1
|
97
|
-
end
|
98
|
-
# Flatten the resulting array. This has the side effect of removing the empty
|
99
|
-
# entry at the end that was produced by passing -1 to split. Add it again if
|
100
|
-
# necessary.
|
101
|
-
if (entities[-1] == [])
|
102
|
-
entities.flatten! << []
|
103
|
-
else
|
104
|
-
entities.flatten!
|
105
|
-
end
|
106
|
-
=end
|
107
|
-
|
108
|
-
# Now that we've hit a token, joined the input buffer and added it to the entities
|
109
|
-
# list, we can go ahead and clear the input buffer. All of the segments that were
|
110
|
-
# stored before the join can now be garbage collected.
|
111
|
-
@input.clear
|
112
|
-
|
113
|
-
# The last entity in the list is not token delimited, however, thanks to the -1
|
114
|
-
# passed to split. It represents the beginning of a new list of as-yet-untokenized
|
115
|
-
# data, so we add it to the start of the list.
|
116
|
-
@input << entities.pop
|
117
|
-
|
118
|
-
# Set the new input buffer size, provided we're keeping track
|
119
|
-
@input_size = @input.first.size if @size_limit
|
120
|
-
|
121
|
-
# Now we're left with the list of extracted token-delimited entities we wanted
|
122
|
-
# in the first place. Hooray!
|
123
|
-
entities
|
124
|
-
end
|
125
|
-
|
126
|
-
# Flush the contents of the input buffer, i.e. return the input buffer even though
|
127
|
-
# a token has not yet been encountered
|
128
|
-
def flush
|
129
|
-
buffer = @input.join
|
130
|
-
@input.clear
|
131
|
-
buffer
|
132
|
-
end
|
133
|
-
|
134
|
-
# Is the buffer empty?
|
135
|
-
def empty?
|
136
|
-
@input.empty?
|
137
|
-
end
|
138
|
-
end
|
1
|
+
# BufferedTokenizer - Statefully split input data by a specifiable token
|
2
|
+
#
|
3
|
+
# Authors:: Tony Arcieri, Martin Emde
|
4
|
+
#
|
5
|
+
#----------------------------------------------------------------------------
|
6
|
+
#
|
7
|
+
# Copyright (C) 2006-07 by Tony Arcieri and Martin Emde
|
8
|
+
#
|
9
|
+
# Distributed under the Ruby license (http://www.ruby-lang.org/en/LICENSE.txt)
|
10
|
+
#
|
11
|
+
#---------------------------------------------------------------------------
|
12
|
+
#
|
13
|
+
|
14
|
+
# (C)2006 Tony Arcieri, Martin Emde
|
15
|
+
# Distributed under the Ruby license (http://www.ruby-lang.org/en/LICENSE.txt)
|
16
|
+
|
17
|
+
# BufferedTokenizer takes a delimiter upon instantiation, or acts line-based
|
18
|
+
# by default. It allows input to be spoon-fed from some outside source which
|
19
|
+
# receives arbitrary length datagrams which may-or-may-not contain the token
|
20
|
+
# by which entities are delimited.
|
21
|
+
#
|
22
|
+
# Commonly used to parse lines out of incoming data:
|
23
|
+
#
|
24
|
+
# module LineBufferedConnection
|
25
|
+
# def receive_data(data)
|
26
|
+
# (@buffer ||= BufferedTokenizer.new).extract(data).each do |line|
|
27
|
+
# receive_line(line)
|
28
|
+
# end
|
29
|
+
# end
|
30
|
+
# end
|
31
|
+
|
32
|
+
class BufferedTokenizer
|
33
|
+
# New BufferedTokenizers will operate on lines delimited by "\n" by default
|
34
|
+
# or allow you to specify any delimiter token you so choose, which will then
|
35
|
+
# be used by String#split to tokenize the input data
|
36
|
+
def initialize(delimiter = "\n", size_limit = nil)
|
37
|
+
# Store the specified delimiter
|
38
|
+
@delimiter = delimiter
|
39
|
+
|
40
|
+
# Store the specified size limitation
|
41
|
+
@size_limit = size_limit
|
42
|
+
|
43
|
+
# The input buffer is stored as an array. This is by far the most efficient
|
44
|
+
# approach given language constraints (in C a linked list would be a more
|
45
|
+
# appropriate data structure). Segments of input data are stored in a list
|
46
|
+
# which is only joined when a token is reached, substantially reducing the
|
47
|
+
# number of objects required for the operation.
|
48
|
+
@input = []
|
49
|
+
|
50
|
+
# Size of the input buffer
|
51
|
+
@input_size = 0
|
52
|
+
end
|
53
|
+
|
54
|
+
# Extract takes an arbitrary string of input data and returns an array of
|
55
|
+
# tokenized entities, provided there were any available to extract. This
|
56
|
+
# makes for easy processing of datagrams using a pattern like:
|
57
|
+
#
|
58
|
+
# tokenizer.extract(data).map { |entity| Decode(entity) }.each do ...
|
59
|
+
def extract(data)
|
60
|
+
# Extract token-delimited entities from the input string with the split command.
|
61
|
+
# There's a bit of craftiness here with the -1 parameter. Normally split would
|
62
|
+
# behave no differently regardless of if the token lies at the very end of the
|
63
|
+
# input buffer or not (i.e. a literal edge case) Specifying -1 forces split to
|
64
|
+
# return "" in this case, meaning that the last entry in the list represents a
|
65
|
+
# new segment of data where the token has not been encountered
|
66
|
+
entities = data.split @delimiter, -1
|
67
|
+
|
68
|
+
# Check to see if the buffer has exceeded capacity, if we're imposing a limit
|
69
|
+
if @size_limit
|
70
|
+
raise 'input buffer full' if @input_size + entities.first.size > @size_limit
|
71
|
+
@input_size += entities.first.size
|
72
|
+
end
|
73
|
+
|
74
|
+
# Move the first entry in the resulting array into the input buffer. It represents
|
75
|
+
# the last segment of a token-delimited entity unless it's the only entry in the list.
|
76
|
+
@input << entities.shift
|
77
|
+
|
78
|
+
# If the resulting array from the split is empty, the token was not encountered
|
79
|
+
# (not even at the end of the buffer). Since we've encountered no token-delimited
|
80
|
+
# entities this go-around, return an empty array.
|
81
|
+
return [] if entities.empty?
|
82
|
+
|
83
|
+
# At this point, we've hit a token, or potentially multiple tokens. Now we can bring
|
84
|
+
# together all the data we've buffered from earlier calls without hitting a token,
|
85
|
+
# and add it to our list of discovered entities.
|
86
|
+
entities.unshift @input.join
|
87
|
+
|
88
|
+
=begin
|
89
|
+
# Note added by FC, 10Jul07. This paragraph contains a regression. It breaks
|
90
|
+
# empty tokens. Think of the empty line that delimits an HTTP header. It will have
|
91
|
+
# two "\n" delimiters in a row, and this code mishandles the resulting empty token.
|
92
|
+
# It someone figures out how to fix the problem, we can re-enable this code branch.
|
93
|
+
# Multi-character token support.
|
94
|
+
# Split any tokens that were incomplete on the last iteration buf complete now.
|
95
|
+
entities.map! do |e|
|
96
|
+
e.split @delimiter, -1
|
97
|
+
end
|
98
|
+
# Flatten the resulting array. This has the side effect of removing the empty
|
99
|
+
# entry at the end that was produced by passing -1 to split. Add it again if
|
100
|
+
# necessary.
|
101
|
+
if (entities[-1] == [])
|
102
|
+
entities.flatten! << []
|
103
|
+
else
|
104
|
+
entities.flatten!
|
105
|
+
end
|
106
|
+
=end
|
107
|
+
|
108
|
+
# Now that we've hit a token, joined the input buffer and added it to the entities
|
109
|
+
# list, we can go ahead and clear the input buffer. All of the segments that were
|
110
|
+
# stored before the join can now be garbage collected.
|
111
|
+
@input.clear
|
112
|
+
|
113
|
+
# The last entity in the list is not token delimited, however, thanks to the -1
|
114
|
+
# passed to split. It represents the beginning of a new list of as-yet-untokenized
|
115
|
+
# data, so we add it to the start of the list.
|
116
|
+
@input << entities.pop
|
117
|
+
|
118
|
+
# Set the new input buffer size, provided we're keeping track
|
119
|
+
@input_size = @input.first.size if @size_limit
|
120
|
+
|
121
|
+
# Now we're left with the list of extracted token-delimited entities we wanted
|
122
|
+
# in the first place. Hooray!
|
123
|
+
entities
|
124
|
+
end
|
125
|
+
|
126
|
+
# Flush the contents of the input buffer, i.e. return the input buffer even though
|
127
|
+
# a token has not yet been encountered
|
128
|
+
def flush
|
129
|
+
buffer = @input.join
|
130
|
+
@input.clear
|
131
|
+
buffer
|
132
|
+
end
|
133
|
+
|
134
|
+
# Is the buffer empty?
|
135
|
+
def empty?
|
136
|
+
@input.empty?
|
137
|
+
end
|
138
|
+
end
|
data/lib/em/callback.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
|
-
module EventMachine
|
2
|
-
# Utility method for coercing arguments to an object that responds to #call
|
3
|
-
# Accepts an object and a method name to send to, or a block, or an object
|
4
|
-
# that responds to call.
|
5
|
-
#
|
6
|
-
# cb = EM.Callback{ |msg| puts(msg) }
|
7
|
-
# cb.call('hello world')
|
8
|
-
#
|
9
|
-
# cb = EM.Callback(Object, :puts)
|
10
|
-
# cb.call('hello world')
|
11
|
-
#
|
12
|
-
# cb = EM.Callback(proc{ |msg| puts(msg) })
|
13
|
-
# cb.call('hello world')
|
14
|
-
#
|
15
|
-
def self.Callback(object = nil, method = nil, &blk)
|
16
|
-
if object && method
|
17
|
-
lambda { |*args| object.send method, *args }
|
18
|
-
else
|
19
|
-
if object.respond_to? :call
|
20
|
-
object
|
21
|
-
else
|
22
|
-
blk || raise(ArgumentError)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
1
|
+
module EventMachine
|
2
|
+
# Utility method for coercing arguments to an object that responds to #call
|
3
|
+
# Accepts an object and a method name to send to, or a block, or an object
|
4
|
+
# that responds to call.
|
5
|
+
#
|
6
|
+
# cb = EM.Callback{ |msg| puts(msg) }
|
7
|
+
# cb.call('hello world')
|
8
|
+
#
|
9
|
+
# cb = EM.Callback(Object, :puts)
|
10
|
+
# cb.call('hello world')
|
11
|
+
#
|
12
|
+
# cb = EM.Callback(proc{ |msg| puts(msg) })
|
13
|
+
# cb.call('hello world')
|
14
|
+
#
|
15
|
+
def self.Callback(object = nil, method = nil, &blk)
|
16
|
+
if object && method
|
17
|
+
lambda { |*args| object.send method, *args }
|
18
|
+
else
|
19
|
+
if object.respond_to? :call
|
20
|
+
object
|
21
|
+
else
|
22
|
+
blk || raise(ArgumentError)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
26
|
end
|