Skip to content

Commit

Permalink
A few minor readability & comment changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Ball committed Aug 20, 2009
1 parent a4fdbbd commit ea4c591
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions lib/curl-multi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@

module Curl
class Error < RuntimeError
attr_accessor :code
def initialize(code)
self.code = code
super("Curl error #{code}")
end
end

class HTTPError < RuntimeError
attr_accessor :status
def initialize(status)
self.status = status
super("Curl HTTP error #{status}")
end
end
Expand Down Expand Up @@ -85,7 +89,10 @@ def add_chunk(chunk)
class Multi
def size() @handles.size end

def inspect() '{Curl::Multi' + @handles.map{|h| ' '+h.url}.join + '}' end
def inspect()
'{Curl::Multi' + @handles.map{|h| ' '+h.url}.join + '}'
end

alias_method :to_s, :inspect

def get(url, success, failure=lambda{})
Expand All @@ -101,7 +108,11 @@ def select(rfds, wfds)
ready_rfds, ready_wfds = c_select(rfds.map{|s|s.fileno},
wfds.map{|s|s.fileno})
work() # Curl may or may not have work to do, but we can't tell.

# If we find any ready file descriptors, return them
return ready_rfds, ready_wfds if ready_rfds.any? or ready_wfds.any?
# If our original descriptor lists were empty, return after
# one loop
return [], [] if rfds == [] and wfds == []
end
end
Expand Down Expand Up @@ -135,7 +146,9 @@ def initialize

# Add a URL to the queue of items to fetch
def add(url, body, success, failure=lambda{})
while (h = add_to_curl(Req.new(url, success, failure), url, body)) == nil
while true
h = add_to_curl(Req.new(url, success, failure), url, body)
break if h
select([], [])
end
@handles << h
Expand Down Expand Up @@ -240,7 +253,7 @@ def post_process(handles)
/* Pass it the URL */
curl_easy_setopt(easy_handle, CURLOPT_URL, c_url);
/* GET or POST? */
/* if POST */
if (body != Qnil) {
char *c_body = StringValuePtr(body);
uint body_sz = RSTRING(body)->len;
Expand Down Expand Up @@ -280,10 +293,12 @@ def post_process(handles)
FD_ZERO(&wfds);
FD_ZERO(&efds);
/* Put curl's fds into the sets. */
/* Put curl's fds into the sets. Also sets n to the *
* highest fd */
cr = curl_multi_fdset(multi_handle, &rfds, &wfds, &efds, &n);
CHECKN(cr);
/* Put the given fds into the sets. */
for (i = 0; i < RARRAY(rfda)->len; i++) {
int fd = FIX2INT(RARRAY(rfda)->ptr[i]);
Expand Down

0 comments on commit ea4c591

Please sign in to comment.