def receive(opts={})
timeout = opts.fetch(:timeout, 40).to_i
wait_for_null = opts.fetch(:wait_for_null, true)
response = ""
res = select([@sock], nil, nil, timeout)
if (res == nil)
raise "Timeout waiting for reader response." if @raise_errors
end
if (wait_for_null)
begin
timeout(timeout) {
response = @sock.gets("\0")
}
rescue Timeout::Error
raise "Timeout waiting for reader response." if @raise_errors
end
response.strip!
if response.include? "Error"
raise response if @raise_errors
end
if (response.include? "Goodbye!")
close(false)
end
return response
else
return @sock.recv(1024)
end
end