eventmachine 0.7.0 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/COPYING +44 -265
  2. data/GNU +281 -0
  3. data/LEGAL +25 -0
  4. data/README +5 -3
  5. data/RELEASE_NOTES +7 -2
  6. data/ext/binder.cpp +8 -15
  7. data/ext/binder.h +8 -15
  8. data/ext/cmain.cpp +29 -15
  9. data/ext/ed.cpp +36 -43
  10. data/ext/ed.h +8 -15
  11. data/ext/em.cpp +116 -21
  12. data/ext/em.h +11 -16
  13. data/ext/emwin.cpp +9 -16
  14. data/ext/emwin.h +9 -16
  15. data/ext/eventmachine.h +9 -14
  16. data/ext/extconf.rb +9 -17
  17. data/ext/files.cpp +7 -14
  18. data/ext/files.h +7 -14
  19. data/ext/page.cpp +8 -15
  20. data/ext/page.h +8 -15
  21. data/ext/project.h +15 -15
  22. data/ext/rubymain.cpp +37 -16
  23. data/ext/sigs.cpp +8 -15
  24. data/ext/sigs.h +8 -15
  25. data/ext/ssl.cpp +8 -15
  26. data/ext/ssl.h +8 -15
  27. data/lib/em/deferrable.rb +40 -27
  28. data/lib/em/eventable.rb +12 -23
  29. data/lib/em/future.rb +62 -0
  30. data/lib/eventmachine.rb +156 -66
  31. data/lib/eventmachine_version.rb +12 -23
  32. data/lib/evma.rb +15 -18
  33. data/lib/evma/callback.rb +16 -19
  34. data/lib/evma/container.rb +17 -19
  35. data/lib/evma/factory.rb +16 -19
  36. data/lib/evma/protocol.rb +17 -19
  37. data/lib/evma/reactor.rb +17 -19
  38. data/lib/pr_eventmachine.rb +12 -23
  39. data/lib/protocols/buftok.rb +121 -0
  40. data/lib/protocols/header_and_content.rb +12 -23
  41. data/lib/protocols/httpclient.rb +44 -31
  42. data/lib/protocols/line_and_text.rb +97 -118
  43. data/lib/protocols/tcptest.rb +12 -22
  44. data/tests/test_basic.rb +14 -24
  45. data/tests/test_eventables.rb +14 -24
  46. data/tests/test_exc.rb +57 -0
  47. data/tests/test_futures.rb +136 -0
  48. data/tests/test_hc.rb +14 -24
  49. data/tests/test_httpclient.rb +106 -25
  50. data/tests/test_ltp.rb +14 -23
  51. data/tests/test_timers.rb +109 -0
  52. data/tests/test_ud.rb +14 -24
  53. metadata +11 -2
@@ -1,34 +1,23 @@
1
- # $Id: header_and_content.rb 281 2006-11-20 03:17:22Z blackhedd $
1
+ # $Id: header_and_content.rb 322 2007-05-22 22:18:35Z blackhedd $
2
2
  #
3
- # Author:: blackhedd (gmail address: garbagecat10).
4
- # Date:: 15 November 2006
3
+ # Author:: Francis Cianfrocca (gmail: blackhedd)
4
+ # Homepage:: http://rubyeventmachine.com
5
+ # Date:: 15 Nov 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
- # Gmail: garbagecat10
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 as published by
21
- # the Free Software Foundation; either version 2 of the License, or
22
- # (at your option) any later version.
23
- #
24
- # This program is distributed in the hope that it will be useful,
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
  #
@@ -1,34 +1,23 @@
1
- # $Id: httpclient.rb 226 2006-08-10 08:55:49Z blackhedd $
1
+ # $Id: httpclient.rb 322 2007-05-22 22:18:35Z blackhedd $
2
2
  #
3
- # Author:: blackhedd (gmail address: garbagecat10).
3
+ # Author:: Francis Cianfrocca (gmail: blackhedd)
4
+ # Homepage:: http://rubyeventmachine.com
4
5
  # Date:: 16 July 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
- # Gmail: garbagecat10
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 as published by
21
- # the Free Software Foundation; either version 2 of the License, or
22
- # (at your option) any later version.
23
- #
24
- # This program is distributed in the hope that it will be useful,
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
  #
@@ -43,8 +32,9 @@ class HttpClient < Connection
43
32
  include EventMachine::Deferrable
