Parent

Class Index [+]

Quicksearch

Curl::Multi

Public Class Methods

default_timeout = 4 => 4 click to toggle source

Get the global default time out for all Curl::Multi Handles.

VALUE ruby_curl_multi_get_default_timeout(VALUE klass) 
default_timeout = 4 => 4 click to toggle source

Set the global default time out for all Curl::Multi Handles. This value is used when libcurl cannot determine a timeout value when calling curl_multi_timeout.

VALUE ruby_curl_multi_set_default_timeout(VALUE klass, VALUE timeout) 
click to toggle source

Curl::Multi.download(|}

will create 2 new files file1.txt and file2.txt

2 files will be opened, and remain open until the call completes

when using the :post or :put method, urls should be a hash, including the individual post fields per post

     # File lib/curb.rb, line 202
202:       def download(urls,easy_options={},multi_options={},download_paths=nil,&blk)
203:         procs = []
204:         files = []
205:         urls_with_config = []
206:         url_to_download_paths = {}
207: 
208:         urls.each_with_index do|urlcfg,i|
209:           if urlcfg.is_a?(Hash)
210:             url = url[:url]
211:           else
212:             url = urlcfg
213:           end
214: 
215:           if download_paths and download_paths[i]
216:             download_path = download_paths[i]
217:           else
218:             download_path = File.basename(url)
219:           end
220: 
221:           lambda do|dp|
222:             file = File.open(dp,"wb")
223:             procs << (lambda {|data| file.write data; data.size })
224:             files << file
225:           end.call(download_path)
226: 
227:           if urlcfg.is_a?(Hash)
228:             urls_with_config << urlcfg.merge({:on_body => procs.last}.merge(easy_options))
229:           else
230:             urls_with_config << {:url => url, :on_body => procs.last, :method => :get}.merge(easy_options)
231:           end
232:           url_to_download_paths[url] = download_path # store for later
233:         end
234: 
235:         if blk
236:           Curl::Multi.http(urls_with_config, multi_options) {|c,code,method| blk.call(c,url_to_download_paths[c.url]) }
237:         else
238:           Curl::Multi.http(urls_with_config, multi_options)
239:         end
240: 
241:       ensure
242:         errors = []
243:         files.each {|f|
244:           begin
245:             f.close
246:           rescue => e
247:             errors << e
248:           end
249:         }
250:         raise errors unless errors.empty?
251:       end
get('url1','url2','url3','url4','url5', :follow_location => true) do|easy| easy end click to toggle source

Blocking call to fetch multiple url’s in parallel.

    # File lib/curb.rb, line 67
67:       def get(urls, easy_options={}, multi_options={}, &blk)
68:         url_confs = []
69:         urls.each do|url|
70:           url_confs << {:url => url, :method => :get}.merge(easy_options)
71:         end
72:         self.http(url_confs, multi_options) {|c,code,method| blk.call(c) }
73:       end
click to toggle source

Curl::Multi.http( [

  { :url => 'url1', :method => :post,
    :post_fields => {'field1' => 'value1', 'field2' => 'value2'} },
  { :url => 'url2', :method => :get,
    :follow_location => true, :max_redirects => 3 },
  { :url => 'url3', :method => :put, :put_data => File.open('file.txt','rb') },
  { :url => 'url4', :method => :head }

], {:pipeline => true})

Blocking call to issue multiple HTTP requests with varying verb’s.

urls_with_config: is a hash of url’s pointing to the easy handle options as well as the special option :method, that can by one of [:get, :post, :put, :delete, :head], when no verb is provided e.g. :method => nil -> GET is used multi_options: options for the multi handle blk: a callback, that yeilds when a handle is completed

     # File lib/curb.rb, line 141
141:       def http(urls_with_config, multi_options={}, &blk)
142:         m = Curl::Multi.new
143:         # configure the multi handle
144:         multi_options.each { |k,v| m.send("#{k}=", v) }
145:         callbacks = [:on_progress,:on_debug,:on_failure,:on_success,:on_body,:on_header]
146: 
147:         urls_with_config.each do|conf|
148:           c = conf.dup # avoid being destructive to input
149:           url     = c.delete(:url)
150:           method  = c.delete(:method)
151:           headers = c.delete(:headers)
152: 
153:           easy    = Curl::Easy.new(url)
154: 
155:           # assign callbacks
156:           callbacks.each do |cb|
157:             cbproc = c.delete(cb)
158:             easy.send(cb,&cbproc) if cbproc
159:           end
160: 
161:           case method
162:           when :post
163:             fields = c.delete(:post_fields)
164:             # set the post post using the url fields
165:             easy.post_body = fields.map{|f,k| "#{easy.escape(f)}=#{easy.escape(k)}"}.join('&')
166:           when :put
167:             easy.put_data = c.delete(:put_data)
168:           when :head
169:             easy.head = true
170:           when :delete
171:             easy.delete = true
172:           when :get
173:           else
174:             # XXX: nil is treated like a GET
175:           end
176: 
177:           # headers is a special key
178:           headers.each {|k,v| easy.headers[k] = v } if headers
179:  
180:           #
181:           # use the remaining options as specific configuration to the easy handle
182:           # bad options should raise an undefined method error
183:           #
184:           c.each { |k,v| easy.send("#{k}=",v) }
185: 
186:           easy.on_complete {|curl,code| blk.call(curl,code,method) } if blk
187:           m.add(easy)
188:         end
189:         m.perform
190:       end
> click to toggle source

