Sha256: 6612f0855343878cf247a49ba43976a5a4dcfe556e0f7eb5a1dbec297f9ee50b
Contents?: true
Size: 1.53 KB
Versions: 3
Compression:
Stored size: 1.53 KB
Contents
require 'sanford-protocol/test/fake_socket' class SimpleClient def self.call_with_request(service_host, version, name, params) self.new(service_host).call_with_request(version, name, params) end def self.call_with_msg_body(service_host, *args) self.new(service_host).call_with_msg_body(*args) end def self.call_with_encoded_msg_body(service_host, *args) self.new(service_host).call_with_encoded_msg_body(*args) end def self.call_with(service_host, bytes) self.new(service_host).call(bytes) end def initialize(service_host, options = {}) @host, @port = service_host.ip, service_host.port @delay = options[:with_delay] end def call_with_request(*args) self.call_using_fake_socket(:with_request, *args) end def call_with_msg_body(*args) self.call_using_fake_socket(:with_msg_body, *args) end def call_with_encoded_msg_body(*args) self.call_using_fake_socket(:with_encoded_msg_body, *args) end def call_with_keep_alive socket = TCPSocket.new(@host, @port) ensure socket.close rescue false end def call(bytes) socket = TCPSocket.new(@host, @port) socket.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, true) connection = Sanford::Protocol::Connection.new(socket) sleep(@delay) if @delay socket.send(bytes, 0) Sanford::Protocol::Response.parse(connection.read) ensure socket.close rescue false end protected def call_using_fake_socket(method, *args) self.call(Sanford::Protocol::Test::FakeSocket.send(method, *args).in) end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
sanford-0.6.2 | test/support/simple_client.rb |
sanford-0.6.1 | test/support/simple_client.rb |
sanford-0.6.0 | test/support/simple_client.rb |