Sha256: 9b5c4a848d90f3bd3e4c37b57004c90c6ef4ccbd79e4a22dce4617816389be53

Contents?: true

Size: 955 Bytes

Versions: 15

Compression:

Stored size: 955 Bytes

Contents

require 'socket'

require 'sanford-protocol'

module Bench

  class Client

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

    # TCP_NODELAY is set to disable buffering. In the case of Sanford
    # communication, we have all the information we need to send up front and
    # are closing the connection, so it doesn't need to buffer.
    # See http://linux.die.net/man/7/tcp

    def call(name, params)
      socket = TCPSocket.open(@host, @port)
      socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, true)
      connection = Sanford::Protocol::Connection.new(socket)
      request = Sanford::Protocol::Request.new(name, params)
      connection.write(request.to_hash)
      connection.close_write
      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

15 entries across 15 versions & 1 rubygems

Version Path
sanford-0.19.1 bench/client.rb
sanford-0.19.0 bench/client.rb
sanford-0.18.2 bench/client.rb
sanford-0.18.1 bench/client.rb
sanford-0.18.0 bench/client.rb
sanford-0.17.0 bench/client.rb
sanford-0.16.1 bench/client.rb
sanford-0.16.0 bench/client.rb
sanford-0.15.1 bench/client.rb
sanford-0.15.0 bench/client.rb
sanford-0.14.0 bench/client.rb
sanford-0.13.0 bench/client.rb
sanford-0.12.0 bench/client.rb
sanford-0.11.1 bench/client.rb
sanford-0.11.0 bench/client.rb