Example #1
0
// 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);
}
Example #2
0
static void del_defer(void *glue_data, void *id)
{
    dfr_t *d = (dfr_t *)id;

    IOT_UNUSED(glue_data);

    uv_timer_stop(&d->uv_tmr);
    iot_free(d);
}
Example #3
0
 void Timer::stop() 
 {
     int r = uv_timer_stop(&handle);
     if (r < 0) 
     {
         throw std::runtime_error(uv_strerror(r));
     }
     self.reset();
 }
Example #4
0
static void delete_timer(lcb_io_opt_t iobase, void *timer_opaque)
{
    my_timer_t *timer = (my_timer_t *)timer_opaque;

    uv_timer_stop(&timer->uvt);
    timer->callback = NULL;

    (void)iobase;
}
void HTTPCURLRequest::retry() {
    // All batons get notified when the network status changed, but some of them
    // might not actually wait for the network to become available again.
    if (timer && strategy == PreemptImmediately) {
        // Triggers the timer upon the next event loop iteration.
        uv_timer_stop(timer);
        uv_timer_start(timer, restart, 0, 0);
    }
}
Example #6
0
static void
invoke_task(uv_timer_t* timer, int unused)
{
  task_timer* t = (task_timer*)timer->data;
  t->task(t->data);
  t->dtor(t->data);
  uv_timer_stop(timer);
  free(t);
}
Example #7
0
static void timer_cb(uv_timer_t* handle, int status) {
    ASSERT(handle == &timer_handle);
    ASSERT(status == 0);
    timer_called++;
    if (timer_called == 1)
        uv_stop(uv_default_loop());
    else if (timer_called == num_ticks)
        uv_timer_stop(handle);
}
Example #8
0
LWS_VISIBLE LWS_EXTERN void
lws_email_destroy(struct lws_email *email)
{
	if (email->content)
		lws_free_set_NULL(email->content);

	uv_timer_stop(&email->timeout_email);
	uv_close((uv_handle_t *)&email->timeout_email, NULL);
}
Example #9
0
static void del_timer(void *glue_data, void *id)
{
    tmr_t *t = (tmr_t *)id;

    IOT_UNUSED(glue_data);

    uv_timer_stop(&t->uv_tmr);
    iot_free(t);
}
Example #10
0
static void on_get_host_addrs_(uv_getaddrinfo_t *req, int status, struct addrinfo *addrs)
{
  wsn_client_ctx_t *client = CONTAINER_OF(req, wsn_client_ctx_t, getaddrinfo_req);

  uv_timer_stop(&client->timer_handle);
  
  if (status < 0) {
    wsn_report_err(WSN_ERR_GET_ADDR_INFO, "Failed to getaddrinfo for client to (\"%s\"): %s",
                   client->conf->host, uv_strerror(status));
    uv_freeaddrinfo(addrs);
    return;
  }

  int ipv4_naddrs = 0;
  int ipv6_naddrs = 0;
  for (struct addrinfo *ai = addrs; ai != NULL; ai = ai->ai_next) {
    if (ai->ai_family == AF_INET) {
      ipv4_naddrs += 1;
    } else if (ai->ai_family == AF_INET6) {
      ipv6_naddrs += 1;
    }
  }

  if (ipv4_naddrs == 0 && ipv6_naddrs == 0) {
    wsn_report_err(WSN_ERR_GET_ADDR_INFO, "Remote host (\"%s\") has no IPv4/6 addresses",
                   client->conf->host);
    uv_freeaddrinfo(addrs);
    return;
  }

  union {
    struct sockaddr addr;
    struct sockaddr_in addr4;
    struct sockaddr_in6 addr6;
  } s;
  
  for (struct addrinfo *ai = addrs; ai != NULL; ai = ai->ai_next) {
    if (ai->ai_family == AF_INET) {
      s.addr4 = *(const struct sockaddr_in *) ai->ai_addr;
      s.addr4.sin_port = htons(client->conf->port);
    } else if (ai->ai_family == AF_INET6) {
      s.addr6 = *(const struct sockaddr_in6 *) ai->ai_addr;
      s.addr6.sin6_port = htons(client->conf->port);
    } else {
      continue;
    }
    client->host_addr = s.addr;
    break;
  }

  uv_freeaddrinfo(addrs);
  
  if (wsn_client_start_connect_(client) != 0) {
    uv_stop(client->loop);
    return;
  }
}
Example #11
0
void HTTPRequest::removeBackoffTimer() {
    assert(uv_thread_self() == thread_id);
    if (backoff_timer) {
        delete static_cast<RetryBaton *>(backoff_timer->data);
        uv_timer_stop(backoff_timer);
        uv_close((uv_handle_t *)backoff_timer, [](uv_handle_t *handle) { delete (uv_timer_t *)handle; });
        backoff_timer = nullptr;
    }
}
Example #12
0
static int lua_timer_stop(lua_State * L)
{
	int ret = -1;
	luatimer_t * tm = (luatimer_t *)luaL_checkudata(L, 1,UVLUA_TIMER_CLS);
	if(NULL != tm){
		ret = uv_timer_stop(&tm->timer);
	}
	lua_pushinteger(L,ret);
	return 1;
}
Example #13
0
static void mod_timer(void *glue_data, void *id, unsigned int msecs)
{
    uv_glue_t *uv = (uv_glue_t *)glue_data;
    tmr_t     *t = (tmr_t *)id;

    uv_timer_stop(&t->uv_tmr);
    uv_timer_init(uv->uv, &t->uv_tmr);
    t->uv_tmr.data = t;
    uv_timer_start(&t->uv_tmr, timer_cb, msecs, msecs);
}
Example #14
0
static void
elops_destroy_pt_uv(struct lws_context *context, int tsi)
{
	struct lws_context_per_thread *pt = &context->pt[tsi];
	int m, ns;

	lwsl_info("%s: %d\n", __func__, tsi);

	if (!lws_check_opt(context->options, LWS_SERVER_OPTION_LIBUV))
		return;

	if (!pt->uv.io_loop)
		return;

	if (pt->event_loop_destroy_processing_done)
		return;

	pt->event_loop_destroy_processing_done = 1;

	if (!pt->event_loop_foreign) {
		uv_signal_stop(&pt->w_sigint.uv.watcher);

		ns = LWS_ARRAY_SIZE(sigs);
		if (lws_check_opt(context->options,
				  LWS_SERVER_OPTION_UV_NO_SIGSEGV_SIGFPE_SPIN))
			ns = 2;

		for (m = 0; m < ns; m++) {
			uv_signal_stop(&pt->uv.signals[m]);
			uv_close((uv_handle_t *)&pt->uv.signals[m],
				 lws_uv_close_cb_sa);
		}
	} else
		lwsl_debug("%s: not closing pt signals\n", __func__);

	uv_timer_stop(&pt->uv.timeout_watcher);
	uv_close((uv_handle_t *)&pt->uv.timeout_watcher, lws_uv_close_cb_sa);
	uv_timer_stop(&pt->uv.hrtimer);
	uv_close((uv_handle_t *)&pt->uv.hrtimer, lws_uv_close_cb_sa);

	uv_idle_stop(&pt->uv.idle);
	uv_close((uv_handle_t *)&pt->uv.idle, lws_uv_close_cb_sa);
}
Example #15
0
void
lws_libuv_destroyloop(struct lws_context *context, int tsi)
{
	struct lws_context_per_thread *pt = &context->pt[tsi];
//	struct lws_context *ctx;
	int m, budget = 100, ns;

	if (!lws_check_opt(context->options, LWS_SERVER_OPTION_LIBUV))
		return;

	if (!pt->io_loop_uv)
		return;

	lwsl_notice("%s: closing signals + timers context %p\n", __func__, context);

	if (context->use_ev_sigint) {
		uv_signal_stop(&pt->w_sigint.uv_watcher);

		ns = ARRAY_SIZE(sigs);
		if (lws_check_opt(context->options, LWS_SERVER_OPTION_UV_NO_SIGSEGV_SIGFPE_SPIN))
			ns = 2;

		for (m = 0; m < ns; m++) {
			uv_signal_stop(&pt->signals[m]);
			uv_close((uv_handle_t *)&pt->signals[m], lws_uv_close_cb);
		}
	}

	uv_timer_stop(&pt->uv_timeout_watcher);
	uv_close((uv_handle_t *)&pt->uv_timeout_watcher, lws_uv_close_cb);

	uv_idle_stop(&pt->uv_idle);
	uv_close((uv_handle_t *)&pt->uv_idle, lws_uv_close_cb);

	if (pt->ev_loop_foreign)
		return;

	while (budget-- && uv_run(pt->io_loop_uv, UV_RUN_NOWAIT))
		;

	lwsl_notice("%s: closing all loop handles context %p\n", __func__, context);

	uv_stop(pt->io_loop_uv);

	uv_walk(pt->io_loop_uv, lws_uv_walk_cb, NULL);

	while (uv_run(pt->io_loop_uv, UV_RUN_NOWAIT))
		;
#if UV_VERSION_MAJOR > 0
	m = uv_loop_close(pt->io_loop_uv);
	if (m == UV_EBUSY)
		lwsl_err("%s: uv_loop_close: UV_EBUSY\n", __func__);
#endif
	lws_free(pt->io_loop_uv);
}
Example #16
0
void EventServer::remove_timer(int64_t handle) {
  CHECK_EQ(std::this_thread::get_id(), thread_id_);

  auto es_handle = timer_handles_[handle];

  CHECK_EQ(0, uv_timer_stop(&es_handle->uv_handle));
  uv_close(reinterpret_cast<uv_handle_t*>(&es_handle->uv_handle),
           &EventServer::uv_close_cb);

  timer_handles_.erase(handle);
}
Example #17
0
void pc__timeout_cb(uv_timer_t* timeout_timer, int status) {
  uv_timer_stop(timeout_timer);
  pc_client_t *client = (pc_client_t *)timeout_timer->data;
  if(status == -1) {
    fprintf(stderr, "Pomelo timeout timer error, %s\n",
            uv_err_name(uv_last_error(client->uv_loop)));
  } else {
    fprintf(stderr, "Pomelo client heartbeat timeout.\n");
  }
  pc_client_stop(client);
}
Example #18
0
// Finish writing all data from ClientRequest Stream
void iotjs_https_finish_request(iotjs_https_t* https_data) {
  IOTJS_VALIDATED_STRUCT_METHOD(iotjs_https_t, https_data);
  _this->stream_ended = true;
  if (_this->request_done) {
    iotjs_https_cleanup(https_data);
  } else if (_this->is_stream_writable) {
    curl_easy_pause(_this->curl_easy_handle, CURLPAUSE_CONT);
    uv_timer_stop(&(_this->timeout));
    uv_timer_start(&(_this->timeout), iotjs_https_uv_timeout_callback, 1, 0);
  }
}
Example #19
0
int luv_timer_stop(lua_State* L) {
    uv_timer_t* handle = (uv_timer_t*)luv_checkudata(L, 1, "timer");

    int err = uv_timer_stop(handle);
    if (err < 0) {
        return luaL_error(L, "timer_stop: %s", uv_strerror(err));
    }
    luv_handle_unref(L, handle->data);

    return 0;
}
void SyncWorker::uv_process_timer_tick_callback( uv_timer_t * handle )
{
    SyncWorker* inst = static_cast< SyncWorker* >( handle->data );

    if ( inst == nullptr )
    {
        uv_timer_stop( handle );
        return;
    }

    inst->callback_( inst );

    ++inst->loop_count_;

    if ( inst->finished )
    {
        uv_timer_stop( &inst->timer_ );
        SAFE_DELETE( inst );
    }
}
Example #21
0
void pc__client_reconnected_cb(pc_connect_t* conn_req, int status) {
  pc_client_t* client = conn_req->client;
  client->reconnecting = 0;
  uv_timer_stop(&client->reconnect_timer);
  if (status == 0) {
    client->reconnects = 0;
    pc_emit_event(client, PC_EVENT_RECONNECT, client);
  } else {
    pc_client_stop(client);
  }
}
Example #22
0
/*
 * Class:     com_oracle_libuv_handles_TimerHandle
 * Method:    _stop
 * Signature: (J)I
 */
