Class: Socket::Option
| Relationships & Source Files | |
| Inherits: | Object | 
| Defined in: | ext/socket/option.c | 
Overview
Option represents a socket option used by BasicSocket#getsockopt and BasicSocket#setsockopt.  A socket option contains the socket #family, protocol #level, option name #optname and option value #data.
Class Method Summary
- 
    
      .bool(family, level, optname, bool)  ⇒ sockopt 
    
    Creates a new Optionobject which contains boolean as data.
- 
    
      .byte(family, level, optname, integer)  ⇒ sockopt 
    
    Creates a new Optionobject which contains a byte as data.
- 
    
      .int(family, level, optname, integer)  ⇒ sockopt 
    
    Creates a new Optionobject which contains an int as data.
- 
    
      .ipv4_multicast_loop(integer)  ⇒ sockopt 
    
    Creates a new Optionobject for IP_MULTICAST_LOOP.
- 
    
      .ipv4_multicast_ttl(integer)  ⇒ sockopt 
    
    Creates a new Optionobject for IP_MULTICAST_TTL.
- 
    
      .linger(onoff, secs)  ⇒ sockopt 
    
    Creates a new Optionobject for SOL_SOCKET/SO_LINGER.
- 
    
      .new(family, level, optname, data)  ⇒ sockopt 
    
    constructor
    Returns a new Optionobject.
Instance Method Summary
- 
    
      #bool  ⇒ Boolean 
    
    Returns the data in sockopt as an boolean value. 
- 
    
      #byte  ⇒ Integer 
    
    Returns the data in sockopt as an byte. 
- 
    
      #data  ⇒ String 
    
    Alias for #to_s. 
- 
    
      #family  ⇒ Integer 
    
    returns the socket family as an integer. 
- 
    
      #inspect  ⇒ String 
    
    Returns a string which shows sockopt in human-readable form. 
- 
    
      #int  ⇒ Integer 
    
    Returns the data in sockopt as an int. 
- 
    
      #ipv4_multicast_loop  ⇒ Integer 
    
    Returns the ipv4_multicast_loop data in sockopt as an integer. 
- 
    
      #ipv4_multicast_ttl  ⇒ Integer 
    
    Returns the ipv4_multicast_ttl data in sockopt as an integer. 
- 
    
      #level  ⇒ Integer 
    
    returns the socket level as an integer. 
- 
    
      #linger  ⇒ Array, seconds 
    
    Returns the linger data in sockopt as a pair of boolean and integer. 
- 
    
      #optname  ⇒ Integer 
    
    returns the socket option name as an integer. 
- 
    
      #to_s  ⇒ String 
      (also: #data)
    
    returns the socket option data as a string. 
- 
    
      #unpack(template)  ⇒ Array 
    
    Calls String#unpackon sockopt.data.
Constructor Details
    .new(family, level, optname, data)  ⇒ sockopt   
Returns a new Option object.
sockopt = Socket::Option.new(:INET, :SOCKET, :KEEPALIVE, [1].pack("i"))
p sockopt #=> #<Socket::Option: INET SOCKET KEEPALIVE 1>Class Method Details
    .bool(family, level, optname, bool)  ⇒ sockopt   
Creates a new Option object which contains boolean as data. Actually 0 or 1 as int is used.
require 'socket'
p Socket::Option.bool(:INET, :SOCKET, :KEEPALIVE, true)
#=> #<Socket::Option: INET SOCKET KEEPALIVE 1>
p Socket::Option.bool(:INET, :SOCKET, :KEEPALIVE, false)
#=> #<Socket::Option: AF_INET SOCKET KEEPALIVE 0>
    .byte(family, level, optname, integer)  ⇒ sockopt   
Creates a new Option object which contains a byte as data.
p Socket::Option.byte(:INET, :SOCKET, :KEEPALIVE, 1)
#=> #<Socket::Option: INET SOCKET KEEPALIVE 1>
    .int(family, level, optname, integer)  ⇒ sockopt   
Creates a new Option object which contains an int as data.
The size and endian is dependent on the platform.
p Socket::Option.int(:INET, :SOCKET, :KEEPALIVE, 1)
#=> #<Socket::Option: INET SOCKET KEEPALIVE 1>
    .ipv4_multicast_loop(integer)  ⇒ sockopt   
Creates a new Option object for IP_MULTICAST_LOOP.
The size is dependent on the platform.
sockopt = Socket::Option.int(:INET, :IPPROTO_IP, :IP_MULTICAST_LOOP, 1)
p sockopt.int => 1
p Socket::Option.ipv4_multicast_loop(10)
#=> #<Socket::Option: INET IP MULTICAST_LOOP 10>
    .ipv4_multicast_ttl(integer)  ⇒ sockopt   
Creates a new Option object for IP_MULTICAST_TTL.
The size is dependent on the platform.
p Socket::Option.ipv4_multicast_ttl(10)
#=> #<Socket::Option: INET IP MULTICAST_TTL 10>
    .linger(onoff, secs)  ⇒ sockopt   
Creates a new Option object for SOL_SOCKET/SO_LINGER.
onoff should be an integer or a boolean.
secs should be the number of seconds.
p Socket::Option.linger(true, 10)
#=> #<Socket::Option: UNSPEC SOCKET LINGER on 10sec>Instance Method Details
    #bool  ⇒ Boolean   
    #byte  ⇒ Integer   
    
      #data  ⇒ String 
      #to_s  ⇒ String 
    
  
String 
      #to_s  ⇒ String 
    Alias for #to_s.
    #family  ⇒ Integer   
    #inspect  ⇒ String   
    #int  ⇒ Integer   
    #ipv4_multicast_loop  ⇒ Integer   
Returns the ipv4_multicast_loop data in sockopt as an integer.
sockopt = Socket::Option.ipv4_multicast_loop(10)
p sockopt.ipv4_multicast_loop => 10
    #ipv4_multicast_ttl  ⇒ Integer   
Returns the ipv4_multicast_ttl data in sockopt as an integer.
sockopt = Socket::Option.ipv4_multicast_ttl(10)
p sockopt.ipv4_multicast_ttl => 10
    #level  ⇒ Integer   
    #linger  ⇒ Array, seconds   
    #optname  ⇒ Integer   
    
      #data  ⇒ String 
      #to_s  ⇒ String 
    
    Also known as: #data
  
String 
      #to_s  ⇒ String