Skip to content

Commit

Permalink
Assume F_GETFL is available
Browse files Browse the repository at this point in the history
  • Loading branch information
sodabrew committed Oct 9, 2015
1 parent 93b9833 commit e52b1a3
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions code/protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,13 @@ def set_protocol_messages(messages)
end

def set_nonblocking(sock)
flag = File::NONBLOCK
if defined?(Fcntl::F_GETFL)
flag |= sock.fcntl(Fcntl::F_GETFL)
end
sock.fcntl(Fcntl::F_SETFL, flag)
flags = sock.fcntl(Fcntl::F_GETFL) | Fcntl::O_NONBLOCK
sock.fcntl(Fcntl::F_SETFL, flags)
end

def reset_nonblocking(sock)
# Linux Doesn't inherit and BSD does... recomended behavior is to set again
flag = 0xffffffff ^ File::NONBLOCK
if defined?(Fcntl::F_GETFL)
flag &= sock.fcntl(Fcntl::F_GETFL)
end
sock.fcntl(Fcntl::F_SETFL, flag)
flags = sock.fcntl(Fcntl::F_GETFL) ^ Fcntl::O_NONBLOCK
sock.fcntl(Fcntl::F_SETFL, flags)
end

def read_packet(sock)
Expand Down

0 comments on commit e52b1a3

Please sign in to comment.