This repository has been archived by the owner on Jun 25, 2018. It is now read-only.
forked from oldmoe/neverblock
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
unknown
committed
Jul 27, 2009
1 parent
e2b0e38
commit 553fc4a
Showing
3 changed files
with
66 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
require 'rubygems' | ||
require File.expand_path(File.dirname(__FILE__) + "/fix_sockets") | ||
|
||
class Socket | ||
|
||
class Socket | ||
|
||
alias_method :connect_blocking, :connect | ||
|
||
def connect_neverblock(server_sockaddr) | ||
begin | ||
connect_nonblock(server_sockaddr) | ||
rescue Errno::EINPROGRESS, Errno::EINTR, Errno::EALREADY, Errno::EWOULDBLOCK | ||
attach_to_reactor(:write) | ||
retry | ||
rescue Errno::EISCONN | ||
end | ||
end | ||
|
||
def connect(server_sockaddr) | ||
if Fiber.current[:neverblock] | ||
connect_neverblock(server_sockaddr) | ||
else | ||
connect_blocking(server_sockaddr) | ||
end | ||
end | ||
|
||
def connect_neverblock(server_sockaddr) | ||
begin | ||
connect_nonblock(server_sockaddr) | ||
rescue Errno::EINPROGRESS, Errno::EINTR, Errno::EALREADY, Errno::EWOULDBLOCK | ||
attach_to_reactor(:write) | ||
retry | ||
rescue Errno::EISCONN | ||
end | ||
end | ||
|
||
def connect(server_sockaddr) | ||
if Fiber.current[:neverblock] | ||
connect_neverblock(server_sockaddr) | ||
else | ||
connect_blocking(server_sockaddr) | ||
end | ||
end | ||
end |