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.
- #protocol ⇒ Object
- #sync ⇒ Object
-
#sync=(value) ⇒ Object
Best effort to set *_NODELAY if it makes sense.
- #type ⇒ Object
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 |
#protocol ⇒ Object
72 73 74 |
# File 'lib/async/io/socket.rb', line 72 def protocol self.local_address.protocol end |
#sync ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/async/io/socket.rb', line 59 def sync case self.protocol when Socket::IPPROTO_TCP self.getsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY).bool else true end && super end |
#sync=(value) ⇒ Object
Best effort to set *_NODELAY if it makes sense. Swallows errors where possible.
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/async/io/socket.rb', line 46 def sync=(value) super case self.protocol when 0, Socket::IPPROTO_TCP self.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, value ? 1 : 0) else warn "Unsure how to sync=#{value} for #{self.protocol}!" end rescue Errno::EINVAL # On Darwin, sometimes occurs when the connection is not yet fully formed. Empirically, TCP_NODELAY is enabled despite this result. end |
#type ⇒ Object
68 69 70 |
# File 'lib/async/io/socket.rb', line 68 def type self.local_address.socktype end |