Module: Async::IO::Peer
- Included in:
- BasicSocket, SSLSocket, TCPSocket, UNIXSocket
- Defined in:
- lib/async/io/socket.rb
Instance Method Summary collapse
-
#connected? ⇒ Boolean
Is it likely that the socket is still connected? May return false positive, but won’t return false negative.
Instance Method Details
#connected? ⇒ Boolean
Is it likely that the socket is still connected? May return false positive, but won’t return false negative.
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/async/io/socket.rb', line 31 def connected? return false if @io.closed? # 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, Socket::MSG_PEEK, exception: false) # 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 |