Class: HTTP::Timeout::PerOperation

### Home Classes Methods

### In Files

- lib/http/timeout/per_operation.rb

### Parent

HTTP::Timeout::Null

### Methods

- ::new
- #connect
- #connect_ssl
- #readpartial
- #write

### Class/Module Index

Quicksearch

- HTTP
- HTTP::Cache
- HTTP::Cache::Headers
- HTTP::Cache::NullCache
- HTTP::Cache::NullLogger
- HTTP::CacheError
- HTTP::Chainable
- HTTP::Client
- HTTP::Connection
- HTTP::Error
- HTTP::Headers
- HTTP::Headers::Mixin
- HTTP::InvalidHeaderNameError
- HTTP::MimeType
- HTTP::MimeType::Adapter
- HTTP::MimeType::JSON
- HTTP::Options
- HTTP::Redirector
- HTTP::Redirector::EndlessRedirectError
- HTTP::Redirector::TooManyRedirectsError
- HTTP::Request
- HTTP::Request::Caching
- HTTP::Request::UnsupportedMethodError
- HTTP::Request::UnsupportedSchemeError
- HTTP::Request::Writer
- HTTP::RequestError
- HTTP::Response
- HTTP::Response::Body
- HTTP::Response::Caching
- HTTP::Response::IoBody
- HTTP::Response::Parser
- HTTP::Response::Status
- HTTP::Response::StringBody
- HTTP::ResponseError
- HTTP::StateError
- HTTP::Timeout
- HTTP::Timeout::Global
- HTTP::Timeout::Null
- HTTP::Timeout::PerOperation
- HTTP::TimeoutError
- HTTP::URI
- Object

No matching classes.

# HTTP::Timeout::PerOperation

### Constants

CONNECT_TIMEOUT
READ_TIMEOUT
WRITE_TIMEOUT

### Attributes

connect_timeout[R]
read_timeout[R]
write_timeout[R]

### Public Class Methods

new(*args) click to toggle source

    # File lib/http/timeout/per_operation.rb, line 10
    def initialize(*args)
      super

      @read_timeout = options.fetch(:read_timeout, READ_TIMEOUT)
      @write_timeout = options.fetch(:write_timeout, WRITE_TIMEOUT)
      @connect_timeout = options.fetch(:connect_timeout, CONNECT_TIMEOUT)
    end

### Public Instance Methods

connect(socket_class, host, port) click to toggle source

    # File lib/http/timeout/per_operation.rb, line 18
    def connect(socket_class, host, port)
      ::Timeout.timeout(connect_timeout, TimeoutError) do
        @socket = socket_class.open(host, port)
      end
    end

connect_ssl() click to toggle source

    # File lib/http/timeout/per_operation.rb, line 24
    def connect_ssl
      socket.connect_nonblock
    rescue IO::WaitReadable
      if IO.select([socket], nil, nil, connect_timeout)
        retry
      else
        raise TimeoutError, "Connection timed out after #{connect_timeout} seconds"
      end
    rescue IO::WaitWritable
      if IO.select(nil, [socket], nil, connect_timeout)
        retry
      else
        raise TimeoutError, "Connection timed out after #{connect_timeout} seconds"
      end
    end

readpartial(size) click to toggle source

Read data from the socket

    # File lib/http/timeout/per_operation.rb, line 41
    def readpartial(size)
      socket.read_nonblock(size)
    rescue IO::WaitReadable
      if IO.select([socket], nil, nil, read_timeout)
        retry
      else
        raise TimeoutError, "Read timed out after #{read_timeout} seconds"
      end
    end

write(data) click to toggle source

Write data to the socket

    # File lib/http/timeout/per_operation.rb, line 52
    def write(data)
      socket.write_nonblock(data)
    rescue IO::WaitWritable
      if IO.select(nil, [socket], nil, write_timeout)
        retry
      else
        raise TimeoutError, "Read timed out after #{write_timeout} seconds"
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.