libc-eventmachine 0.12.5.42
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/Rakefile +195 -0
- data/docs/COPYING +60 -0
- data/docs/ChangeLog +211 -0
- data/docs/DEFERRABLES +138 -0
- data/docs/EPOLL +141 -0
- data/docs/GNU +281 -0
- data/docs/INSTALL +15 -0
- data/docs/KEYBOARD +38 -0
- data/docs/LEGAL +25 -0
- data/docs/LIGHTWEIGHT_CONCURRENCY +72 -0
- data/docs/PURE_RUBY +77 -0
- data/docs/README +74 -0
- data/docs/RELEASE_NOTES +96 -0
- data/docs/SMTP +9 -0
- data/docs/SPAWNED_PROCESSES +93 -0
- data/docs/TODO +10 -0
- data/ext/binder.cpp +126 -0
- data/ext/binder.h +48 -0
- data/ext/cmain.cpp +582 -0
- data/ext/cplusplus.cpp +177 -0
- data/ext/ed.cpp +1522 -0
- data/ext/ed.h +380 -0
- data/ext/em.cpp +1947 -0
- data/ext/em.h +186 -0
- data/ext/emwin.cpp +300 -0
- data/ext/emwin.h +94 -0
- data/ext/epoll.cpp +26 -0
- data/ext/epoll.h +25 -0
- data/ext/eventmachine.h +98 -0
- data/ext/eventmachine_cpp.h +96 -0
- data/ext/extconf.rb +129 -0
- data/ext/fastfilereader/extconf.rb +77 -0
- data/ext/fastfilereader/mapper.cpp +214 -0
- data/ext/fastfilereader/mapper.h +59 -0
- data/ext/fastfilereader/rubymain.cpp +127 -0
- data/ext/files.cpp +94 -0
- data/ext/files.h +65 -0
- data/ext/kb.cpp +82 -0
- data/ext/page.cpp +107 -0
- data/ext/page.h +51 -0
- data/ext/pipe.cpp +351 -0
- data/ext/project.h +119 -0
- data/ext/rubymain.cpp +858 -0
- data/ext/sigs.cpp +89 -0
- data/ext/sigs.h +32 -0
- data/ext/ssl.cpp +423 -0
- data/ext/ssl.h +90 -0
- data/java/src/com/rubyeventmachine/Application.java +196 -0
- data/java/src/com/rubyeventmachine/Connection.java +74 -0
- data/java/src/com/rubyeventmachine/ConnectionFactory.java +37 -0
- data/java/src/com/rubyeventmachine/DefaultConnectionFactory.java +46 -0
- data/java/src/com/rubyeventmachine/EmReactor.java +408 -0
- data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
- data/java/src/com/rubyeventmachine/EventableChannel.java +57 -0
- data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +171 -0
- data/java/src/com/rubyeventmachine/EventableSocketChannel.java +244 -0
- data/java/src/com/rubyeventmachine/PeriodicTimer.java +38 -0
- data/java/src/com/rubyeventmachine/Timer.java +54 -0
- data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +108 -0
- data/java/src/com/rubyeventmachine/tests/ConnectTest.java +124 -0
- data/java/src/com/rubyeventmachine/tests/EMTest.java +80 -0
- data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +53 -0
- data/java/src/com/rubyeventmachine/tests/TestServers.java +74 -0
- data/java/src/com/rubyeventmachine/tests/TestTimers.java +89 -0
- data/lib/em/deferrable.rb +208 -0
- data/lib/em/eventable.rb +39 -0
- data/lib/em/future.rb +62 -0
- data/lib/em/messages.rb +66 -0
- data/lib/em/processes.rb +68 -0
- data/lib/em/spawnable.rb +88 -0
- data/lib/em/streamer.rb +112 -0
- data/lib/eventmachine.rb +1920 -0
- data/lib/eventmachine_version.rb +31 -0
- data/lib/evma/callback.rb +32 -0
- data/lib/evma/container.rb +75 -0
- data/lib/evma/factory.rb +77 -0
- data/lib/evma/protocol.rb +87 -0
- data/lib/evma/reactor.rb +48 -0
- data/lib/evma.rb +32 -0
- data/lib/jeventmachine.rb +140 -0
- data/lib/pr_eventmachine.rb +1017 -0
- data/lib/protocols/buftok.rb +127 -0
- data/lib/protocols/header_and_content.rb +129 -0
- data/lib/protocols/httpcli2.rb +803 -0
- data/lib/protocols/httpclient.rb +270 -0
- data/lib/protocols/line_and_text.rb +126 -0
- data/lib/protocols/linetext2.rb +161 -0
- data/lib/protocols/memcache.rb +293 -0
- data/lib/protocols/postgres.rb +261 -0
- data/lib/protocols/saslauth.rb +179 -0
- data/lib/protocols/smtpclient.rb +308 -0
- data/lib/protocols/smtpserver.rb +556 -0
- data/lib/protocols/stomp.rb +153 -0
- data/lib/protocols/tcptest.rb +57 -0
- data/tasks/cpp.rake +77 -0
- data/tasks/project.rake +78 -0
- data/tasks/tests.rake +193 -0
- data/tests/test_attach.rb +83 -0
- data/tests/test_basic.rb +231 -0
- data/tests/test_bind.rb +73 -0
- data/tests/test_connection_count.rb +35 -0
- data/tests/test_defer.rb +47 -0
- data/tests/test_epoll.rb +163 -0
- data/tests/test_error_handler.rb +32 -0
- data/tests/test_errors.rb +82 -0
- data/tests/test_eventables.rb +77 -0
- data/tests/test_exc.rb +58 -0
- data/tests/test_futures.rb +214 -0
- data/tests/test_handler_check.rb +37 -0
- data/tests/test_hc.rb +218 -0
- data/tests/test_httpclient.rb +215 -0
- data/tests/test_httpclient2.rb +155 -0
- data/tests/test_kb.rb +61 -0
- data/tests/test_ltp.rb +188 -0
- data/tests/test_ltp2.rb +320 -0
- data/tests/test_next_tick.rb +109 -0
- data/tests/test_processes.rb +56 -0
- data/tests/test_pure.rb +129 -0
- data/tests/test_running.rb +47 -0
- data/tests/test_sasl.rb +74 -0
- data/tests/test_send_file.rb +243 -0
- data/tests/test_servers.rb +80 -0
- data/tests/test_smtpclient.rb +83 -0
- data/tests/test_smtpserver.rb +93 -0
- data/tests/test_spawn.rb +329 -0
- data/tests/test_ssl_args.rb +68 -0
- data/tests/test_ssl_methods.rb +50 -0
- data/tests/test_timers.rb +148 -0
- data/tests/test_ud.rb +43 -0
- data/tests/testem.rb +31 -0
- metadata +230 -0
|
@@ -0,0 +1,127 @@
|
|
|
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
|
+
class BufferedTokenizer
|
|
23
|
+
# New BufferedTokenizers will operate on lines delimited by "\n" by default
|
|
24
|
+
# or allow you to specify any delimiter token you so choose, which will then
|
|
25
|
+
# be used by String#split to tokenize the input data
|
|
26
|
+
def initialize(delimiter = "\n", size_limit = nil)
|
|
27
|
+
# Store the specified delimiter
|
|
28
|
+
@delimiter = delimiter
|
|
29
|
+
|
|
30
|
+
# Store the specified size limitation
|
|
31
|
+
@size_limit = size_limit
|
|
32
|
+
|
|
33
|
+
# The input buffer is stored as an array. This is by far the most efficient
|
|
34
|
+
# approach given language constraints (in C a linked list would be a more
|
|
35
|
+
# appropriate data structure). Segments of input data are stored in a list
|
|
36
|
+
# which is only joined when a token is reached, substantially reducing the
|
|
37
|
+
# number of objects required for the operation.
|
|
38
|
+
@input = []
|
|
39
|
+
|
|
40
|
+
# Size of the input buffer
|
|
41
|
+
@input_size = 0
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Extract takes an arbitrary string of input data and returns an array of
|
|
45
|
+
# tokenized entities, provided there were any available to extract. This
|
|
46
|
+
# makes for easy processing of datagrams using a pattern like:
|
|
47
|
+
#
|
|
48
|
+
# tokenizer.extract(data).map { |entity| Decode(entity) }.each do ...
|
|
49
|
+
def extract(data)
|
|
50
|
+
# Extract token-delimited entities from the input string with the split command.
|
|
51
|
+
# There's a bit of craftiness here with the -1 parameter. Normally split would
|
|
52
|
+
# behave no differently regardless of if the token lies at the very end of the
|
|
53
|
+
# input buffer or not (i.e. a literal edge case) Specifying -1 forces split to
|
|
54
|
+
# return "" in this case, meaning that the last entry in the list represents a
|
|
55
|
+
# new segment of data where the token has not been encountered
|
|
56
|
+
entities = data.split @delimiter, -1
|
|
57
|
+
|
|
58
|
+
# Check to see if the buffer has exceeded capacity, if we're imposing a limit
|
|
59
|
+
if @size_limit
|
|
60
|
+
raise 'input buffer full' if @input_size + entities.first.size > @size_limit
|
|
61
|
+
@input_size += entities.first.size
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Move the first entry in the resulting array into the input buffer. It represents
|
|
65
|
+
# the last segment of a token-delimited entity unless it's the only entry in the list.
|
|
66
|
+
@input << entities.shift
|
|
67
|
+
|
|
68
|
+
# If the resulting array from the split is empty, the token was not encountered
|
|
69
|
+
# (not even at the end of the buffer). Since we've encountered no token-delimited
|
|
70
|
+
# entities this go-around, return an empty array.
|
|
71
|
+
return [] if entities.empty?
|
|
72
|
+
|
|
73
|
+
# At this point, we've hit a token, or potentially multiple tokens. Now we can bring
|
|
74
|
+
# together all the data we've buffered from earlier calls without hitting a token,
|
|
75
|
+
# and add it to our list of discovered entities.
|
|
76
|
+
entities.unshift @input.join
|
|
77
|
+
|
|
78
|
+
=begin
|
|
79
|
+
# Note added by FC, 10Jul07. This paragraph contains a regression. It breaks
|
|
80
|
+
# empty tokens. Think of the empty line that delimits an HTTP header. It will have
|
|
81
|
+
# two "\n" delimiters in a row, and this code mishandles the resulting empty token.
|
|
82
|
+
# It someone figures out how to fix the problem, we can re-enable this code branch.
|
|
83
|
+
# Multi-character token support.
|
|
84
|
+
# Split any tokens that were incomplete on the last iteration buf complete now.
|
|
85
|
+
entities.map! do |e|
|
|
86
|
+
e.split @delimiter, -1
|
|
87
|
+
end
|
|
88
|
+
# Flatten the resulting array. This has the side effect of removing the empty
|
|
89
|
+
# entry at the end that was produced by passing -1 to split. Add it again if
|
|
90
|
+
# necessary.
|
|
91
|
+
if (entities[-1] == [])
|
|
92
|
+
entities.flatten! << []
|
|
93
|
+
else
|
|
94
|
+
entities.flatten!
|
|
95
|
+
end
|
|
96
|
+
=end
|
|
97
|
+
|
|
98
|
+
# Now that we've hit a token, joined the input buffer and added it to the entities
|
|
99
|
+
# list, we can go ahead and clear the input buffer. All of the segments that were
|
|
100
|
+
# stored before the join can now be garbage collected.
|
|
101
|
+
@input.clear
|
|
102
|
+
|
|
103
|
+
# The last entity in the list is not token delimited, however, thanks to the -1
|
|
104
|
+
# passed to split. It represents the beginning of a new list of as-yet-untokenized
|
|
105
|
+
# data, so we add it to the start of the list.
|
|
106
|
+
@input << entities.pop
|
|
107
|
+
|
|
108
|
+
# Set the new input buffer size, provided we're keeping track
|
|
109
|
+
@input_size = @input.first.size if @size_limit
|
|
110
|
+
|
|
111
|
+
# Now we're left with the list of extracted token-delimited entities we wanted
|
|
112
|
+
# in the first place. Hooray!
|
|
113
|
+
entities
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# Flush the contents of the input buffer, i.e. return the input buffer even though
|
|
117
|
+
# a token has not yet been encountered
|
|
118
|
+
def flush
|
|
119
|
+
buffer = @input.join
|
|
120
|
+
@input.clear
|
|
121
|
+
buffer
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def empty?
|
|
125
|
+
@input.empty?
|
|
126
|
+
end
|
|
127
|
+
end
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# $Id$
|
|
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
|
+
|
|
27
|
+
|
|
28
|
+
module EventMachine
|
|
29
|
+
module Protocols
|
|
30
|
+
|
|
31
|
+
# Originally, this subclassed LineAndTextProtocol, which in
|
|
32
|
+
# turn relies on BufferedTokenizer, which doesn't gracefully
|
|
33
|
+
# handle the transitions between lines and binary text.
|
|
34
|
+
# Changed 13Sep08 by FCianfrocca.
|
|
35
|
+
class HeaderAndContentProtocol < Connection
|
|
36
|
+
include LineText2
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
ContentLengthPattern = /Content-length:\s*(\d+)/i
|
|
40
|
+
|
|
41
|
+
def initialize *args
|
|
42
|
+
super
|
|
43
|
+
init_for_request
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def receive_line line
|
|
47
|
+
case @hc_mode
|
|
48
|
+
when :discard_blanks
|
|
49
|
+
unless line == ""
|
|
50
|
+
@hc_mode = :headers
|
|
51
|
+
receive_line line
|
|
52
|
+
end
|
|
53
|
+
when :headers
|
|
54
|
+
if line == ""
|
|
55
|
+
raise "unrecognized state" unless @hc_headers.length > 0
|
|
56
|
+
if respond_to?(:receive_headers)
|
|
57
|
+
receive_headers @hc_headers
|
|
58
|
+
end
|
|
59
|
+
# @hc_content_length will be nil, not 0, if there was no content-length header.
|
|
60
|
+
if @hc_content_length.to_i > 0
|
|
61
|
+
set_binary_mode @hc_content_length
|
|
62
|
+
else
|
|
63
|
+
dispatch_request
|
|
64
|
+
end
|
|
65
|
+
else
|
|
66
|
+
@hc_headers << line
|
|
67
|
+
if ContentLengthPattern =~ line
|
|
68
|
+
# There are some attacks that rely on sending multiple content-length
|
|
69
|
+
# headers. This is a crude protection, but needs to become tunable.
|
|
70
|
+
raise "extraneous content-length header" if @hc_content_length
|
|
71
|
+
@hc_content_length = $1.to_i
|
|
72
|
+
end
|
|
73
|
+
if @hc_headers.length == 1 and respond_to?(:receive_first_header_line)
|
|
74
|
+
receive_first_header_line line
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
else
|
|
78
|
+
raise "internal error, unsupported mode"
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def receive_binary_data text
|
|
83
|
+
@hc_content = text
|
|
84
|
+
dispatch_request
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def dispatch_request
|
|
88
|
+
if respond_to?(:receive_request)
|
|
89
|
+
receive_request @hc_headers, @hc_content
|
|
90
|
+
end
|
|
91
|
+
init_for_request
|
|
92
|
+
end
|
|
93
|
+
private :dispatch_request
|
|
94
|
+
|
|
95
|
+
def init_for_request
|
|
96
|
+
@hc_mode = :discard_blanks
|
|
97
|
+
@hc_headers = []
|
|
98
|
+
# originally was @hc_headers ||= []; @hc_headers.clear to get a performance
|
|
99
|
+
# boost, but it's counterproductive because a subclassed handler will have to
|
|
100
|
+
# call dup to use the header array we pass in receive_headers.
|
|
101
|
+
|
|
102
|
+
@hc_content_length = nil
|
|
103
|
+
@hc_content = ""
|
|
104
|
+
end
|
|
105
|
+
private :init_for_request
|
|
106
|
+
|
|
107
|
+
# Basically a convenience method. We might create a subclass that does this
|
|
108
|
+
# automatically. But it's such a performance killer.
|
|
109
|
+
def headers_2_hash hdrs
|
|
110
|
+
self.class.headers_2_hash hdrs
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
class << self
|
|
114
|
+
def headers_2_hash hdrs
|
|
115
|
+
hash = {}
|
|
116
|
+
hdrs.each {|h|
|
|
117
|
+
if /\A([^\s:]+)\s*:\s*/ =~ h
|
|
118
|
+
tail = $'.dup
|
|
119
|
+
hash[ $1.downcase.gsub(/-/,"_").intern ] = tail
|
|
120
|
+
end
|
|
121
|
+
}
|
|
122
|
+
hash
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|