Module: Yahns::ClientExpireTCPI

Defined in:
lib/yahns/client_expire_tcpi.rb

Overview

included in Yahns::HttpClient

this provides the ability to expire idle clients once we hit a soft limit on idle clients

we absolutely DO NOT issue IO#close in here, only BasicSocket#shutdown

Instance Method Summary collapse

Instance Method Details

#yahns_expire(timeout) ⇒ Object



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
# File 'lib/yahns/client_expire_tcpi.rb', line 13

def yahns_expire(timeout) # rarely called
  return 0 if closed?

  info = Raindrops::TCP_Info.new(self)
  return 0 if info.state != 1 # TCP_ESTABLISHED == 1

  # Linux struct tcp_info timers are in milliseconds
  timeout *= 1000

  send_timedout = !!(info.last_data_sent > timeout)

  # tcpi_last_data_recv is not valid unless tcpi_ato (ACK timeout) is set
  if 0 == info.ato
    sd = send_timedout && (info.last_ack_recv > timeout)
  else
    sd = send_timedout && (info.last_data_recv > timeout)
  end
  if sd
    shutdown
    1
  else
    0
  end
# shutdown may race with the shutdown in http_response_done
rescue
  0
end