Skip to content

Commit

Permalink
Always use the same array for select
Browse files Browse the repository at this point in the history
  • Loading branch information
composerinteralia committed Apr 18, 2024
1 parent a274b6e commit 262a1ff
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/nocturne/socket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Nocturne
class Socket
def initialize(options)
@sock = ::Socket.new(::Socket::AF_INET, ::Socket::SOCK_STREAM)
@select_sock = [@sock]
@sock.connect ::Socket.pack_sockaddr_in(options[:port] || 3306, options[:host] || "localhost")
end

Expand All @@ -14,7 +15,7 @@ def recv(buffer)
result = @sock.recv_nonblock(MAX_BYTES, 0, buffer, exception: false)

if :wait_readable == result
IO.select([@sock])
IO.select(@select_sock)
else
return result
end
Expand All @@ -26,7 +27,7 @@ def sendmsg(data)
result = @sock.sendmsg_nonblock(data, exception: false)

if :wait_writable == result
IO.select(nil, [@sock])
IO.select(nil, @select_sock)
else
return result
end
Expand Down

0 comments on commit 262a1ff

Please sign in to comment.