lib/netsoul/client.rb in netsoul-2.2.0 vs lib/netsoul/client.rb in netsoul-2.2.1

- old
+ new

@@ -4,11 +4,11 @@ module Netsoul class Client include Logging attr_reader :started SOCKET_READ_TIMEOUT = 12 * 60 - SOCKET_WRITE_TIMEOUT = 10 + SOCKET_WRITE_TIMEOUT = 1 * 60 def initialize(*args) opts = args.last.is_a?(Hash) ? args.last : {} @config = Config.new(opts) @started = false @@ -57,19 +57,27 @@ end def send(str) _, sock = IO.select(nil, [@socket], nil, SOCKET_WRITE_TIMEOUT) fail Netsoul::SocketError, 'Timeout or fail on write socket' if sock.nil? || sock.empty? - sock.first.puts str + s = sock.first + if s + s.puts str + s.flush + end log :info, "[send] #{str.chomp}" end def get sock, = IO.select([@socket], nil, nil, SOCKET_READ_TIMEOUT) fail Netsoul::SocketError, 'Timeout or fail on read socket' if sock.nil? || sock.empty? res = sock.first.gets - log :info, "[get ] #{res.chomp}" if res - res || '' + if res + log :info, "[get ] #{res.chomp}" + res + else + 'nothing' # Send some string and permit IO.select to thrown exception if something goes wrong. + end end def close @started = false @socket.close