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