end
def read_connection(fd)
- buffer = ''
- begin
- buffer << fd.read_nonblock(4096) while true
- rescue Errno::EAGAIN, EOFError
- @buffers[fd] << buffer
- end
+ @buffers[fd] << fd.readpartial(1048576)
frame = slice_frame!(@buffers[fd])
if frame
@worker_queue.push [:frame, fd, frame]
def read_signals
# clear the signal pipe
- begin
- @signal_pipes[0].read_nonblock(1024) while true
- rescue Errno::EAGAIN
- end
+ # note that since read_nonblock is broken in jruby,
+ # we can only read up to a set number of signals at once
+ sigstr = @signal_pipes[0].readpartial(1024)
# now read the signals
begin
- loop do
+ sigstr.length.times do
signal, obj = @signal_queue.pop(true)
case signal
when :connection
end
rescue ThreadError
# out of signals
+ # note that in a perfect world this would never happen, since we're
+ # only reading the number of signals pushed on the pipe, but given the lack
+ # of locks, in theory we could clear the pipe/queue while a new signal is being
+ # placed on the pipe, at which point our next read_signals would hit this error
end
end
end
end
- def read(sz, nonblock=false)
+ def read(sz, partial=false)
begin
- if nonblock
- data = @handle.read_nonblock(sz)
+ if partial
+ data = @handle.readpartial(sz)
else
data = @handle.read(sz)
end
data
end
- def read_nonblock(sz)
+ def readpartial(sz)
read(sz, true)
end