44
33
 
45
34
 
35
+ MaxPostContentLength = 20 * 1024 * 1024
36
+
46
37
  # USAGE SAMPLE:
47
- # WARNING, POST is not yet supported!!!!!
48
38
  #
49
39
  # EventMachine.run {
50
40
  # http = EventMachine::Protocols::HttpClient.request(
@@ -62,7 +52,7 @@ class HttpClient < Connection
62
52
  #
63
53
 
64
54
  # TODO:
65
- # POST REQUESTS!!!!!!!!!!!
55
+ # Add streaming so we can support enormous POSTs. Current max is 20meg.
66
56
  # Timeout for connections that run too long or hang somewhere in the middle.
67
57
  # Persistent connections (HTTP/1.1), may need a associated delegate object.
68
58
  # DNS: Some way to cache DNS lookups for hostnames we connect to. Ruby's
@@ -100,10 +90,11 @@ class HttpClient < Connection
100
90
  end
101
91
 
102
92
  def send_request args
93
+ args[:verb] ||= args[:method] # Support :method as an alternative to :verb.
103
94
  args[:verb] ||= :get # IS THIS A GOOD IDEA, to default to GET if nothing was specified?
104
95
 
105
96
  verb = args[:verb].to_s.upcase
106
- unless ["GET", "POST", "HEAD"].include?(verb)
97
+ unless ["GET", "POST", "PUT", "DELETE", "HEAD"].include?(verb)
107
98
  set_deferred_status :failed, {:status => 0} # TODO, not signalling the error type
108
99
  return # NOTE THE EARLY RETURN, we're not sending any data.
109
100
  end
@@ -120,16 +111,33 @@ class HttpClient < Connection
120
111
 
121
112
  # Allow an override for the host header if it's not the connect-string.
122
113
  host = args[:host_header] || args[:host] || "_"
114
+ # For now, ALWAYS tuck in the port string, although we may want to omit it if it's the default.
115
+ port = args[:port]
116
+
117
+ # POST items.
118
+ postcontenttype = args[:contenttype] || "application/octet-stream"
119
+ postcontent = args[:content] || ""
120
+ raise "oversized content in HTTP POST" if postcontent.length > MaxPostContentLength
123
121
 
124
122
  # ESSENTIAL for the request's line-endings to be CRLF, not LF. Some servers misbehave otherwise.
125
123
  req = [
126
- "#{verb} #{request}#{qs} HTTP/1.1",
127
- "Host: #{host}",
124
+ "#{verb} #{request}#{qs} HTTP/1.0",
125
+ "Host: #{host}:#{port}",
128
126
  "User-agent: Ruby EventMachine",
129
- ""
130
- ].map {|l| "#{l}\r\n"}.join
127
+ ]
131
128
 
132
- send_data req
129
+ if verb == "POST" || verb == "PUT"
130
+ req << "Content-type: #{postcontenttype}"
131
+ req << "Content-length: #{postcontent.length}"
132
+ end
133
+
134
+ req << ""
135
+ reqstring = req.map {|l| "#{l}\r\n"}.join
136
+ send_data reqstring
137
+
138
+ if verb == "POST" || verb == "PUT"
139
+ send_data postcontent
140
+ end
133
141
  end
134
142
 
135
143
 
@@ -149,7 +157,12 @@ class HttpClient < Connection
149
157
  if ary.length == 2
150
158
  data = ary.last
151
159
  if ary.first == ""
152
- @read_state = :content
160
+ if @content_length and @content_length > 0
161
+ @read_state = :content
162
+ else
163
+ dispatch_response
164
+ @read_state = :base
165
+ end
153
166
  else
154
167
  @headers << ary.first
155
168
  if @headers.length == 1
@@ -1,141 +1,120 @@
1
- # $Id: line_and_text.rb 279 2006-11-18 15:40:25Z blackhedd $
1
+ # $Id: line_and_text.rb 322 2007-05-22 22:18:35Z blackhedd $
2
2
  #
3
- # Author:: blackhedd (gmail address: garbagecat10).
3
+ # Author:: Francis Cianfrocca (gmail: blackhedd)
4
+ # Homepage:: http://rubyeventmachine.com
4
5
  # Date:: 15 November 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
