Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tcp_timeout

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tcp_timeout

  • 0.1.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

TCPTimeout

A wrapper around Ruby Sockets providing timeouts for connect, write, and read operations using Socket#*_nonblock methods and IO.select instead of Timeout.timeout.

Usage

gem install tcp_timeout

Pass one or more of :connect_timeout, :write_timeout, and :read_timeout as options to TCPTimeout::TCPSocket.new. If a timeout is omitted or nil, that operation will behave as a normal Socket would. On timeout, a TCPTimeout::SocketTimeout (subclass of SocketError) will be raised.

When calling #read with a byte length it is possible for it to read some data before timing out. If you need to avoid losing this data you can pass a buffer string which will receive the data even after a timeout.

Other options:

  • :family - set the address family for the connection, e.g. :INET or :INET6
  • :local_host and :local_port - the host and port to bind to

TCPTimeout::TCPSocket supports only a subset of IO methods, including:

close closed? read read_nonblock readbyte readpartial write write_nonblock

Example:

begin
  sock = TCPTimeout::TCPSocket.new(host, port, connect_timeout: 10, write_timeout: 9)
  sock.write('data')
  sock.close
rescue TCPTimeout::SocketTimeout
  puts "Operation timed out!"
end

FAQs

Package last updated on 15 May 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc