Skip to content
This repository has been archived by the owner on Dec 7, 2018. It is now read-only.

Commit

Permalink
Use Celluloid::IO.wait_readable for all servers/sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcieri committed Apr 4, 2013
1 parent 015fa7d commit c28e5a2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 25 deletions.
12 changes: 3 additions & 9 deletions lib/celluloid/io/tcp_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,12 @@ def initialize(hostname, port)
end

def accept
actor = Thread.current[:celluloid_actor]

if evented?
Celluloid.current_actor.wait_readable @server
accept_nonblock
else
Celluloid::IO::TCPSocket.from_ruby_socket @server.accept
end
Celluloid::IO.wait_readable(@server)
accept_nonblock
end

def accept_nonblock
Celluloid::IO::TCPSocket.from_ruby_socket @server.accept_nonblock
Celluloid::IO::TCPSocket.new(@server.accept_nonblock)
end

def to_io
Expand Down
8 changes: 1 addition & 7 deletions lib/celluloid/io/udp_socket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@ def evented?
end

# Wait until the socket is readable
def wait_readable
if evented?
Celluloid.current_actor.wait_readable(@socket)
else
Kernel.select([@socket])
end
end
def wait_readable; Celluloid::IO.wait_readable(self); end

# Receives up to maxlen bytes from socket. flags is zero or more of the
# MSG_ options. The first element of the results, mesg, is the data
Expand Down
12 changes: 3 additions & 9 deletions lib/celluloid/io/unix_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,12 @@ def initialize(socket_path)
end

def accept
actor = Thread.current[:celluloid_actor]

if evented?
Celluloid.current_actor.wait_readable @server
accept_nonblock
else
Celluloid::IO::UNIXSocket.from_ruby_socket @server.accept
end
Celluloid::IO.wait_readable(@server)
accept_nonblock
end

def accept_nonblock
Celluloid::IO::UNIXSocket.from_ruby_socket @server.accept_nonblock
Celluloid::IO::UNIXSocket.new(@server.accept_nonblock)
end

def to_io
Expand Down

0 comments on commit c28e5a2

Please sign in to comment.