# File lib/ethon/curls/options.rb, line 13
      def set_option(option, value, handle, type = :easy)
        type = type.to_sym unless type.is_a?(Symbol)
        raise NameError, "Ethon::Curls::Options unknown type #{type}." unless respond_to?(OPTION_STRINGS[type])
        opthash=send(OPTION_STRINGS[type], nil)
        raise Errors::InvalidOption.new(option) unless opthash.include?(option)

        case opthash[option][:type]
        when :none
          return if value.nil?
          value=1
          func=:long
        when :int
          return if value.nil?
          func=:long
          value=value.to_i
        when :bool
          return if value.nil?
          func=:long
          value=(value&&value!=0) ? 1 : 0
        when :time
          return if value.nil?
          func=:long
          value=value.to_i
        when :enum
          return if value.nil?
          func=:long
          value = case value
          when Symbol
            opthash[option][:opts][value]
          when String
            opthash[option][:opts][value.to_sym]
          else
            value
          end.to_i
        when :bitmask
          return if value.nil?
          func=:long
          value = case value
          when Symbol
            opthash[option][:opts][value]
          when Array
            value.inject(0) { |res,v| res|opthash[option][:opts][v] }
          else
            value
          end.to_i
        when :string
          func=:string
          value=value.to_s unless value.nil?
        when :string_as_pointer
          func = :ffipointer
          s = ''
          s = value.to_s unless value.nil?
          value = FFI::MemoryPointer.new(:char, s.bytesize)
          value.put_bytes(0, s)
        when :string_escape_null
          func=:string
          value=Util.escape_zero_byte(value) unless value.nil?
        when :ffipointer
          func=:ffipointer
          raise Errors::InvalidValue.new(option,value) unless value.nil? or value.is_a? FFI::Pointer
        when :curl_slist
          func=:ffipointer
          raise Errors::InvalidValue.new(option,value) unless value.nil? or value.is_a? FFI::Pointer
        when :buffer
          raise NotImplementedError, "Ethon::Curls::Options option #{option} buffer type not implemented."
        when :dontuse_object
          raise NotImplementedError, "Ethon::Curls::Options option #{option} type not implemented."
        when :cbdata
          raise NotImplementedError, "Ethon::Curls::Options option #{option} callback data type not implemented. Use Ruby closures."
        when :callback
          func=:callback
          raise Errors::InvalidValue.new(option,value) unless value.nil? or value.is_a? Proc
        when :debug_callback
          func=:debug_callback
          raise Errors::InvalidValue.new(option,value) unless value.nil? or value.is_a? Proc
        when :progress_callback
          func=:progress_callback
          raise Errors::InvalidValue.new(option,value) unless value.nil? or value.is_a? Proc
        when :off_t
          return if value.nil?
          func=:off_t
          value=value.to_i
        end

        if func==:long or func==:off_t then
            bits=FFI.type_size(:long)*8 if func==:long
            bits=FFI.type_size(:int64)*8 if func==:off_t
            tv=((value<0) ? value.abs-1 : value)
            raise Errors::InvalidValue.new(option,value) unless tv<(1<<bits)
        end
        send(FUNCS[type][func], handle, opthash[option][:opt], value)
      end