def setsockopt name, value, length = nil
      if 1 == @option_lookup[name]
        length = 8
        pointer = LibC.malloc length
        pointer.write_long_long value

      elsif 0 == @option_lookup[name]
        length = 4
        pointer = LibC.malloc length
        pointer.write_int value

      elsif 2 == @option_lookup[name]
        length ||= value.size

        # note: not checking errno for failed memory allocations :(
        pointer = LibC.malloc length
        pointer.write_string value
      end

      rc = LibXS.xs_setsockopt @socket, name, pointer, length
      LibC.free(pointer) unless pointer.nil? || pointer.null?
      rc
    end
def setsockopt name, value, length = nil
      if 1 == @option_lookup[name]
        length = 8
        pointer = LibC.malloc length
        pointer.write_long_long value

      elsif 0 == @option_lookup[name]
        length = 4
        pointer = LibC.malloc length
        pointer.write_int value

      elsif 2 == @option_lookup[name]
        length ||= value.size

        # note: not checking errno for failed memory allocations :(
        pointer = LibC.malloc length
        pointer.write_string value
      end

      rc = LibXS.xs_setsockopt @socket, name, pointer, length
      LibC.free(pointer) unless pointer.nil? || pointer.null?
      rc
    end
Allocates a socket of type +type+ for sending and receiving data.

 To avoid rescuing exceptions, use the factory method #create for
 all socket creation.

 By default, this class uses XS::Message for manual
 memory management. For automatic garbage collection of received messages,
 it is possible to override the :receiver_class to use XS::ManagedMessage.

 @example Socket creation
   sock = Socket.new(Context.new, XS::REQ, :receiver_class => XS::ManagedMessage)

 Advanced users may want to replace the receiver class with their
 own custom class. The custom class must conform to the same public API
 as XS::Message.

 Creation of a new Socket object can raise an exception. This occurs when the
 +context_ptr+ is null or when the allocation of the Crossroads socket within the
 context fails.

 @example
   begin
     socket = Socket.new(context.pointer, XS::REQ)
   rescue ContextError => e
     # error handling
   end

 @param pointer
 @param [Constant] type
   One of @XS::REQ@, @XS::REP@, @XS::PUB@, @XS::SUB@, @XS::PAIR@,
          @XS::PULL@, @XS::PUSH@, @XS::XREQ@, @XS::REP@,
          @XS::DEALER@ or @XS::ROUTER@
 @param [Hash] options

 @return [Socket] when successful
 @return nil when unsuccessful
 Set the queue options on this socket

 @param [Constant] name numeric values
   One of @XS::AFFINITY@, @XS::RATE@, @XS::RECOVERY_IVL@,
          @XS::LINGER@, @XS::RECONNECT_IVL@, @XS::BACKLOG@,
          @XS::RECONNECT_IVL_MAX@, @XS::MAXMSGSIZE@, @XS::SNDHWM@,
          @XS::RCVHWM@, @XS::MULTICAST_HOPS@, @XS::RCVTIMEO@,
          @XS::SNDTIMEO@, @XS::IPV4ONLY@, @XS::KEEPALIVE@,
          @XS::SUBSCRIBE@, @XS::UNSUBSCRIBE@, @XS::IDENTITY@,
          @XS::SNDBUF@, @XS::RCVBUF@
 @param [Constant] name string values
   One of @XS::IDENTITY@, @XS::SUBSCRIBE@ or @XS::UNSUBSCRIBE@
 @param value

 @return 0 when the operation completed successfully
 @return -1 when this operation fails

 With a -1 return code, the user must check XS.errno to determine the
 cause.

 @example
   rc = socket.setsockopt(XS::LINGER, 1_000)
   XS::Util.resultcode_ok?(rc) ? puts("succeeded") : puts("failed")