JNIEXPORT jint JNICALL Java_com_oracle_libuv_handles_TimerHandle__1stop
  (JNIEnv *env, jobject that, jlong timer) {

  assert(timer);
  uv_timer_t* handle = reinterpret_cast<uv_timer_t*>(timer);
  int r = uv_timer_stop(handle);
  if (r) {
    ThrowException(env, handle->loop, "uv_timer_stop");
  }
  return r;
}
Example #23
0
void start_timeout(CURLM *multi, long timeout_ms, void *userp) {
	Mathilda *m = (Mathilda *) userp;
	uv_timer_stop(&m->timeout);

	if(timeout_ms > 0) {
		m->timeout.data = m;
		uv_timer_start(&m->timeout, (uv_timer_cb) on_timeout, timeout_ms, 0);
	} else {
		on_timeout(&m->timeout);
	}
}
Example #24
0
static int timer_final1(void* vparam) {
  timer_param_t* param = (timer_param_t*)vparam;

  TUV_ASSERT(order_cb_called == 2);

  TUV_ASSERT(0 == uv_timer_stop(&param->handle_a));
  TUV_ASSERT(0 == uv_timer_stop(&param->handle_b));

  /* Test for starting handle_b then handle_a */
  order_cb_called = 0;
  param->handle_b.data = &param->first;
  TUV_ASSERT(0 == uv_timer_start(&param->handle_b, order_cb_b, 0, 0));

  param->handle_a.data = &param->second;
  TUV_ASSERT(0 == uv_timer_start(&param->handle_a, order_cb_a, 0, 0));

  tuv_run(param->loop, timer_loop, timer_final2, param);

  return 1; // don't clear loop param info
}
Example #25
0
int uv_timer_again(uv_timer_t* handle) {
  if (handle->timer_cb == NULL)
    return UV_EINVAL;

  if (handle->repeat) {
    uv_timer_stop(handle);
    uv_timer_start(handle, handle->timer_cb, handle->repeat, handle->repeat);
  }

  return 0;
}
Example #26
0
int uv_timer_again(uv_timer_t* handle) {
  if (handle->timer_cb == NULL)
    return uv__set_artificial_error(handle->loop, UV_EINVAL);

  if (handle->repeat) {
    uv_timer_stop(handle);
    uv_timer_start(handle, handle->timer_cb, handle->repeat, handle->repeat);
  }

  return 0;
}
Example #27
0
void uv__run_timers(uv_loop_t* loop) {
  uv_timer_t* handle;

  while ((handle = RB_MIN(uv__timers, &loop->timer_handles))) {
    if (handle->timeout > loop->time) break;

    uv_timer_stop(handle);
    uv_timer_again(handle);
    handle->timer_cb(handle, 0);
  }
}
Example #28
0
static void uv_finit(void)
{
	//uv_unref((uv_handle_t*)&g_timer);
	uv_timer_stop(&g_timer);
	uv_stop(&g_loop);
	uv_async_init(&g_loop, &g_async, NULL);
	uv_async_send(&g_async);
	uv_thread_join(&g_loop_thread);
	if (g_sys) delete g_sys;
	//if (g_remote) delete g_remote;
}
Example #29
0
bool Client::disconnect()
{
#   ifndef XMRIG_PROXY_PROJECT
    uv_timer_stop(&m_keepAliveTimer);
#   endif

    m_expire   = 0;
    m_failures = -1;

    return close();
}
int HTTPCURLContext::startTimeout(CURLM * /* multi */, long timeout_ms, void *userp) {
    assert(userp);
    auto context = reinterpret_cast<HTTPCURLContext *>(userp);
    MBGL_VERIFY_THREAD(context->tid);
    if (timeout_ms < 0) {
        // A timeout of 0 ms means that the timer will invoked in the next loop iteration.
        timeout_ms = 0;
    }
    uv_timer_stop(context->timeout);
    uv_timer_start(context->timeout, onTimeout, timeout_ms, 0);
    return 0;
}