Module: Pitchfork::SocketHelper

Included in:
HttpServer
Defined in:
lib/pitchfork/socket_helper.rb

Constant Summary collapse

DEFAULTS =

internal interface

{
  # The semantics for TCP_DEFER_ACCEPT changed in Linux 2.6.32+
  # with commit d1b99ba41d6c5aa1ed2fc634323449dd656899e9
  # This change shouldn't affect pitchfork users behind nginx (a
  # value of 1 remains an optimization).
  :tcp_defer_accept => 1,

  # FreeBSD, we need to override this to 'dataready' if we
  # eventually support non-HTTP/1.x
  :accept_filter => 'httpready',

  # same default value as Mongrel
  :backlog => 1024,

  # favor latency over bandwidth savings
  :tcp_nopush => nil,
  :tcp_nodelay => true,
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.sock_name(sock) ⇒ Object

Returns the configuration name of a socket as a string. sock may be a string value, in which case it is returned as-is Warning: TCP sockets may not always return the name given to it.



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/pitchfork/socket_helper.rb', line 179

def sock_name(sock)
  case sock
  when String then sock
  when UNIXServer
    Socket.unpack_sockaddr_un(sock.getsockname)
  when TCPServer
    tcp_name(sock)
  when Socket
    begin
      tcp_name(sock)
    rescue ArgumentError
      Socket.unpack_sockaddr_un(sock.getsockname)
    end
  else
    raise ArgumentError, "Unhandled class #{sock.class}: #{sock.inspect}"
  end
end

.tcp_name(sock) ⇒ Object

returns rfc2732-style (e.g. “[::1]:666”) addresses for IPv6



170
171
172
173
# File 'lib/pitchfork/socket_helper.rb', line 170

def tcp_name(sock)
  port, addr = Socket.unpack_sockaddr_in(sock.getsockname)
  addr.include?(':') ? "[#{addr}]:#{port}" : "#{addr}:#{port}"
end

Instance Method Details

#accf_arg(af_name) ⇒ Object

configure platform-specific options (only tested on Linux 2.6 so far)



32
33
34
# File 'lib/pitchfork/socket_helper.rb', line 32

def accf_arg(af_name)
  [ af_name, nil ].pack('a16a240')
end