eventmachine 0.12.8-x86-mswin32-60 → 0.12.10-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +14 -13
- data/Rakefile +374 -264
- data/eventmachine.gemspec +4 -5
- data/ext/binder.cpp +125 -126
- data/ext/binder.h +46 -48
- data/ext/cmain.cpp +184 -42
- data/ext/cplusplus.cpp +202 -202
- data/ext/ed.cpp +242 -81
- data/ext/ed.h +39 -22
- data/ext/em.cpp +127 -108
- data/ext/em.h +27 -18
- data/ext/emwin.cpp +3 -3
- data/ext/eventmachine.h +49 -38
- data/ext/eventmachine_cpp.h +96 -96
- data/ext/extconf.rb +147 -132
- data/ext/fastfilereader/extconf.rb +82 -76
- data/ext/project.h +151 -140
- data/ext/rubymain.cpp +222 -103
- data/ext/ssl.cpp +460 -460
- data/ext/ssl.h +94 -94
- data/java/src/com/rubyeventmachine/EmReactor.java +570 -423
- data/java/src/com/rubyeventmachine/EventableChannel.java +69 -57
- data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +189 -171
- data/java/src/com/rubyeventmachine/EventableSocketChannel.java +364 -244
- data/java/src/com/rubyeventmachine/{Application.java → application/Application.java} +194 -200
- data/java/src/com/rubyeventmachine/{Connection.java → application/Connection.java} +74 -74
- data/java/src/com/rubyeventmachine/{ConnectionFactory.java → application/ConnectionFactory.java} +36 -36
- data/java/src/com/rubyeventmachine/{DefaultConnectionFactory.java → application/DefaultConnectionFactory.java} +46 -46
- data/java/src/com/rubyeventmachine/{PeriodicTimer.java → application/PeriodicTimer.java} +38 -38
- data/java/src/com/rubyeventmachine/{Timer.java → application/Timer.java} +54 -54
- data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +109 -108
- data/java/src/com/rubyeventmachine/tests/ConnectTest.java +148 -146
- data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +53 -53
- data/java/src/com/rubyeventmachine/tests/TestServers.java +75 -74
- data/java/src/com/rubyeventmachine/tests/TestTimers.java +90 -89
- data/lib/em/connection.rb +71 -12
- data/lib/em/deferrable.rb +191 -186
- data/lib/em/protocols.rb +36 -35
- data/lib/em/protocols/httpclient2.rb +590 -582
- data/lib/em/protocols/line_and_text.rb +125 -126
- data/lib/em/protocols/linetext2.rb +161 -160
- data/lib/em/protocols/object_protocol.rb +45 -39
- data/lib/em/protocols/smtpclient.rb +357 -331
- data/lib/em/protocols/socks4.rb +66 -0
- data/lib/em/queue.rb +60 -60
- data/lib/em/timers.rb +56 -55
- data/lib/em/version.rb +1 -1
- data/lib/eventmachine.rb +125 -169
- data/lib/jeventmachine.rb +257 -142
- data/tasks/{cpp.rake → cpp.rake_example} +76 -76
- data/tests/test_attach.rb +125 -100
- data/tests/test_basic.rb +1 -2
- data/tests/test_connection_count.rb +34 -44
- data/tests/test_epoll.rb +0 -2
- data/tests/test_get_sock_opt.rb +30 -0
- data/tests/test_httpclient2.rb +3 -3
- data/tests/test_inactivity_timeout.rb +21 -1
- data/tests/test_ltp.rb +182 -188
- data/tests/test_next_tick.rb +0 -2
- data/tests/test_pause.rb +70 -0
- data/tests/test_pending_connect_timeout.rb +48 -0
- data/tests/test_ssl_args.rb +78 -67
- data/tests/test_timers.rb +162 -141
- metadata +13 -11
- data/tasks/project.rake +0 -79
- data/tasks/tests.rake +0 -193
@@ -1,126 +1,125 @@
|
|
1
|
-
#--
|
2
|
-
#
|
3
|
-
# Author:: Francis Cianfrocca (gmail: blackhedd)
|
4
|
-
# Homepage:: http://rubyeventmachine.com
|
5
|
-
# Date:: 15 November 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
|
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
|
-
@lbp_binary_bytes_received
|
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
|
-
@lbp_binary_limit
|
103
|
-
|
104
|
-
|
105
|
-
@
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
@
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
@
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
end
|
1
|
+
#--
|
2
|
+
#
|
3
|
+
# Author:: Francis Cianfrocca (gmail: blackhedd)
|
4
|
+
# Homepage:: http://rubyeventmachine.com
|
5
|
+
# Date:: 15 November 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
|
+
module EventMachine
|
28
|
+
module Protocols
|
29
|
+
# A protocol that handles line-oriented data with interspersed binary text.
|
30
|
+
#
|
31
|
+
# This version is optimized for performance. See EventMachine::Protocols::LineText2
|
32
|
+
# for a version which is optimized for correctness with regard to binary text blocks
|
33
|
+
# that can switch back to line mode.
|
34
|
+
class LineAndTextProtocol < Connection
|
35
|
+
MaxLineLength = 16*1024
|
36
|
+
MaxBinaryLength = 32*1024*1024
|
37
|
+
|
38
|
+
def initialize *args
|
39
|
+
super
|
40
|
+
lbp_init_line_state
|
41
|
+
end
|
42
|
+
def receive_data data
|
43
|
+
if @lbp_mode == :lines
|
44
|
+
begin
|
45
|
+
@lpb_buffer.extract(data).each do |line|
|
46
|
+
receive_line(line.chomp) if respond_to?(:receive_line)
|
47
|
+
end
|
48
|
+
rescue Exception
|
49
|
+
receive_error('overlength line') if respond_to?(:receive_error)
|
50
|
+
close_connection
|
51
|
+
return
|
52
|
+
end
|
53
|
+
else
|
54
|
+
if @lbp_binary_limit > 0
|
55
|
+
wanted = @lbp_binary_limit - @lbp_binary_bytes_received
|
56
|
+
chunk = nil
|
57
|
+
if data.length > wanted
|
58
|
+
chunk = data.slice!(0...wanted)
|
59
|
+
else
|
60
|
+
chunk = data
|
61
|
+
data = ""
|
62
|
+
end
|
63
|
+
@lbp_binary_buffer[@lbp_binary_bytes_received...(@lbp_binary_bytes_received+chunk.length)] = chunk
|
64
|
+
@lbp_binary_bytes_received += chunk.length
|
65
|
+
if @lbp_binary_bytes_received == @lbp_binary_limit
|
66
|
+
receive_binary_data(@lbp_binary_buffer) if respond_to?(:receive_binary_data)
|
67
|
+
lbp_init_line_state
|
68
|
+
end
|
69
|
+
receive_data(data) if data.length > 0
|
70
|
+
else
|
71
|
+
receive_binary_data(data) if respond_to?(:receive_binary_data)
|
72
|
+
data = ""
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def unbind
|
78
|
+
if @lbp_mode == :binary and @lbp_binary_limit > 0
|
79
|
+
if respond_to?(:receive_binary_data)
|
80
|
+
receive_binary_data( @lbp_binary_buffer[0...@lbp_binary_bytes_received] )
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Set up to read the supplied number of binary bytes.
|
86
|
+
# This recycles all the data currently waiting in the line buffer, if any.
|
87
|
+
# If the limit is nil, then ALL subsequent data will be treated as binary
|
88
|
+
# data and passed to the upstream protocol handler as we receive it.
|
89
|
+
# If a limit is given, we'll hold the incoming binary data and not
|
90
|
+
# pass it upstream until we've seen it all, or until there is an unbind
|
91
|
+
# (in which case we'll pass up a partial).
|
92
|
+
# Specifying nil for the limit (the default) means there is no limit.
|
93
|
+
# Specifiyng zero for the limit will cause an immediate transition back to line mode.
|
94
|
+
#
|
95
|
+
def set_binary_mode size = nil
|
96
|
+
if @lbp_mode == :lines
|
97
|
+
if size == 0
|
98
|
+
receive_binary_data("") if respond_to?(:receive_binary_data)
|
99
|
+
# Do no more work here. Stay in line mode and keep consuming data.
|
100
|
+
else
|
101
|
+
@lbp_binary_limit = size.to_i # (nil will be stored as zero)
|
102
|
+
if @lbp_binary_limit > 0
|
103
|
+
raise "Overlength" if @lbp_binary_limit > MaxBinaryLength # arbitrary sanity check
|
104
|
+
@lbp_binary_buffer = "\0" * @lbp_binary_limit
|
105
|
+
@lbp_binary_bytes_received = 0
|
106
|
+
end
|
107
|
+
|
108
|
+
@lbp_mode = :binary
|
109
|
+
receive_data @lpb_buffer.flush
|
110
|
+
end
|
111
|
+
else
|
112
|
+
raise "invalid operation"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
#--
|
117
|
+
# For internal use, establish protocol baseline for handling lines.
|
118
|
+
def lbp_init_line_state
|
119
|
+
@lpb_buffer = BufferedTokenizer.new("\n", MaxLineLength)
|
120
|
+
@lbp_mode = :lines
|
121
|
+
end
|
122
|
+
private :lbp_init_line_state
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -1,160 +1,161 @@
|
|
1
|
-
#--
|
2
|
-
#
|
3
|
-
# Author:: Francis Cianfrocca (gmail: blackhedd)
|
4
|
-
# Homepage:: http://rubyeventmachine.com
|
5
|
-
# Date:: 15 November 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
|
-
# In the grand, time-honored tradition of re-inventing the wheel, we offer
|
29
|
-
# here YET ANOTHER protocol that handles line-oriented data with interspersed
|
30
|
-
# binary text. This one trades away some of the performance optimizations of
|
31
|
-
# EventMachine::Protocols::LineAndTextProtocol in order to get better correctness
|
32
|
-
# with regard to binary text blocks that can switch back to line mode. It also
|
33
|
-
# permits the line-delimiter to change in midstream.
|
34
|
-
# This was originally written to support Stomp.
|
35
|
-
module LineText2
|
36
|
-
# TODO! We're not enforcing the limits on header lengths and text-lengths.
|
37
|
-
# When we get around to that, call #receive_error if the user defined it, otherwise
|
38
|
-
# throw exceptions.
|
39
|
-
|
40
|
-
MaxLineLength = 16*1024
|
41
|
-
MaxBinaryLength = 32*1024*1024
|
42
|
-
|
43
|
-
#--
|
44
|
-
# Will be called recursively until there's no data to read.
|
45
|
-
# That way the user-defined handlers we call can modify the
|
46
|
-
# handling characteristics on a per-token basis.
|
47
|
-
#
|
48
|
-
def receive_data data
|
49
|
-
return unless (data and data.length > 0)
|
50
|
-
|
51
|
-
# Do this stuff in lieu of a constructor.
|
52
|
-
@lt2_mode ||= :lines
|
53
|
-
@lt2_delimiter ||= "\n"
|
54
|
-
@lt2_linebuffer ||= []
|
55
|
-
|
56
|
-
if @lt2_mode == :lines
|
57
|
-
if ix = data.index( @lt2_delimiter )
|
58
|
-
@lt2_linebuffer << data[0...ix]
|
59
|
-
ln = @lt2_linebuffer.join
|
60
|
-
@lt2_linebuffer.clear
|
61
|
-
if @lt2_delimiter == "\n"
|
62
|
-
ln.chomp!
|
63
|
-
end
|
64
|
-
receive_line ln
|
65
|
-
receive_data data[(ix+@lt2_delimiter.length)..-1]
|
66
|
-
else
|
67
|
-
@lt2_linebuffer << data
|
68
|
-
end
|
69
|
-
elsif @lt2_mode == :text
|
70
|
-
if @lt2_textsize
|
71
|
-
needed = @lt2_textsize - @lt2_textpos
|
72
|
-
will_take = if data.length > needed
|
73
|
-
needed
|
74
|
-
else
|
75
|
-
data.length
|
76
|
-
end
|
77
|
-
|
78
|
-
@lt2_textbuffer << data[0...will_take]
|
79
|
-
tail = data[will_take..-1]
|
80
|
-
|
81
|
-
@lt2_textpos += will_take
|
82
|
-
if @lt2_textpos >= @lt2_textsize
|
83
|
-
# Reset line mode (the default behavior) BEFORE calling the
|
84
|
-
# receive_binary_data. This makes it possible for user code
|
85
|
-
# to call set_text_mode, enabling chains of text blocks
|
86
|
-
# (which can possibly be of different sizes).
|
87
|
-
set_line_mode
|
88
|
-
receive_binary_data @lt2_textbuffer.join
|
89
|
-
receive_end_of_binary_data
|
90
|
-
end
|
91
|
-
|
92
|
-
receive_data tail
|
93
|
-
else
|
94
|
-
receive_binary_data data
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
|
100
|
-
def set_delimiter delim
|
101
|
-
@lt2_delimiter = delim.to_s
|
102
|
-
end
|
103
|
-
|
104
|
-
# Called internally but also exposed to user code, for the case in which
|
105
|
-
# processing of binary data creates a need to transition back to line mode.
|
106
|
-
# We support an optional parameter to "throw back" some data, which might
|
107
|
-
# be an umprocessed chunk of the transmitted binary data, or something else
|
108
|
-
# entirely.
|
109
|
-
def set_line_mode data=""
|
110
|
-
@lt2_mode = :lines
|
111
|
-
(@lt2_linebuffer ||= []).clear
|
112
|
-
receive_data data.to_s
|
113
|
-
end
|
114
|
-
|
115
|
-
def set_text_mode size=nil
|
116
|
-
if size == 0
|
117
|
-
set_line_mode
|
118
|
-
else
|
119
|
-
@lt2_mode = :text
|
120
|
-
(@lt2_textbuffer ||= []).clear
|
121
|
-
@lt2_textsize = size # which can be nil, signifying no limit
|
122
|
-
@lt2_textpos = 0
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
# Alias for #set_text_mode, added for back-compatibility with LineAndTextProtocol.
|
127
|
-
def set_binary_mode size=nil
|
128
|
-
set_text_mode size
|
129
|
-
end
|
130
|
-
|
131
|
-
# In case of a dropped connection, we'll send a partial buffer to user code
|
132
|
-
# when in sized text mode. User overrides of #receive_binary_data need to
|
133
|
-
# be aware that they may get a short buffer.
|
134
|
-
def unbind
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
#
|
152
|
-
#
|
153
|
-
# to
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
end
|
160
|
-
|
1
|
+
#--
|
2
|
+
#
|
3
|
+
# Author:: Francis Cianfrocca (gmail: blackhedd)
|
4
|
+
# Homepage:: http://rubyeventmachine.com
|
5
|
+
# Date:: 15 November 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
|
+
# In the grand, time-honored tradition of re-inventing the wheel, we offer
|
29
|
+
# here YET ANOTHER protocol that handles line-oriented data with interspersed
|
30
|
+
# binary text. This one trades away some of the performance optimizations of
|
31
|
+
# EventMachine::Protocols::LineAndTextProtocol in order to get better correctness
|
32
|
+
# with regard to binary text blocks that can switch back to line mode. It also
|
33
|
+
# permits the line-delimiter to change in midstream.
|
34
|
+
# This was originally written to support Stomp.
|
35
|
+
module LineText2
|
36
|
+
# TODO! We're not enforcing the limits on header lengths and text-lengths.
|
37
|
+
# When we get around to that, call #receive_error if the user defined it, otherwise
|
38
|
+
# throw exceptions.
|
39
|
+
|
40
|
+
MaxLineLength = 16*1024
|
41
|
+
MaxBinaryLength = 32*1024*1024
|
42
|
+
|
43
|
+
#--
|
44
|
+
# Will be called recursively until there's no data to read.
|
45
|
+
# That way the user-defined handlers we call can modify the
|
46
|
+
# handling characteristics on a per-token basis.
|
47
|
+
#
|
48
|
+
def receive_data data
|
49
|
+
return unless (data and data.length > 0)
|
50
|
+
|
51
|
+
# Do this stuff in lieu of a constructor.
|
52
|
+
@lt2_mode ||= :lines
|
53
|
+
@lt2_delimiter ||= "\n"
|
54
|
+
@lt2_linebuffer ||= []
|
55
|
+
|
56
|
+
if @lt2_mode == :lines
|
57
|
+
if ix = data.index( @lt2_delimiter )
|
58
|
+
@lt2_linebuffer << data[0...ix]
|
59
|
+
ln = @lt2_linebuffer.join
|
60
|
+
@lt2_linebuffer.clear
|
61
|
+
if @lt2_delimiter == "\n"
|
62
|
+
ln.chomp!
|
63
|
+
end
|
64
|
+
receive_line ln
|
65
|
+
receive_data data[(ix+@lt2_delimiter.length)..-1]
|
66
|
+
else
|
67
|
+
@lt2_linebuffer << data
|
68
|
+
end
|
69
|
+
elsif @lt2_mode == :text
|
70
|
+
if @lt2_textsize
|
71
|
+
needed = @lt2_textsize - @lt2_textpos
|
72
|
+
will_take = if data.length > needed
|
73
|
+
needed
|
74
|
+
else
|
75
|
+
data.length
|
76
|
+
end
|
77
|
+
|
78
|
+
@lt2_textbuffer << data[0...will_take]
|
79
|
+
tail = data[will_take..-1]
|
80
|
+
|
81
|
+
@lt2_textpos += will_take
|
82
|
+
if @lt2_textpos >= @lt2_textsize
|
83
|
+
# Reset line mode (the default behavior) BEFORE calling the
|
84
|
+
# receive_binary_data. This makes it possible for user code
|
85
|
+
# to call set_text_mode, enabling chains of text blocks
|
86
|
+
# (which can possibly be of different sizes).
|
87
|
+
set_line_mode
|
88
|
+
receive_binary_data @lt2_textbuffer.join
|
89
|
+
receive_end_of_binary_data
|
90
|
+
end
|
91
|
+
|
92
|
+
receive_data tail
|
93
|
+
else
|
94
|
+
receive_binary_data data
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
def set_delimiter delim
|
101
|
+
@lt2_delimiter = delim.to_s
|
102
|
+
end
|
103
|
+
|
104
|
+
# Called internally but also exposed to user code, for the case in which
|
105
|
+
# processing of binary data creates a need to transition back to line mode.
|
106
|
+
# We support an optional parameter to "throw back" some data, which might
|
107
|
+
# be an umprocessed chunk of the transmitted binary data, or something else
|
108
|
+
# entirely.
|
109
|
+
def set_line_mode data=""
|
110
|
+
@lt2_mode = :lines
|
111
|
+
(@lt2_linebuffer ||= []).clear
|
112
|
+
receive_data data.to_s
|
113
|
+
end
|
114
|
+
|
115
|
+
def set_text_mode size=nil
|
116
|
+
if size == 0
|
117
|
+
set_line_mode
|
118
|
+
else
|
119
|
+
@lt2_mode = :text
|
120
|
+
(@lt2_textbuffer ||= []).clear
|
121
|
+
@lt2_textsize = size # which can be nil, signifying no limit
|
122
|
+
@lt2_textpos = 0
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
# Alias for #set_text_mode, added for back-compatibility with LineAndTextProtocol.
|
127
|
+
def set_binary_mode size=nil
|
128
|
+
set_text_mode size
|
129
|
+
end
|
130
|
+
|
131
|
+
# In case of a dropped connection, we'll send a partial buffer to user code
|
132
|
+
# when in sized text mode. User overrides of #receive_binary_data need to
|
133
|
+
# be aware that they may get a short buffer.
|
134
|
+
def unbind
|
135
|
+
@lt2_mode ||= nil
|
136
|
+
if @lt2_mode == :text and @lt2_textpos > 0
|
137
|
+
receive_binary_data @lt2_textbuffer.join
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
# Stub. Should be subclassed by user code.
|
142
|
+
def receive_line ln
|
143
|
+
# no-op
|
144
|
+
end
|
145
|
+
|
146
|
+
# Stub. Should be subclassed by user code.
|
147
|
+
def receive_binary_data data
|
148
|
+
# no-op
|
149
|
+
end
|
150
|
+
|
151
|
+
# Stub. Should be subclassed by user code.
|
152
|
+
# This is called when transitioning internally from text mode
|
153
|
+
# back to line mode. Useful when client code doesn't want
|
154
|
+
# to keep track of how much data it's received.
|
155
|
+
def receive_end_of_binary_data
|
156
|
+
# no-op
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|