Module: Raindrops::Aggregate::LastDataRecv

Defined in:
lib/raindrops/aggregate/last_data_recv.rb

Overview

  • Kgio::TCPServer#kgio_tryaccept

Constant Summary collapse

TCP_Info =

:stopdoc:

Raindrops::TCP_Info
@@default_aggregate =
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#raindrops_aggregateObject

The integer value of last_data_recv is sent to this object. This is usually a duck type compatible with the Aggregate class, but can be anything that accepts the *<<* method.



23
24
25
# File 'lib/raindrops/aggregate/last_data_recv.rb', line 23

def raindrops_aggregate
  @raindrops_aggregate
end

Class Method Details

.cornify!Object

automatically extends any TCPServer objects used by Unicorn



39
40
41
42
43
# File 'lib/raindrops/aggregate/last_data_recv.rb', line 39

def self.cornify!
  Unicorn::HttpServer::LISTENERS.each do |sock|
    sock.extend(self) if TCPServer === sock
  end
end

.default_aggregateObject

By default, this is a Raindrops::Aggregate::PMQ object It may be anything that responds to *<<*



29
30
31
# File 'lib/raindrops/aggregate/last_data_recv.rb', line 29

def self.default_aggregate
  @@default_aggregate ||= Raindrops::Aggregate::PMQ.new
end

.default_aggregate=(agg) ⇒ Object

Assign any object that responds to *<<*



34
35
36
# File 'lib/raindrops/aggregate/last_data_recv.rb', line 34

def self.default_aggregate=(agg)
  @@default_aggregate = agg
end

.extended(obj) ⇒ Object

each extended object needs to have TCP_DEFER_ACCEPT enabled for accuracy.



47
48
49
50
51
# File 'lib/raindrops/aggregate/last_data_recv.rb', line 47

def self.extended(obj)
  obj.raindrops_aggregate = default_aggregate
  # obj.setsockopt Socket::SOL_TCP, tcp_defer_accept = 9, seconds = 60
  obj.setsockopt Socket::SOL_TCP, 9, 60
end

Instance Method Details

#acceptObject



63
64
65
# File 'lib/raindrops/aggregate/last_data_recv.rb', line 63

def accept
  count! super
end

#accept_nonblockObject



67
68
69
# File 'lib/raindrops/aggregate/last_data_recv.rb', line 67

def accept_nonblock
  count! super
end

#count!(io) ⇒ Object

The last_data_recv member of Raindrops::TCP_Info can be used to infer the time a client spent in the listen queue before it was accepted.

We require TCP_DEFER_ACCEPT on the listen socket for last_data_recv to be accurate



79
80
81
82
83
84
85
# File 'lib/raindrops/aggregate/last_data_recv.rb', line 79

def count!(io)
  if io
    x = TCP_Info.new(io)
    @raindrops_aggregate << x.last_data_recv
  end
  io
end

#kgio_accept(*args) ⇒ Object



59
60
61
# File 'lib/raindrops/aggregate/last_data_recv.rb', line 59

def kgio_accept(*args)
  count! super
end

#kgio_tryaccept(*args) ⇒ Object

:stopdoc:



55
56
57
# File 'lib/raindrops/aggregate/last_data_recv.rb', line 55

def kgio_tryaccept(*args)
  count! super
end