eventmachine 0.7.0 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +44 -265
- data/GNU +281 -0
- data/LEGAL +25 -0
- data/README +5 -3
- data/RELEASE_NOTES +7 -2
- data/ext/binder.cpp +8 -15
- data/ext/binder.h +8 -15
- data/ext/cmain.cpp +29 -15
- data/ext/ed.cpp +36 -43
- data/ext/ed.h +8 -15
- data/ext/em.cpp +116 -21
- data/ext/em.h +11 -16
- data/ext/emwin.cpp +9 -16
- data/ext/emwin.h +9 -16
- data/ext/eventmachine.h +9 -14
- data/ext/extconf.rb +9 -17
- data/ext/files.cpp +7 -14
- data/ext/files.h +7 -14
- data/ext/page.cpp +8 -15
- data/ext/page.h +8 -15
- data/ext/project.h +15 -15
- data/ext/rubymain.cpp +37 -16
- data/ext/sigs.cpp +8 -15
- data/ext/sigs.h +8 -15
- data/ext/ssl.cpp +8 -15
- data/ext/ssl.h +8 -15
- data/lib/em/deferrable.rb +40 -27
- data/lib/em/eventable.rb +12 -23
- data/lib/em/future.rb +62 -0
- data/lib/eventmachine.rb +156 -66
- data/lib/eventmachine_version.rb +12 -23
- data/lib/evma.rb +15 -18
- data/lib/evma/callback.rb +16 -19
- data/lib/evma/container.rb +17 -19
- data/lib/evma/factory.rb +16 -19
- data/lib/evma/protocol.rb +17 -19
- data/lib/evma/reactor.rb +17 -19
- data/lib/pr_eventmachine.rb +12 -23
- data/lib/protocols/buftok.rb +121 -0
- data/lib/protocols/header_and_content.rb +12 -23
- data/lib/protocols/httpclient.rb +44 -31
- data/lib/protocols/line_and_text.rb +97 -118
- data/lib/protocols/tcptest.rb +12 -22
- data/tests/test_basic.rb +14 -24
- data/tests/test_eventables.rb +14 -24
- data/tests/test_exc.rb +57 -0
- data/tests/test_futures.rb +136 -0
- data/tests/test_hc.rb +14 -24
- data/tests/test_httpclient.rb +106 -25
- data/tests/test_ltp.rb +14 -23
- data/tests/test_timers.rb +109 -0
- data/tests/test_ud.rb +14 -24
- metadata +11 -2
data/lib/eventmachine_version.rb
CHANGED
@@ -1,34 +1,23 @@
|
|
1
|
-
# $Id: eventmachine_version.rb
|
1
|
+
# $Id: eventmachine_version.rb 324 2007-05-22 22:43:35Z blackhedd $
|
2
2
|
#
|
3
|
-
# Author::
|
3
|
+
# Author:: Francis Cianfrocca (gmail: blackhedd)
|
4
|
+
# Homepage:: http://rubyeventmachine.com
|
4
5
|
# Date:: 8 Apr 2006
|
5
6
|
#
|
6
|
-
# Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
|
7
|
-
#
|
8
|
-
# This program is made available under the terms of the GPL version 2.
|
9
|
-
#
|
10
7
|
# See EventMachine and EventMachine::Connection for documentation and
|
11
8
|
# usage examples.
|
12
9
|
#
|
13
10
|
#----------------------------------------------------------------------------
|
14
11
|
#
|
15
|
-
# Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
12
|
+
# Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
|
13
|
+
# Gmail: blackhedd
|
14
|
+
#
|
19
15
|
# This program is free software; you can redistribute it and/or modify
|
20
|
-
# it under the terms of the GNU General Public License
|
21
|
-
# the Free Software Foundation; either version 2 of the
|
22
|
-
# (at your option) any later version.
|
23
|
-
#
|
24
|
-
#
|
25
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
26
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
27
|
-
# GNU General Public License for more details.
|
28
|
-
#
|
29
|
-
# You should have received a copy of the GNU General Public License
|
30
|
-
# along with this program; if not, write to the Free Software
|
31
|
-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
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.
|
32
21
|
#
|
33
22
|
#---------------------------------------------------------------------------
|
34
23
|
#
|
@@ -36,7 +25,7 @@
|
|
36
25
|
|
37
26
|
module EventMachine
|
38
27
|
|
39
|
-
VERSION = "0.7.
|
28
|
+
VERSION = "0.7.2"
|
40
29
|
|
41
30
|
end
|
42
31
|
|
data/lib/evma.rb
CHANGED
@@ -1,27 +1,24 @@
|
|
1
|
-
# $Id: evma.rb
|
1
|
+
# $Id: evma.rb 319 2007-05-22 22:11:18Z blackhedd $
|
2
2
|
#
|
3
|
+
# Author:: Francis Cianfrocca (gmail: blackhedd)
|
3
4
|
# Homepage:: http://rubyeventmachine.com
|
4
|
-
#
|
5
|
-
#
|
5
|
+
# Date:: 8 Apr 2006
|
6
|
+
#
|
7
|
+
# See EventMachine and EventMachine::Connection for documentation and
|
8
|
+
# usage examples.
|
6
9
|
#
|
7
|
-
|
8
|
-
# See the file COPYING in the distribution for full licensing information.
|
9
|
-
#-------------------------------------------------------------------
|
10
|
-
# This file is part of Ruby/EventMachine.
|
10
|
+
#----------------------------------------------------------------------------
|
11
11
|
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
# the Free Software Foundation; either version 2.1 of the License, or
|
15
|
-
# (at your option) any later version.
|
12
|
+
# Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
|
13
|
+
# Gmail: blackhedd
|
16
14
|
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
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.
|
21
19
|
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
20
|
+
# See the file COPYING for complete licensing information.
|
21
|
+
#
|
25
22
|
#-------------------------------------------------------------------
|
26
23
|
#
|
27
24
|
|
data/lib/evma/callback.rb
CHANGED
@@ -1,28 +1,25 @@
|
|
1
|
-
# $Id: callback.rb
|
1
|
+
# $Id: callback.rb 321 2007-05-22 22:15:04Z blackhedd $
|
2
2
|
#
|
3
|
+
# Author:: Francis Cianfrocca (gmail: blackhedd)
|
3
4
|
# Homepage:: http://rubyeventmachine.com
|
4
|
-
#
|
5
|
-
#
|
5
|
+
# Date:: 19 May 2006
|
6
|
+
#
|
7
|
+
# See EventMachine and EventMachine::Connection for documentation and
|
8
|
+
# usage examples.
|
6
9
|
#
|
7
|
-
|
8
|
-
# See the file COPYING in the distribution for full licensing information.
|
9
|
-
#-------------------------------------------------------------------
|
10
|
-
# This file is part of Ruby/EventMachine.
|
10
|
+
#----------------------------------------------------------------------------
|
11
11
|
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
# the Free Software Foundation; either version 2.1 of the License, or
|
15
|
-
# (at your option) any later version.
|
12
|
+
# Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
|
13
|
+
# Gmail: blackhedd
|
16
14
|
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
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.
|
21
19
|
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
|
25
|
-
#-------------------------------------------------------------------
|
20
|
+
# See the file COPYING for complete licensing information.
|
21
|
+
#
|
22
|
+
#---------------------------------------------------------------------------
|
26
23
|
#
|
27
24
|
|
28
25
|
|
data/lib/evma/container.rb
CHANGED
@@ -1,31 +1,29 @@
|
|
1
|
-
# $Id: container.rb
|
1
|
+
# $Id: container.rb 321 2007-05-22 22:15:04Z blackhedd $
|
2
2
|
#
|
3
|
+
# Author:: Francis Cianfrocca (gmail: blackhedd)
|
3
4
|
# Homepage:: http://rubyeventmachine.com
|
4
|
-
#
|
5
|
-
#
|
5
|
+
# Date:: 19 May 2006
|
6
|
+
#
|
7
|
+
# See EventMachine and EventMachine::Connection for documentation and
|
8
|
+
# usage examples.
|
6
9
|
#
|
7
|
-
|
8
|
-
# See the file COPYING in the distribution for full licensing information.
|
9
|
-
#-------------------------------------------------------------------
|
10
|
-
# This file is part of Ruby/EventMachine.
|
10
|
+
#----------------------------------------------------------------------------
|
11
11
|
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
# the Free Software Foundation; either version 2.1 of the License, or
|
15
|
-
# (at your option) any later version.
|
12
|
+
# Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
|
13
|
+
# Gmail: blackhedd
|
16
14
|
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
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.
|
21
19
|
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
|
25
|
-
#-------------------------------------------------------------------
|
20
|
+
# See the file COPYING for complete licensing information.
|
21
|
+
#
|
22
|
+
#---------------------------------------------------------------------------
|
26
23
|
#
|
27
24
|
|
28
25
|
|
26
|
+
|
29
27
|
require 'singleton'
|
30
28
|
|
31
29
|
module Evma
|
data/lib/evma/factory.rb
CHANGED
@@ -1,28 +1,25 @@
|
|
1
|
-
# $Id: factory.rb
|
1
|
+
# $Id: factory.rb 321 2007-05-22 22:15:04Z blackhedd $
|
2
2
|
#
|
3
|
+
# Author:: Francis Cianfrocca (gmail: blackhedd)
|
3
4
|
# Homepage:: http://rubyeventmachine.com
|
4
|
-
#
|
5
|
-
#
|
5
|
+
# Date:: 19 May 2006
|
6
|
+
#
|
7
|
+
# See EventMachine and EventMachine::Connection for documentation and
|
8
|
+
# usage examples.
|
6
9
|
#
|
7
|
-
|
8
|
-
# See the file COPYING in the distribution for full licensing information.
|
9
|
-
#-------------------------------------------------------------------
|
10
|
-
# This file is part of Ruby/EventMachine.
|
10
|
+
#----------------------------------------------------------------------------
|
11
11
|
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
# the Free Software Foundation; either version 2.1 of the License, or
|
15
|
-
# (at your option) any later version.
|
12
|
+
# Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
|
13
|
+
# Gmail: blackhedd
|
16
14
|
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
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.
|
21
19
|
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
|
25
|
-
#-------------------------------------------------------------------
|
20
|
+
# See the file COPYING for complete licensing information.
|
21
|
+
#
|
22
|
+
#---------------------------------------------------------------------------
|
26
23
|
#
|
27
24
|
|
28
25
|
|
data/lib/evma/protocol.rb
CHANGED
@@ -1,30 +1,28 @@
|
|
1
|
-
# $Id: protocol.rb
|
1
|
+
# $Id: protocol.rb 321 2007-05-22 22:15:04Z blackhedd $
|
2
2
|
#
|
3
|
+
# Author:: Francis Cianfrocca (gmail: blackhedd)
|
3
4
|
# Homepage:: http://rubyeventmachine.com
|
4
|
-
#
|
5
|
-
#
|
5
|
+
# Date:: 19 May 2006
|
6
|
+
#
|
7
|
+
# See EventMachine and EventMachine::Connection for documentation and
|
8
|
+
# usage examples.
|
6
9
|
#
|
7
|
-
|
8
|
-
# See the file COPYING in the distribution for full licensing information.
|
9
|
-
#-------------------------------------------------------------------
|
10
|
-
# This file is part of Ruby/EventMachine.
|
10
|
+
#----------------------------------------------------------------------------
|
11
11
|
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
# the Free Software Foundation; either version 2.1 of the License, or
|
15
|
-
# (at your option) any later version.
|
12
|
+
# Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
|
13
|
+
# Gmail: blackhedd
|
16
14
|
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
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.
|
21
19
|
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
|
25
|
-
#-------------------------------------------------------------------
|
20
|
+
# See the file COPYING for complete licensing information.
|
21
|
+
#
|
22
|
+
#---------------------------------------------------------------------------
|
26
23
|
#
|
27
24
|
|
25
|
+
|
28
26
|
module Evma
|
29
27
|
class Protocol
|
30
28
|
|
data/lib/evma/reactor.rb
CHANGED
@@ -1,31 +1,29 @@
|
|
1
|
-
# $Id: reactor.rb
|
1
|
+
# $Id: reactor.rb 321 2007-05-22 22:15:04Z blackhedd $
|
2
2
|
#
|
3
|
+
# Author:: Francis Cianfrocca (gmail: blackhedd)
|
3
4
|
# Homepage:: http://rubyeventmachine.com
|
4
|
-
#
|
5
|
-
#
|
5
|
+
# Date:: 18 May 2006
|
6
|
+
#
|
7
|
+
# See EventMachine and EventMachine::Connection for documentation and
|
8
|
+
# usage examples.
|
6
9
|
#
|
7
|
-
|
8
|
-
# See the file COPYING in the distribution for full licensing information.
|
9
|
-
#-------------------------------------------------------------------
|
10
|
-
# This file is part of Ruby/EventMachine.
|
10
|
+
#----------------------------------------------------------------------------
|
11
11
|
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
# the Free Software Foundation; either version 2.1 of the License, or
|
15
|
-
# (at your option) any later version.
|
12
|
+
# Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
|
13
|
+
# Gmail: blackhedd
|
16
14
|
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
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.
|
21
19
|
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
|
25
|
-
#-------------------------------------------------------------------
|
20
|
+
# See the file COPYING for complete licensing information.
|
21
|
+
#
|
22
|
+
#---------------------------------------------------------------------------
|
26
23
|
#
|
27
24
|
|
28
25
|
|
26
|
+
|
29
27
|
require 'singleton'
|
30
28
|
|
31
29
|
module Evma
|
data/lib/pr_eventmachine.rb
CHANGED
@@ -1,36 +1,25 @@
|
|
1
|
-
# $Id: pr_eventmachine.rb
|
1
|
+
# $Id: pr_eventmachine.rb 319 2007-05-22 22:11:18Z blackhedd $
|
2
2
|
#
|
3
|
-
# Author::
|
3
|
+
# Author:: Francis Cianfrocca (gmail: blackhedd)
|
4
|
+
# Homepage:: http://rubyeventmachine.com
|
4
5
|
# Date:: 8 Apr 2006
|
5
6
|
#
|
6
|
-
# Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
|
7
|
-
#
|
8
|
-
# This program is made available under the terms of the GPL version 2.
|
9
|
-
#
|
10
7
|
# See EventMachine and EventMachine::Connection for documentation and
|
11
8
|
# usage examples.
|
12
9
|
#
|
13
10
|
#----------------------------------------------------------------------------
|
14
11
|
#
|
15
|
-
# Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
12
|
+
# Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
|
13
|
+
# Gmail: blackhedd
|
14
|
+
#
|
19
15
|
# This program is free software; you can redistribute it and/or modify
|
20
|
-
# it under the terms of the GNU General Public License
|
21
|
-
# the Free Software Foundation; either version 2 of the
|
22
|
-
# (at your option) any later version.
|
23
|
-
#
|
24
|
-
#
|
25
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
26
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
27
|
-
# GNU General Public License for more details.
|
28
|
-
#
|
29
|
-
# You should have received a copy of the GNU General Public License
|
30
|
-
# along with this program; if not, write to the Free Software
|
31
|
-
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
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.
|
32
21
|
#
|
33
|
-
|
22
|
+
#-------------------------------------------------------------------
|
34
23
|
#
|
35
24
|
#
|
36
25
|
|
@@ -0,0 +1,121 @@
|
|
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
|
+
# Multi-character token support.
|
79
|
+
# Split any tokens that were incomplete on the last iteration buf complete now.
|
80
|
+
entities.map! do |e|
|
81
|
+
e.split @delimiter, -1
|
82
|
+
end
|
83
|
+
# Flatten the resulting array. This has the side effect of removing the empty
|
84
|
+
# entry at the end that was produced by passing -1 to split. Add it again if
|
85
|
+
# necessary.
|
86
|
+
if (entities[-1] == [])
|
87
|
+
entities.flatten! << []
|
88
|
+
else
|
89
|
+
entities.flatten!
|
90
|
+
end
|
91
|
+
|
92
|
+
# Now that we've hit a token, joined the input buffer and added it to the entities
|
93
|
+
# list, we can go ahead and clear the input buffer. All of the segments that were
|
94
|
+
# stored before the join can now be garbage collected.
|
95
|
+
@input.clear
|
96
|
+
|
97
|
+
# The last entity in the list is not token delimited, however, thanks to the -1
|
98
|
+
# passed to split. It represents the beginning of a new list of as-yet-untokenized
|
99
|
+
# data, so we add it to the start of the list.
|
100
|
+
@input << entities.pop
|
101
|
+
|
102
|
+
# Set the new input buffer size, provided we're keeping track
|
103
|
+
@input_size = @input.first.size if @size_limit
|
104
|
+
|
105
|
+
# Now we're left with the list of extracted token-delimited entities we wanted
|
106
|
+
# in the first place. Hooray!
|
107
|
+
entities
|
108
|
+
end
|
109
|
+
|
110
|
+
# Flush the contents of the input buffer, i.e. return the input buffer even though
|
111
|
+
# a token has not yet been encountered
|
112
|
+
def flush
|
113
|
+
buffer = @input.join
|
114
|
+
@input.clear
|
115
|
+
buffer
|
116
|
+
end
|
117
|
+
|
118
|
+
def empty?
|
119
|
+
@input.empty?
|
120
|
+
end
|
121
|
+
end
|