diff --git a/code/protocol.rb b/code/protocol.rb index 28a116c..ae24ec3 100644 --- a/code/protocol.rb +++ b/code/protocol.rb @@ -91,14 +91,15 @@ def do_write(client, buff) defined?(nwritten) ? nwritten : 0 end - def do_read(client, numr = 32768) - client.sysread(numr) - rescue Errno::EAGAIN, Errno::EINTR # Ruby threading can cause an alarm/timer interrupt on a syscall - sleep 0.001 # A tiny pause to prevent consuming all CPU - retry + def do_read(client, size) + out = "" + while out.bytesize < size + remain = size - out.bytesize + out << client.readpartial(remain) + end + out rescue EOFError - $log.debug("Got an EOF from socket read") - return nil + out rescue Errno::ECONNRESET,Errno::EPIPE,Errno::EINVAL,Errno::EBADF raise "Got an #{$!} from socket read" end diff --git a/code/queue.rb b/code/queue.rb index bee9604..c906ce9 100644 --- a/code/queue.rb +++ b/code/queue.rb @@ -1071,7 +1071,7 @@ def handle_status_read(msg) child_pid = msg['child_pid'] $log.debug("#{child_pid}: Reading status from child") - data = do_read(child_io, 4096) + data = child_io.readpartial(4096) rescue nil return false unless data child_msgs = data.split("\n")