lib/bertrpc/action.rb in bertrpc-0.4.2 vs lib/bertrpc/action.rb in bertrpc-1.0.0
- old
+ new
@@ -22,11 +22,11 @@
sock.write([bert.length].pack("N"))
sock.write(bert)
end
def transaction(bert_request)
- sock = connect_to(@svc.host, @svc.port, @svc.timeout)
+ sock = TCPSocket.new(@svc.host, @svc.port)
if @req.options
if @req.options[:cache] && @req.options[:cache][0] == :validation
token = @req.options[:cache][1]
info_bert = encode_ruby_request([:info, :cache, [:validation, token]])
@@ -42,33 +42,8 @@
raise ProtocolError.new(ProtocolError::NO_DATA) unless bert_response
sock.close
bert_response
rescue Errno::ECONNREFUSED
raise ConnectionError.new("Unable to connect to #{@svc.host}:#{@svc.port}")
- rescue Errno::EAGAIN
- raise ReadTimeoutError.new(@svc.host, @svc.port, @svc.timeout)
end
-
- # Creates a socket object which does speedy, non-blocking reads
- # and can perform reliable read timeouts.
- #
- # Raises Timeout::Error on timeout.
- #
- # +host+ String address of the target TCP server
- # +port+ Integer port of the target TCP server
- # +timeout+ Optional Integer (in seconds) of the read timeout
- def connect_to(host, port, timeout = nil)
- sock = TCPSocket.new(host, port)
- sock.setsockopt Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1
-
- if timeout
- secs = Integer(timeout)
- usecs = Integer((timeout - secs) * 1_000_000)
- optval = [secs, usecs].pack("l_2")
- sock.setsockopt Socket::SOL_SOCKET, Socket::SO_RCVTIMEO, optval
- sock.setsockopt Socket::SOL_SOCKET, Socket::SO_SNDTIMEO, optval
- end
-
- sock
- end
end
-end
+end
\ No newline at end of file