Class: HTTP::Timeout::Global

Inherits:
PerOperation show all
Defined in:
lib/http/timeout/global.rb

Constant Summary

Constants inherited from PerOperation

PerOperation::CONNECT_TIMEOUT, PerOperation::READ_TIMEOUT, PerOperation::WRITE_TIMEOUT

Instance Attribute Summary collapse

Attributes inherited from PerOperation

#connect_timeout, #read_timeout, #write_timeout

Attributes inherited from Null

#options, #socket

Instance Method Summary collapse

Methods inherited from Null

#start_tls

Constructor Details

#initialize(*args) ⇒ Global


10
11
12
13
14
15
# File 'lib/http/timeout/global.rb', line 10

def initialize(*args)
  super

  @time_left = connect_timeout + read_timeout + write_timeout
  @total_timeout = time_left
end

Instance Attribute Details

#time_leftObject (readonly)

Returns the value of attribute time_left


8
9
10
# File 'lib/http/timeout/global.rb', line 8

def time_left
  @time_left
end

#total_timeoutObject (readonly)

Returns the value of attribute total_timeout


8
9
10
# File 'lib/http/timeout/global.rb', line 8

def total_timeout
  @total_timeout
end

Instance Method Details

#connect(socket_class, host, port) ⇒ Object


17
18
19
20
21
22
23
24
# File 'lib/http/timeout/global.rb', line 17

def connect(socket_class, host, port)
  reset_timer
  ::Timeout.timeout(time_left, TimeoutError) do
    @socket = socket_class.open(host, port)
  end

  log_time
end

#connect_sslObject


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/http/timeout/global.rb', line 26

def connect_ssl
  reset_timer

  begin
    socket.connect_nonblock
  rescue IO::WaitReadable
    IO.select([socket], nil, nil, time_left)
    log_time
    retry
  rescue IO::WaitWritable
    IO.select(nil, [socket], nil, time_left)
    log_time
    retry
  end
end

#readpartial(size) ⇒ Object

Read from the socket


43
44
45
# File 'lib/http/timeout/global.rb', line 43

def readpartial(size)
  perform_io { read_nonblock(size) }
end

#write(data) ⇒ Object Also known as: <<

Write to the socket


48
49
50
# File 'lib/http/timeout/global.rb', line 48

def write(data)
  perform_io { write_nonblock(data) }
end