- # Gmail: garbagecat10
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 as published by
21
- # the Free Software Foundation; either version 2 of the License, or
22
- # (at your option) any later version.
23
- #
24
- # This program is distributed in the hope that it will be useful,
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
-
37
-
25
+ #
26
+ require File.dirname(__FILE__) + '/buftok'
38
27
 
39
28
  module EventMachine
40
- module Protocols
41
-
42
- class LineAndTextProtocol < Connection
43
- MaxLineLength = 16*1024
44
- MaxBinaryLength = 32*1024*1024
29
+ module Protocols
45
30
 
46
- def initialize *args
47
- super
48
- lbp_init_line_state
49
- end
50
- def receive_data data
51
- if @lbp_mode == :lines
52
- @lbp_data << data
53
- while i = @lbp_data.index("\n")
54
- # line-length test is provisional. Need to be tunable and do something
55
- # more intelligent than throwing something.
56
- if i > MaxLineLength
57
- receive_error("overlength line") if respond_to?(:receive_error)
58
- close_connection
59
- break # exit the while loop
60
- end
61
- line = @lbp_data.slice!(0..i).chomp
62
- receive_line line if respond_to?(:receive_line)
63
- end
64
- else
65
- if @lbp_binary_limit > 0
66
- wanted = @lbp_binary_limit - @lbp_binary_bytes_received
67
- chunk = nil
68
- if data.length > wanted
69
- chunk = data.slice!(0...wanted)
70
- else
71
- chunk = data
72
- data = ""
73
- end
74
- @lbp_binary_buffer[@lbp_binary_bytes_received...(@lbp_binary_bytes_received+chunk.length)] = chunk
75
- @lbp_binary_bytes_received += chunk.length
76
- if @lbp_binary_bytes_received == @lbp_binary_limit
77
- receive_binary_data(@lbp_binary_buffer) if respond_to?(:receive_binary_data)
78
- lbp_init_line_state
79
- end
80
- receive_data(data) if data.length > 0
81
- else
82
- receive_binary_data(data) if respond_to?(:receive_binary_data)
83
- data = ""
84
- end
85
- end
86
- end
31
+ class LineAndTextProtocol < Connection
32
+ MaxLineLength = 16*1024
33
+ MaxBinaryLength = 32*1024*1024
87
34
 
88
- def unbind
89
- if @lbp_mode == :binary and @lbp_binary_limit > 0
90
- if respond_to?(:receive_binary_data)
91
- receive_binary_data( @lbp_binary_buffer[0...@lbp_binary_bytes_received] )
92
- end
93
- end
94
- end
35
+ def initialize *args
36
+ super
37
+ lbp_init_line_state
38
+ end
39
+ def receive_data data
40
+ if @lbp_mode == :lines
41
+ begin
42
+ @lpb_buffer.extract(data).each { |line| receive_line(line) if respond_to?(:receive_line) }
43
+ rescue Exception
44
+ receive_error('overlength line') if respond_to?(:receive_error)
45
+ close_connection
46
+ return
47
+ end
48
+ else
49
+ if @lbp_binary_limit > 0
50
+ wanted = @lbp_binary_limit - @lbp_binary_bytes_received
51
+ chunk = nil
52
+ if data.length > wanted
53
+ chunk = data.slice!(0...wanted)
54
+ else
55
+ chunk = data
56
+ data = ""
57
+ end
58
+ @lbp_binary_buffer[@lbp_binary_bytes_received...(@lbp_binary_bytes_received+chunk.length)] = chunk
59
+ @lbp_binary_bytes_received += chunk.length
60
+ if @lbp_binary_bytes_received == @lbp_binary_limit
61
+ receive_binary_data(@lbp_binary_buffer) if respond_to?(:receive_binary_data)
62
+ lbp_init_line_state
63
+ end
64
+ receive_data(data) if data.length > 0
65
+ else
66
+ receive_binary_data(data) if respond_to?(:receive_binary_data)
67
+ data = ""
68
+ end
69
+ end
70
+ end
95
71
 
