Skip to content

Commit

Permalink
fix curl multi bug (#4147)
Browse files Browse the repository at this point in the history
* defense

* optimize
  • Loading branch information
matyhtf committed Apr 9, 2021
1 parent 653f2fe commit f32867a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion ext-src/swoole_curl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ CURLcode Multi::exec(php_curl *ch) {
if (sockfd >= 0 && handle->socket && handle->socket->removed) {
swoole_event_add(handle->socket, get_event(handle->action));
}
if (!timer && handle->socket->removed) {
break;
}
}

CURLcode retval = read_info();
Expand Down Expand Up @@ -228,6 +231,7 @@ long Multi::select(php_curlm *mh) {
co = nullptr;
};

int event_count = 0;
for (zend_llist_element *element = mh->easyh.head; element; element = element->next) {
zval *z_ch = (zval *) element->data;
php_curl *ch;
Expand All @@ -236,12 +240,18 @@ long Multi::select(php_curlm *mh) {
}
Handle *handle = get_handle(ch->cp);
if (handle && handle->socket && handle->socket->removed) {
swoole_event_add(handle->socket, get_event(handle->action));
if (swoole_event_add(handle->socket, get_event(handle->action)) == SW_OK) {
event_count++;
}
swTraceLog(SW_TRACE_CO_CURL, "resume, handle=%p, curl=%p, fd=%d", handle, ch->cp, handle->socket->get_fd());
}
}
set_timer();

// no events and timers, should not be suspended
if (!timer && event_count == 0) {
return 0;
}
co->yield();
auto count = selector->active_handles.size();

Expand Down

0 comments on commit f32867a

Please sign in to comment.