File: options.rb

package info (click to toggle)
ruby-ethon 0.16.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 676 kB
  • sloc: ruby: 5,403; sh: 9; makefile: 8
file content (117 lines) | stat: -rw-r--r-- 3,163 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# frozen_string_literal: true
module Ethon
  class Multi

    # This module contains the logic and knowledge about the
    # available options on multi.
    module Options

      # Sets max_total_connections option.
      #
      # @example Set max_total_connections option.
      #   multi.max_total_conections = $value
      #
      # @param [ String ] value The value to set.
      #
      # @return [ void ]
      def max_total_connections=(value)
        Curl.set_option(:max_total_connections, value_for(value, :int), handle, :multi)
      end

      # Sets maxconnects option.
      #
      # @example Set maxconnects option.
      #   multi.maxconnects = $value
      #
      # @param [ String ] value The value to set.
      #
      # @return [ void ]
      def maxconnects=(value)
        Curl.set_option(:maxconnects, value_for(value, :int), handle, :multi)
      end

      # Sets pipelining option.
      #
      # @example Set pipelining option.
      #   multi.pipelining = $value
      #
      # @param [ String ] value The value to set.
      #
      # @return [ void ]
      def pipelining=(value)
        Curl.set_option(:pipelining, value_for(value, :int), handle, :multi)
      end

      # Sets socketdata option.
      #
      # @example Set socketdata option.
      #   multi.socketdata = $value
      #
      # @param [ String ] value The value to set.
      #
      # @return [ void ]
      def socketdata=(value)
        Curl.set_option(:socketdata, value_for(value, :string), handle, :multi)
      end

      # Sets socketfunction option.
      #
      # @example Set socketfunction option.
      #   multi.socketfunction = $value
      #
      # @param [ String ] value The value to set.
      #
      # @return [ void ]
      def socketfunction=(value)
        Curl.set_option(:socketfunction, value_for(value, :string), handle, :multi)
      end

      # Sets timerdata option.
      #
      # @example Set timerdata option.
      #   multi.timerdata = $value
      #
      # @param [ String ] value The value to set.
      #
      # @return [ void ]
      def timerdata=(value)
        Curl.set_option(:timerdata, value_for(value, :string), handle, :multi)
      end

      # Sets timerfunction option.
      #
      # @example Set timerfunction option.
      #   multi.timerfunction = $value
      #
      # @param [ String ] value The value to set.
      #
      # @return [ void ]
      def timerfunction=(value)
        Curl.set_option(:timerfunction, value_for(value, :string), handle, :multi)
      end

      private

      # Return the value to set to multi handle. It is converted with the help
      # of bool_options, enum_options and int_options.
      #
      # @example Return casted the value.
      #   multi.value_for(:verbose)
      #
      # @return [ Object ] The casted value.
      def value_for(value, type, option = nil)
        return nil if value.nil?

        if type == :bool
          value ? 1 : 0
        elsif type == :int
          value.to_i
        elsif value.is_a?(String)
          Ethon::Easy::Util.escape_zero_byte(value)
        else
          value
        end
      end
    end
  end
end