Skip to content
This repository has been archived by the owner on Apr 16, 2023. It is now read-only.

Commit

Permalink
Code review.
Browse files Browse the repository at this point in the history
  • Loading branch information
christiankakesa committed Jan 16, 2016
1 parent d04479d commit 67e16ba
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/netsoul/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,24 @@ def disconnect
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
Expand Down

0 comments on commit 67e16ba

Please sign in to comment.