Skip to content

Commit

Permalink
clean up the loop
Browse files Browse the repository at this point in the history
  • Loading branch information
taf2 committed Mar 20, 2011
1 parent 7a7d4d6 commit e7c92be
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions ext/curb_multi.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,29 +482,23 @@ VALUE ruby_curl_multi_perform(int argc, VALUE *argv, VALUE self) {

if (timeout_milliseconds == 0) { /* no delay */
rb_curl_multi_run( self, rbcm->handle, &(rbcm->running) );
rb_curl_multi_read_info( self, rbcm->handle );
if (block != Qnil) { rb_funcall(block, rb_intern("call"), 1, self); }
continue;
}
else if (timeout_milliseconds < 0) {
timeout_milliseconds = cCurlMutiDefaulttimeout; /* libcurl doesn't know how long to wait, use a default timeout */
}

if (timeout_milliseconds > cCurlMutiDefaulttimeout) {
timeout_milliseconds = cCurlMutiDefaulttimeout; /* buggy versions libcurl sometimes reports huge timeouts... let's cap it */
if (timeout_milliseconds < 0 || timeout_milliseconds > cCurlMutiDefaulttimeout) {
timeout_milliseconds = cCurlMutiDefaulttimeout; /* libcurl doesn't know how long to wait, use a default timeout */
/* or buggy versions libcurl sometimes reports huge timeouts... let's cap it */
}

tv.tv_sec = 0; /* never wait longer than 1 second */
tv.tv_usec = (int)(timeout_milliseconds * 1000); /* XXX: int is the right type for OSX, what about linux? */

if (timeout_milliseconds == 0) { /* no delay */
rb_curl_multi_run( self, rbcm->handle, &(rbcm->running) );
continue;
}

if (block != Qnil) { rb_funcall(block, rb_intern("call"), 1, self); }

FD_ZERO(&fdread);
FD_ZERO(&fdwrite);
FD_ZERO(&fdexcep);

/* load the fd sets from the multi handle */
mcode = curl_multi_fdset(rbcm->handle, &fdread, &fdwrite, &fdexcep, &maxfd);
if (mcode != CURLM_OK) {
Expand All @@ -529,17 +523,19 @@ VALUE ruby_curl_multi_perform(int argc, VALUE *argv, VALUE self) {
case -1:
rb_raise(rb_eRuntimeError, "select(): %s", strerror(errno));
break;
case 0:
case 0: /* timeout */
default: /* action */
rb_curl_multi_run( self, rbcm->handle, &(rbcm->running) );
rb_curl_multi_read_info( self, rbcm->handle );
if (block != Qnil) { rb_funcall(block, rb_intern("call"), 1, self); }
default:
rb_curl_multi_run( self, rbcm->handle, &(rbcm->running) );
break;
}
}
rb_curl_multi_read_info( self, rbcm->handle );
if (block != Qnil) { rb_funcall(block, rb_intern("call"), 1, self); }

} while( rbcm->running );

rb_curl_multi_read_info( self, rbcm->handle );
if (block != Qnil) { rb_funcall(block, rb_intern("call"), 1, self); }

return Qtrue;
}
Expand Down

0 comments on commit e7c92be

Please sign in to comment.