static void _do_multi_socket_action(_bosh_conn_ctx conn_ctx) { JW_LOG_TRACE_FUNCTION_NO_ARGS; assert(conn_ctx); // tell curl that a timeout has occurred jw_err err; CURLMcode rc = curl_multi_socket_action( conn_ctx->multi, CURL_SOCKET_TIMEOUT, 0, &conn_ctx->num_active); if (!_check_curl_mcode(rc, &err)) { goto _do_multi_socket_action_fail_label; } // test to see if we have any connection status changes to react to if (!_check_multi_info(conn_ctx, &err)) { goto _do_multi_socket_action_fail_label; } return; _do_multi_socket_action_fail_label: conn_ctx->error_cb(err.code, conn_ctx->cb_arg); }
/* Called by glib when we get action on a multi socket */ static gboolean event_cb(GIOChannel *ch, GIOCondition condition, gpointer data) { GlobalInfo *g = (GlobalInfo*) data; CURLMcode rc; int fd = g_io_channel_unix_get_fd(ch); int action = (condition & G_IO_IN ? CURL_CSELECT_IN : 0) | (condition & G_IO_OUT ? CURL_CSELECT_OUT : 0); rc = curl_multi_socket_action(g->multi, fd, action, &g->still_running); mcode_or_die("event_cb: curl_multi_socket_action", rc); check_multi_info(g); if(g->still_running) { return TRUE; } else { MSG_OUT("last transfer done, kill timeout\n"); if(g->timer_event) { g_source_remove(g->timer_event); } return FALSE; } }
void on_timeout(uv_timer_t *req, int status) { int running_handles; curl_multi_socket_action(curl_handle, CURL_SOCKET_TIMEOUT, 0, &running_handles); check_multi_info(); }
void curl_perform(uv_poll_t *si, int status, int events) { int running_handles; int flags = 0; Socket_Info *s = (Socket_Info *) si->data; Mathilda *m = (Mathilda *) s->m; uv_timer_stop(&m->timeout); if(status < 0) { flags = CURL_CSELECT_ERR; } if(!status && events & UV_READABLE) { flags |= CURL_CSELECT_IN; } if(!status && events & UV_WRITABLE) { flags |= CURL_CSELECT_OUT; } curl_multi_socket_action(m->multi_handle, s->sock_fd, flags, &running_handles); check_multi_info(m); uv_timer_start(&m->timeout, (uv_timer_cb) on_timeout, 0, 0); }
/* note: this function can free the tr_web if its 'closing' flag is set and no tasks remain. callers must not reference their g pointer after calling this function */ static void tr_multi_socket_action( tr_web * g, int fd, int mask ) { int closed = FALSE; CURLMcode rc; dbgmsg( "check_run_count: prev_running %d, still_running %d", g->prev_running, g->still_running ); /* invoke libcurl's processing */ do { rc = curl_multi_socket_action( g->multi, fd, mask, &g->still_running ); dbgmsg( "event_cb(): fd %d, mask %d, still_running is %d", fd, mask, g->still_running ); } while( rc == CURLM_CALL_MULTI_PERFORM ); if( rc != CURLM_OK ) tr_err( "%s", curl_multi_strerror( rc ) ); remove_finished_tasks( g ); add_tasks_from_queue( g ); if( !g->still_running ) { stop_timer( g ); if( g->closing ) { web_close( g ); closed = TRUE; } } if( !closed ) restart_timer( g ); }
static gboolean event_cb(GIOChannel *ch, GIOCondition condition, gpointer data) { CURLMcode res; FetchData *fetch_data = (FetchData*)data; struct curl_data *cd = fetch_data->private_data; CURLM *curl = cd->curlm; int fd = g_io_channel_unix_get_fd(ch); int action = (condition & G_IO_IN ? CURL_CSELECT_IN : 0) | (condition & G_IO_OUT ? CURL_CSELECT_OUT : 0); res = curl_multi_socket_action(curl, fd, action, &cd->running); if (res != CURLM_OK) { g_set_error(&fetch_data->error, RESTRAINT_FETCH_LIBARCHIVE_ERROR, res, "curl failed"); g_idle_add (archive_finish_callback, fetch_data); return FALSE; } check_multi_info(fetch_data); if (cd->running) { return TRUE; } else { if (cd->to_ev != 0) { g_source_remove(cd->to_ev); cd->to_ev = 0; } return FALSE; } }
void curl_perform(uv_poll_t *req, int status, int events) { uv_timer_stop(&timeout); //printf("curl_perform# timeout %d status %d events %d \n",timeout,status,events); int running_handles; int flags = 0; if (events & UV_READABLE) flags |= CURL_CSELECT_IN; if (events & UV_WRITABLE) flags |= CURL_CSELECT_OUT; curl_context_t *context; context = (curl_context_t*)req; //printf("curl_perform# flag %d sockfd %d \n",flags,context->sockfd); curl_multi_socket_action(curl_handle, context->sockfd, flags, &running_handles); char *done_url; CURLMsg *message; int pending; while ((message = curl_multi_info_read(curl_handle, &pending))) { switch (message->msg) { case CURLMSG_DONE: curl_easy_getinfo(message->easy_handle, CURLINFO_EFFECTIVE_URL, &done_url); printf("\n%s DONE\n", done_url); curl_multi_remove_handle(curl_handle, message->easy_handle); curl_easy_cleanup(message->easy_handle); break; default: fprintf(stderr, "CURLMSG default\n"); abort(); } } }
void curl_perform_action(int socket, int actions) { int running_handles; char *done_url; CURLMsg *message; int pending; curl_multi_socket_action(curl_handle, socket, actions, &running_handles); while ((message = curl_multi_info_read(curl_handle, &pending))) { switch (message->msg) { case CURLMSG_DONE: { CURL* easy = message->easy_handle; curl_easy_getinfo(easy, CURLINFO_EFFECTIVE_URL, &done_url); CURLcode code = message->data.result; printf("%s DONE\ncode:%d - %s\n", done_url, code, curl_easy_strerror(code)); curl_multi_remove_handle(curl_handle, message->easy_handle); curl_easy_cleanup(message->easy_handle); --remaining; break; } default: log_error("CURLMSG default\n"); abort(); } } }
void event_callback(int _socket, short _kind, void* _connection_ptr) { const auto connection = static_cast<curl_handler::connection_context*>(_connection_ptr); const auto handler = connection->curl_handler_; const auto tv = curl_handler::make_timeval(connection->timeout_); event_del(connection->timeout_event_); event_add(connection->timeout_event_, &tv); int action = 0; if (_kind & EV_READ) action |= CURL_CSELECT_IN; if (_kind & EV_WRITE) action |= CURL_CSELECT_OUT; const auto error = curl_multi_socket_action(handler->multi_handle_, _socket, action, &handler->running_); assert(!error); (void*) error; // supress warning check_multi_info(handler); if (handler->running_ <= 0) { if (evtimer_pending(handler->timer_event_, NULL)) evtimer_del(handler->timer_event_); } }
static void curl_on_active(handle_t s,int event){ int running_handles; int flags = 0; curl_conn_t conn; CURLMsg *message; int pending; if(event & EVENT_READ) flags |= CURL_CSELECT_IN; if(event & EVENT_WRITE) flags |= CURL_CSELECT_OUT; conn = (curl_conn_t)s; if(conn->c_handle->timer){ kn_del_timer(conn->c_handle->timer); conn->c_handle->timer = NULL; } curl_multi_socket_action(kn_CURLM_get(conn->c_handle), ((handle_t)conn)->fd, flags,&running_handles); while ((message = curl_multi_info_read(kn_CURLM_get(conn->c_handle), &pending))) { kn_CURL_t curl; curl_easy_getinfo(message->easy_handle, CURLINFO_PRIVATE, &curl); if(message->msg == CURLMSG_DONE){ if(curl->cb) curl->cb(curl,message,curl->ud); else kn_curl_easy_cleanup(curl); }else{ fprintf(stderr, "CURLMSG default\n"); abort(); } } }
static int timer_callback(kn_timer_t timer){ kn_CURLM_t cm = (kn_CURLM_t)kn_timer_getud(timer); int running_handles; curl_multi_socket_action(cm->c_handle, CURL_SOCKET_TIMEOUT,0,&running_handles); //cm->timer = NULL;//不需要销毁,callback返回0后会被自动销毁 return 1; }
static int curl_glue_on_io(sd_event_source *s, int fd, uint32_t revents, void *userdata) { CurlGlue *g = userdata; int action, k = 0, translated_fd; assert(s); assert(g); translated_fd = PTR_TO_FD(hashmap_get(g->translate_fds, FD_TO_PTR(fd))); if ((revents & (EPOLLIN|EPOLLOUT)) == (EPOLLIN|EPOLLOUT)) action = CURL_POLL_INOUT; else if (revents & EPOLLIN) action = CURL_POLL_IN; else if (revents & EPOLLOUT) action = CURL_POLL_OUT; else action = 0; if (curl_multi_socket_action(g->curl, translated_fd, action, &k) < 0) { log_debug("Failed to propagate IO event."); return -EINVAL; } curl_glue_check_finished(g); return 0; }
static void inet_sch_task_sock_event_cb(EV_P_ struct ev_io *w, int revents) { inet_sch_manage_t mgr; inet_sch_task_t task; CURLMcode rc; int action; task = (inet_sch_task_t)w->data; assert(task); mgr = task->m_mgr; action = (revents & EV_READ?CURL_POLL_IN : 0) | ( revents & EV_WRITE?CURL_POLL_OUT : 0); rc = curl_multi_socket_action(task->m_mgr->m_multi, w->fd, action, &mgr->m_still_running); if (rc != CURLM_OK) { CPE_ERROR( mgr->m_em, "%s: sock_event_cb: curl_multi_socket_handle fail, %s(%d)!", inet_sch_manage_name(task->m_mgr), inet_sch_curl_code_msg(rc), rc); return; } inet_sch_process_multi_info(mgr); if (mgr->m_still_running <= 0) { if (mgr->m_debug >= 2) { CPE_INFO( mgr->m_em, "%s: sock_event_cb: no task runing, stop timer!", inet_sch_manage_name(task->m_mgr)); } ev_timer_stop(mgr->m_loop, &mgr->m_timer_event); } }
/* Called by asio when our timeout expires */ void http_client::timer_cb(const boost::system::error_code& e) { if(!e) { BOOST_LOG_TRIVIAL(trace) << this << ", " << BOOST_CURRENT_FUNCTION; // CURL_SOCKET_TIMEOUT, 0 is corrent on timeouts http://curl.haxx.se/libcurl/c/curl_multi_socket_action.html CURLMcode rc = curl_multi_socket_action(_multi, CURL_SOCKET_TIMEOUT, 0, &_still_running); //check_multi_info(); //TBD kolla om denna ska vara här } }
static void asio_timer_callback(const boost::system::error_code& error, void* data) { if (!error) { asyn_http_object* aho = (asyn_http_object*)data; CURLMcode code = curl_multi_socket_action(aho->curlm, CURL_SOCKET_TIMEOUT, 0, &aho->still_running); check_multi_curl(data); } }
// This function is for signalling to curl a given time has passed. // This timeout is usually given by curl itself. void iotjs_https_uv_timeout_callback(uv_timer_t* timer) { iotjs_https_t* https_data = (iotjs_https_t*)(timer->data); IOTJS_VALIDATED_STRUCT_METHOD(iotjs_https_t, https_data); uv_timer_stop(timer); curl_multi_socket_action(_this->curl_multi_handle, CURL_SOCKET_TIMEOUT, 0, &_this->running_handles); iotjs_https_check_done(https_data); }
CURLMcode debug_curl_multi_socket_action(CURLM* multi_handle, curl_socket_t sockfd, int ev_bitmask, int* running_handles) { CURLMcode ret; ret = curl_multi_socket_action(multi_handle, sockfd, ev_bitmask, running_handles); Dout(dc::curl, "curl_multi_socket_action(" << (AICURLM*)multi_handle << ", " << Socket(sockfd) << ", " << EvBitmask(ev_bitmask) << ", {" << (ret == CURLM_OK ? *running_handles : 0) << "}) = " << ret); return ret; }
void ConnectionManager::TimerTriggered() { WriteManagerLog(this) << "Timer triggered."; int running_count = 0; curl_multi_socket_action(multi_handle_, CURL_SOCKET_TIMEOUT, 0, &running_count); CheckFinishedConnections(); }
void http_client::socket_rx_cb(const boost::system::error_code& e, boost::asio::ip::tcp::socket * tcp_socket, call_context::handle context) { if(!e && !context->_curl_done) { //BOOST_LOG_TRIVIAL(debug) << "socket_rx_cb " << e << " bytes " << tcp_socket->available(); CURLMcode rc = curl_multi_socket_action(_multi, tcp_socket->native_handle(), CURL_CSELECT_IN, &_still_running); if(!context->_curl_done) tcp_socket->async_read_some(boost::asio::null_buffers(), boost::bind(&http_client::socket_rx_cb, this, boost::asio::placeholders::error, tcp_socket, context)); } }
static void _ev_timer_curl_cb(struct ev_loop *loop, struct ev_timer *w, int revents) { int running = 0; struct curlev *cuev = w->data; curl_multi_socket_action(cuev->multi, CURL_SOCKET_TIMEOUT, 0, &running); xsyslog(LOG_INFO, "ev timer: %p, running: %d", (void*)cuev, running); }
void ConnectionManager::SocketEventTriggered(curl_socket_t socket, bool can_write) { WriteManagerLog(this) << "Socket(" << socket << ") " << (can_write ? "write" : "read") << " event triggered."; int action = can_write ? CURL_CSELECT_OUT : CURL_CSELECT_IN; int running_count = 0; curl_multi_socket_action(multi_handle_, socket, action, &running_count); CheckFinishedConnections(); }
void on_timeout(uv_timer_t *req) { int running_handles; bear_stream_t *stream = (bear_stream_t*) req->data; curl_multi_socket_action(stream->curl_handle, CURL_SOCKET_TIMEOUT, 0, &running_handles); check_multi_info(stream); }
static void timer_cb(struct ev_loop *loop, struct ev_timer *w, int revents) { g_debug("%s w %p revents %i", __PRETTY_FUNCTION__, w, revents); CURLMcode rc; do { rc = curl_multi_socket_action(curl_runtime.multi, CURL_SOCKET_TIMEOUT, 0, &curl_runtime.active); } while( rc == CURLM_CALL_MULTI_PERFORM ); check_run_count(); }
static void notifyCurl(CURLM *curl, curl_socket_t s, int evBitmask, const char *info) { int numhandles = 0; CURLMcode result = curl_multi_socket_action(curl, s, evBitmask, &numhandles); if (result != CURLM_OK) { fprintf(stderr, "Curl error on %s: %i (%s)\n", info, result, curl_multi_strerror(result)); } }
void MultiAdapter::onTimeout(const boost::system::error_code& error) { AC_TRACE << "onTimeout " << error; if (error != 0) { return; } int i; CURLMcode myStatus = curl_multi_socket_action(_curlMulti, CURL_SOCKET_TIMEOUT, 0, &i); checkCurlStatus(myStatus, PLUS_FILE_LINE); };
void event_timer_callback(evutil_socket_t /*_descriptor*/, short /*_flags*/, void* _curl_handler_ptr) { const auto handler = static_cast<curl_handler*>(_curl_handler_ptr); const auto error = curl_multi_socket_action(handler->multi_handle_, CURL_SOCKET_TIMEOUT, 0, &handler->running_); assert(!error); (void*) error; // supress warning check_multi_info(handler); }
/* Called by glib when our timeout expires */ static gboolean timer_cb(gpointer data) { GlobalInfo *g = (GlobalInfo *)data; CURLMcode rc; rc = curl_multi_socket_action(g->multi, CURL_SOCKET_TIMEOUT, 0, &g->still_running); mcode_or_die("timer_cb: curl_multi_socket_action", rc); check_multi_info(g); return FALSE; }
void HTTPCURLContext::onTimeout(UV_TIMER_PARAMS(req)) { assert(req->data); auto context = reinterpret_cast<HTTPCURLContext *>(req->data); MBGL_VERIFY_THREAD(context->tid); int running_handles; CURLMcode error = curl_multi_socket_action(context->multi, CURL_SOCKET_TIMEOUT, 0, &running_handles); if (error != CURLM_OK) { throw std::runtime_error(std::string("CURL multi error: ") + curl_multi_strerror(error)); } context->checkMultiInfo(); }
/* Called by libevent when our timeout expires */ static void timer_cb(EV_P_ struct ev_timer *w, int revents) { DPRINT("%s w %p revents %i\n", __PRETTY_FUNCTION__, w, revents); GlobalInfo *g = (GlobalInfo *)w->data; CURLMcode rc; rc = curl_multi_socket_action(g->multi, CURL_SOCKET_TIMEOUT, 0, &g->still_running); mcode_or_die("timer_cb: curl_multi_socket_action", rc); check_multi_info(g); }
/* Called by libevent when our timeout expires */ static void timer_cb(int fd, short kind, void *userp) { GlobalInfo *g = (GlobalInfo *)userp; CURLMcode rc; (void)fd; (void)kind; rc = curl_multi_socket_action(g->multi, CURL_SOCKET_TIMEOUT, 0, &g->still_running); mcode_or_die("timer_cb: curl_multi_socket_action", rc); check_multi_info(g); }