Sha256: ff7c2b3c69f80651314fe6974fc33608c9cb87c57512aef8d4c96bd0f34d147d

Contents?: true

Size: 1.22 KB

Versions: 10

Compression:

Stored size: 1.22 KB

Contents

# Copyright (C) 2013, Eric Wong <normalperson@yhbt.net> and all contributors
# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
require 'raindrops'

# 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
module Yahns::ClientExpireTCPI # :nodoc:
  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
# FreeBSD has "struct tcp_info", too, but does not support all the fields
# Linux does as of FreeBSD 9 (haven't checked FreeBSD 10, yet).
end if RUBY_PLATFORM =~ /linux/

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
yahns-1.6.0 lib/yahns/client_expire_tcpi.rb
yahns-1.5.0 lib/yahns/client_expire_tcpi.rb
yahns-1.4.0 lib/yahns/client_expire_tcpi.rb
yahns-1.3.1 lib/yahns/client_expire_tcpi.rb
yahns-1.3.0 lib/yahns/client_expire_tcpi.rb
yahns-1.2.0 lib/yahns/client_expire_tcpi.rb
yahns-1.1.0 lib/yahns/client_expire_tcpi.rb
yahns-1.0.0 lib/yahns/client_expire_tcpi.rb
yahns-0.0.3 lib/yahns/client_expire_tcpi.rb
yahns-0.0.2 lib/yahns/client_expire_tcpi.rb