Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

call readpartial and peeraddr on @socket if available to support puma's ... #36

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/tubesock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ def listen

def close
@close_handlers.each(&:call)
@socket.close unless @socket.closed?
@socket.close unless closed?
end

def closed?
@socket.closed?
return @socket.closed? if @socket.respond_to?(:closed)
return @socket.to_io.closed? if @socket.respond_to?(:to_io) and @socket.to_io.respond_to?(:closed?)
true
end

def keepalive
Expand All @@ -94,7 +96,12 @@ def keepalive
def each_frame
framebuffer = WebSocket::Frame::Incoming::Server.new(version: @version)
while IO.select([@socket])
data, addrinfo = @socket.recvfrom(2000)
if(@socket.respond_to?(:readpartial) && @socket.respond_to?(:peeraddr))
data, addrinfo = @socket.readpartial(2000), @socket.peeraddr
else
data, addrinfo = @socket.recvfrom(2000)
end

break if data.empty?
framebuffer << data
while frame = framebuffer.next
Expand All @@ -106,6 +113,7 @@ def each_frame
end
end
end

rescue Errno::EHOSTUNREACH, Errno::ETIMEDOUT, Errno::ECONNRESET, IOError, Errno::EBADF
nil # client disconnected or timed out
end
Expand Down