-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
8 changed files
with
75 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'socket' | ||
|
||
class IO | ||
def connected? | ||
!closed? | ||
end | ||
end | ||
|
||
class Socket | ||
def connected? | ||
# Is it likely that the socket is still connected? | ||
# May return false positive, but won't return false negative. | ||
return false unless super | ||
|
||
# If we can wait for the socket to become readable, we know that the socket may still be open. | ||
result = to_io.recv_nonblock(1, MSG_PEEK, exception: false) | ||
|
||
# No data was available - newer Ruby can return nil instead of empty string: | ||
return false if result.nil? | ||
|
||
# Either there was some data available, or we can wait to see if there is data avaialble. | ||
return !result.empty? || result == :wait_readable | ||
rescue Errno::ECONNRESET | ||
# This might be thrown by recv_nonblock. | ||
return false | ||
end | ||
end |
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
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require 'io/endpoint' | ||
|
||
describe IO::Endpoint do | ||
with ".file_descriptor_limit" do | ||
it "has a file descriptor limit" do | ||
expect(IO::Endpoint.file_descriptor_limit).to be_a Integer | ||
end | ||
end | ||
end |
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