Class: H2::Client::TCPSocket
- Inherits:
-
Socket
- Object
- Socket
- H2::Client::TCPSocket
- Defined in:
- lib/h2/client/tcp_socket.rb
Constant Summary collapse
- DEFAULT_TIMEOUT =
10
Instance Attribute Summary collapse
-
#selector ⇒ Object
readonly
ON_LINUX = !!(RUBY_PLATFORM =~ /linux/).
Instance Method Summary collapse
-
#initialize(addr, port, timeout = DEFAULT_TIMEOUT) ⇒ TCPSocket
constructor
A new instance of TCPSocket.
Constructor Details
#initialize(addr, port, timeout = DEFAULT_TIMEOUT) ⇒ TCPSocket
Returns a new instance of TCPSocket.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/h2/client/tcp_socket.rb', line 12 def initialize addr, port, timeout = DEFAULT_TIMEOUT # resolve name & pack addr family, addr = Socket.getaddrinfo(addr, port, nil, :STREAM, nil, AI_ALL).first.values_at(0,3) sockaddr = Socket.sockaddr_in port, addr super family, SOCK_STREAM # allow send before ack setsockopt IPPROTO_TCP, TCP_NODELAY, 1 # cork on linux # setsockopt IPPROTO_TCP, TCP_CORK, 1 if ON_LINUX if connect_nonblock(sockaddr, exception: false) == :wait_writable if IO.select nil, [self], nil, timeout begin connect_nonblock sockaddr rescue Errno::EISCONN rescue close raise end else close raise Errno::ETIMEDOUT end end end |
Instance Attribute Details
#selector ⇒ Object (readonly)
ON_LINUX = !!(RUBY_PLATFORM =~ /linux/)
10 11 12 |
# File 'lib/h2/client/tcp_socket.rb', line 10 def selector @selector end |