Create a new Curl::Multi instance

VALUE ruby_curl_multi_new(VALUE klass) 
click to toggle source
  Curl::Multi.post([{:url => 'url1', :post_fields => {'field1' => 'value1', 'field2' => 'value2'}},
                    {:url => 'url2', :post_fields => {'field1' => 'value1', 'field2' => 'value2'}},
                    {:url => 'url3', :post_fields => {'field1' => 'value1', 'field2' => 'value2'}}],
                   { :follow_location => true, :multipart_form_post => true },
                   {:pipeline => true }) do|easy|
    easy_handle_on_request_complete
  end

Blocking call to POST multiple form’s in parallel.

urls_with_config: is a hash of url’s pointing to the postfields to send easy_options: are a set of common options to set on all easy handles multi_options: options to set on the Curl::Multi handle

    # File lib/curb.rb, line 91
91:       def post(urls_with_config, easy_options={}, multi_options={}, &blk)
92:         url_confs = []
93:         urls_with_config.each do|uconf|
94:           url_confs << uconf.merge(:method => :post).merge(easy_options)
95:         end
96:         self.http(url_confs, multi_options) {|c,code,method| blk.call(c) }
97:       end
click to toggle source
  Curl::Multi.put([{:url => 'url1', :put_data => "some message"},
                   {:url => 'url2', :put_data => IO.read('filepath')},
                   {:url => 'url3', :put_data => "maybe another string or socket?"],
                   {:follow_location => true},
                   {:pipeline => true }) do|easy|
    easy_handle_on_request_complete
  end

Blocking call to POST multiple form’s in parallel.

urls_with_config: is a hash of url’s pointing to the postfields to send easy_options: are a set of common options to set on all easy handles multi_options: options to set on the Curl::Multi handle

     # File lib/curb.rb, line 115
115:       def put(urls_with_config, easy_options={}, multi_options={}, &blk)
116:         url_confs = []
117:         urls_with_config.each do|uconf|
118:           url_confs << uconf.merge(:method => :put).merge(easy_options)
119:         end
120:         self.http(url_confs, multi_options) {|c,code,method| blk.call(c) }
121:       end

Public Instance Methods

new('url') click to toggle source

multi.add(easy)

Add an easy handle to the multi stack

VALUE ruby_curl_multi_add(VALUE self, VALUE easy) 
cancel! click to toggle source

Cancels all requests currently being made on this Curl::Multi handle.

static VALUE ruby_curl_multi_cancel(VALUE self) 
idle? => true or false click to toggle source

Returns whether or not this Curl::Multi handle is processing any requests. E.g. this returns true when multi.requests.length == 0.

static VALUE ruby_curl_multi_idle(VALUE self) 
max_connects = 800 click to toggle source

Set the max connections in the cache for a multi handle

static VALUE ruby_curl_multi_max_connects(VALUE self, VALUE count) 
new('url') click to toggle source

multi.add(easy1) multi.add(easy2)

multi.perform do

 # while idle other code my execute here

end

Run multi handles, looping selecting when data can be transfered

VALUE ruby_curl_multi_perform(int argc, VALUE *argv, VALUE self) 
pipeline = true click to toggle source

Pass a long set to 1 to enable or 0 to disable. Enabling pipelining on a multi handle will make it attempt to perform HTTP Pipelining as far as possible for transfers using this handle. This means that if you add a second request that can use an already existing connection, the second request will be “piped” on the same connection rather than being executed in parallel. (Added in 7.16.0)

static VALUE ruby_curl_multi_pipeline(VALUE self, VALUE onoff) 
new('url') click to toggle source

multi.add(easy)

# sometime later multi.remove(easy)

Remove an easy handle from a multi stack.

Will raise an exception if the easy handle is not found

VALUE ruby_curl_multi_remove(VALUE self, VALUE easy) 
] click to toggle source

Returns an array containing all the active requests on this Curl::Multi object.

static VALUE ruby_curl_multi_requests(VALUE self) 

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.