Sha256: 67654bf52b5db68c560c3af814e9744a19c9e59c46c3c182ad7562f7b478c3e7

Contents?: true

Size: 707 Bytes

Versions: 7

Compression:

Stored size: 707 Bytes

Contents

require 'socket'

require 'sanford-protocol'

module Bench

  class Client

    def initialize(host, port)
      @host, @port = [ host, port ]
    end

    def call(version, name, params)
      socket = TCPSocket.open(@host, @port)
      socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, true) # TODO - explain
      connection = Sanford::Protocol::Connection.new(socket)
      request = Sanford::Protocol::Request.new(version, name, params)
      connection.write(request.to_hash)
      if IO.select([ socket ], nil, nil, 10)
        Sanford::Protocol::Response.parse(connection.read)
      else
        raise "Timed out!"
      end
    ensure
      socket.close rescue false
    end

  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sanford-0.6.2 bench/client.rb
sanford-0.6.1 bench/client.rb
sanford-0.6.0 bench/client.rb
sanford-0.4.0 bench/client.rb
sanford-0.3.0 bench/client.rb
sanford-0.2.0 bench/client.rb
sanford-0.1.0 bench/client.rb