96
- # Set up to read the supplied number of binary bytes.
97
- # This recycles all the data currently waiting in the line buffer, if any.
98
- # If the limit is nil, then ALL subsequent data will be treated as binary
99
- # data and passed to the upstream protocol handler as we receive it.
100
- # If a limit is given, we'll hold the incoming binary data and not
101
- # pass it upstream until we've seen it all, or until there is an unbind
102
- # (in which case we'll pass up a partial).
103
- # Specifying nil for the limit (the default) means there is no limit.
104
- # Specifiyng zero for the limit will cause an immediate transition back to line mode.
105
- #
106
- def set_binary_mode size = nil
107
- if @lbp_mode == :lines
108
- if size == 0
109
- receive_binary_data("") if respond_to?(:receive_binary_data)
110
- # Do no more work here. Stay in line mode and keep consuming data.
111
- else
112
- @lbp_binary_limit = size.to_i # (nil will be stored as zero)
113
- if @lbp_binary_limit > 0
114
- raise "Overlength" if @lbp_binary_limit > MaxBinaryLength # arbitrary sanity check
115
- @lbp_binary_buffer = "\0" * @lbp_binary_limit
116
- @lbp_binary_bytes_received = 0
117
- end
72
+ def unbind
73
+ if @lbp_mode == :binary and @lbp_binary_limit > 0
74
+ if respond_to?(:receive_binary_data)
75
+ receive_binary_data( @lbp_binary_buffer[0...@lbp_binary_bytes_received] )
76
+ end
77
+ end
78
+ end
118
79
 
119
- @lbp_mode = :binary
120
- if @lbp_data.length > 0
121
- d,@lbp_data = @lbp_data,""
122
- receive_data d
123
- end
124
- end
125
- else
126
- raise "invalid operation"
127
- end
128
- end
80
+ # Set up to read the supplied number of binary bytes.
81
+ # This recycles all the data currently waiting in the line buffer, if any.
82
+ # If the limit is nil, then ALL subsequent data will be treated as binary
83
+ # data and passed to the upstream protocol handler as we receive it.
84
+ # If a limit is given, we'll hold the incoming binary data and not
85
+ # pass it upstream until we've seen it all, or until there is an unbind
86
+ # (in which case we'll pass up a partial).
87
+ # Specifying nil for the limit (the default) means there is no limit.
88
+ # Specifiyng zero for the limit will cause an immediate transition back to line mode.
89
+ #
90
+ def set_binary_mode size = nil
91
+ if @lbp_mode == :lines
92
+ if size == 0
93
+ receive_binary_data("") if respond_to?(:receive_binary_data)
94
+ # Do no more work here. Stay in line mode and keep consuming data.
95
+ else
96
+ @lbp_binary_limit = size.to_i # (nil will be stored as zero)
97
+ if @lbp_binary_limit > 0
98
+ raise "Overlength" if @lbp_binary_limit > MaxBinaryLength # arbitrary sanity check
99
+ @lbp_binary_buffer = "\0" * @lbp_binary_limit
100
+ @lbp_binary_bytes_received = 0
101
+ end
129
102
 
130
- #--
131
- # For internal use, establish protocol baseline for handling lines.
132
- def lbp_init_line_state
133
- @lbp_data = ""
134
- @lbp_mode = :lines
135
- end
136
- private :lbp_init_line_state
103
+ @lbp_mode = :binary
104
+ receive_data @lpb_buffer.flush
105
+ end
106
+ else
107
+ raise "invalid operation"
108
+ end
109
+ end
137
110
 
138
- end
111
+ #--
112
+ # For internal use, establish protocol baseline for handling lines.
113
+ def lbp_init_line_state
114
+ @lpb_buffer = BufferedTokenizer.new("\n", MaxLineLength)
115
+ @lbp_mode = :lines
116
+ end
117
+ private :lbp_init_line_state
139
118
  end
119
+ end
140
120
  end
141
-
@@ -1,37 +1,27 @@
1
- # $Id: tcptest.rb 218 2006-07-17 10:29:20Z blackhedd $
1
+ # $Id: tcptest.rb 322 2007-05-22 22:18:35Z blackhedd $
2
2
  #
3
- # Author:: blackhedd (gmail address: garbagecat10).
3
+ # Author:: Francis Cianfrocca (gmail: blackhedd)
4
+ # Homepage:: http://rubyeventmachine.com
4
5
  # Date:: 16 July 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
- # Gmail: garbagecat10
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 as published by
21
- # the Free Software Foundation; either version 2 of the License, or
22
- # (at your option) any later version.
23
- #
24
- # This program is distributed in the hope that it will be useful,
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
  #
24
+ #
35
25
  #
36
26
 
37
27