summaryrefslogtreecommitdiff
path: root/lib/net/protocol.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/net/protocol.rb')
-rw-r--r--lib/net/protocol.rb36
1 files changed, 21 insertions, 15 deletions
diff --git a/lib/net/protocol.rb b/lib/net/protocol.rb
index c676854b67..8c81298c0e 100644
--- a/lib/net/protocol.rb
+++ b/lib/net/protocol.rb
@@ -26,7 +26,7 @@ require 'io/wait'
module Net # :nodoc:
class Protocol #:nodoc: internal use only
- VERSION = "0.1.3"
+ VERSION = "0.2.2"
private
def Protocol.protocol_param(name, val)
@@ -54,9 +54,20 @@ module Net # :nodoc:
s.connect
end
end
+
+ tcp_socket_parameters = TCPSocket.instance_method(:initialize).parameters
+ TCP_SOCKET_NEW_HAS_OPEN_TIMEOUT = if tcp_socket_parameters != [[:rest]]
+ tcp_socket_parameters.include?([:key, :open_timeout])
+ else
+ # Use Socket.tcp to find out since there is no parameters information for TCPSocket#initialize
+ # See discussion in https://github.com/ruby/net-http/pull/224
+ Socket.method(:tcp).parameters.include?([:key, :open_timeout])
+ end
+ private_constant :TCP_SOCKET_NEW_HAS_OPEN_TIMEOUT
end
+ # :stopdoc:
class ProtocolError < StandardError; end
class ProtoSyntaxError < ProtocolError; end
class ProtoFatalError < ProtocolError; end
@@ -66,6 +77,7 @@ module Net # :nodoc:
class ProtoCommandError < ProtocolError; end
class ProtoRetriableError < ProtocolError; end
ProtocRetryError = ProtoRetriableError
+ # :startdoc:
##
# OpenTimeout, a subclass of Timeout::Error, is raised if a connection cannot
@@ -78,6 +90,7 @@ module Net # :nodoc:
# response cannot be read within the read_timeout.
class ReadTimeout < Timeout::Error
+ # :stopdoc:
def initialize(io = nil)
@io = io
end
@@ -97,6 +110,7 @@ module Net # :nodoc:
# response cannot be written within the write_timeout. Not raised on Windows.
class WriteTimeout < Timeout::Error
+ # :stopdoc:
def initialize(io = nil)
@io = io
end
@@ -120,6 +134,7 @@ module Net # :nodoc:
@continue_timeout = continue_timeout
@debug_output = debug_output
@rbuf = ''.b
+ @rbuf_empty = true
@rbuf_offset = 0
end
@@ -156,7 +171,7 @@ module Net # :nodoc:
read_bytes = 0
begin
while read_bytes + rbuf_size < len
- if s = rbuf_consume_all_shareable!
+ if s = rbuf_consume_all
read_bytes += s.bytesize
dest << s
end
@@ -177,7 +192,7 @@ module Net # :nodoc:
read_bytes = 0
begin
while true
- if s = rbuf_consume_all_shareable!
+ if s = rbuf_consume_all
read_bytes += s.bytesize
dest << s
end
@@ -249,18 +264,8 @@ module Net # :nodoc:
@rbuf.bytesize - @rbuf_offset
end
- # Warning: this method may share the buffer to avoid
- # copying. The caller must no longer use the returned
- # string once rbuf_fill has been called again
- def rbuf_consume_all_shareable!
- @rbuf_empty = true
- buf = if @rbuf_offset == 0
- @rbuf
- else
- @rbuf.byteslice(@rbuf_offset..-1)
- end
- @rbuf_offset = @rbuf.bytesize
- buf
+ def rbuf_consume_all
+ rbuf_consume if rbuf_size > 0
end
def rbuf_consume(len = nil)
@@ -493,6 +498,7 @@ module Net # :nodoc:
# The writer adapter class
#
class WriteAdapter
+ # :stopdoc:
def initialize(writer)
@writer = writer
end