Пример #1
0
void
lws_libuv_destroyloop(struct lws_context *context, int tsi)
{
	struct lws_context_per_thread *pt = &context->pt[tsi];
	int m;

	if (!(context->options & LWS_SERVER_OPTION_LIBUV))
		return;

	if (!pt->io_loop_uv)
		return;

	if (context->use_ev_sigint)
		uv_signal_stop(&pt->w_sigint.uv_watcher);
	for (m = 0; m < ARRAY_SIZE(sigs); m++)
		uv_signal_stop(&pt->signals[m]);
	if (!pt->ev_loop_foreign) {
		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));
		m = uv_loop_close(pt->io_loop_uv);
		if (m == UV_EBUSY)
			lwsl_debug("%s: uv_loop_close: UV_EBUSY\n", __func__);
		lws_free(pt->io_loop_uv);
	}
}
Пример #2
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);
}
Пример #3
0
static void term(void *const unused) {
	fprintf(stderr, "\nStopping StrongLink server...\n");

	uv_ref((uv_handle_t *)sigint);
	uv_signal_stop(sigint);
	async_close((uv_handle_t *)sigint);

	SLNRepoPullsStop(repo);
	HTTPServerClose(server_raw);
	HTTPServerClose(server_tls);

	uv_ref((uv_handle_t *)sigpipe);
	uv_signal_stop(sigpipe);
	uv_close((uv_handle_t *)sigpipe, NULL);
}
Пример #4
0
static int luv_signal_stop(lua_State* L) {
  uv_signal_t* handle = luv_check_signal(L, 1);
  int ret = uv_signal_stop(handle);
  if (ret < 0) return luv_error(L, ret);
  lua_pushinteger(L, ret);
  return 1;
}
Пример #5
0
void uv_signal_close(uv_loop_t* loop, uv_signal_t* handle) {
  uv_signal_stop(handle);

  if (handle->pending_signum == 0) {
    uv__handle_start(handle);
    uv_want_endgame(loop, (uv_handle_t*) handle);
  }
}
Пример #6
0
void Stop() {
	if(!isRunning) {
		return;
	}

	isRunning = false;

	uv_mutex_destroy(&notify_mutex);
	uv_signal_stop(&int_signal);
	uv_signal_stop(&term_signal);
	uv_close((uv_handle_t *) &async_handler, NULL);
	uv_cond_destroy(&notifyDeviceHandled);

	if (gRunLoop) {
		CFRunLoopStop(gRunLoop);
	}
}
Пример #7
0
/* u3_unix_ef_hold()
*/
void
u3_unix_ef_hold(void)
{
    u3_unix* unx_u = &u3_Host.unx_u;
    u3_usig* sig_u;

    for ( sig_u = unx_u->sig_u; sig_u; sig_u = sig_u->nex_u ) {
        uv_signal_stop(&sig_u->sil_u);
    }
}
Пример #8
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);
}
Пример #9
0
void skyray_process_watcher_stop(skyray_process_watcher_t *self)
{
    if (self->process->watcher) {
        self->process->watcher = NULL;
        skyray_sigchld_count --;
    }

    if (skyray_sigchld_count == 0) {
        uv_signal_stop(&skyray_sigchld);
    }
}
Пример #10
0
static void term(void *const unused) {
	fprintf(stderr, "\n");
	alogf("Stopping StrongLink server...\n");

	uv_ref((uv_handle_t *)sigint);
	uv_signal_stop(sigint);
	async_close((uv_handle_t *)sigint);

	SLNRepoPullsStop(repo);
	HTTPServerClose(server_raw);
	HTTPServerClose(server_tls);

	async_pool_enter(NULL);
	fflush(NULL); // Everything.
	async_pool_leave(NULL);

	uv_ref((uv_handle_t *)sigpipe);
	uv_signal_stop(sigpipe);
	uv_close((uv_handle_t *)sigpipe, NULL);
}
Пример #11
0
static int lluv_signal_stop(lua_State *L){
  lluv_handle_t *handle = lluv_check_signal(L, 1, LLUV_FLAG_OPEN);
  int err = uv_signal_stop(LLUV_H(handle, uv_signal_t));
  if(err < 0){
    return lluv_fail(L, handle->flags, LLUV_ERR_UV, err, NULL);
  }

  lluv_handle_unlock(L, handle, LLUV_LOCK_START);

  lua_settop(L, 1);
  return 1;
}
Пример #12
0
/* Closes the server socket and removes all clients from the
 * server. */
static void close_server_cb(uv_handle_t* server_handle)
{
	UvTcpServer* server = server_handle->data;

	/* Close all clients. */
	ArrayList_clear_tsafe(server->client_list);
	free(server->handle);
	server->handle = NULL;

	/* Stop signal handling. */
	uv_signal_stop(&server->sig_handle);
}
Пример #13
0
void signal_stop(void)
{
  uv_signal_stop(&sint);
  uv_signal_stop(&spipe);
  uv_signal_stop(&shup);
  uv_signal_stop(&squit);
  uv_signal_stop(&sterm);
  uv_signal_stop(&swinch);
#ifdef SIGPWR
  uv_signal_stop(&spwr);
#endif
}
Пример #14
0
static PyObject *
Signal_func_stop(Signal *self)
{
    int r;

    RAISE_IF_HANDLE_CLOSED(self, PyExc_HandleClosedError, NULL);

    r = uv_signal_stop((uv_signal_t *)UV_HANDLE(self));
    if (r != 0) {
        RAISE_UV_EXCEPTION(UV_HANDLE_LOOP(self), PyExc_SignalError);
        return NULL;
    }

    Py_RETURN_NONE;
}
static void
foreign_event_loop_cleanup_libuv(void)
{
	/* cleanup the foreign loop assets */

	uv_timer_stop(&timer_outer_uv);
	uv_close((uv_handle_t*)&timer_outer_uv, NULL);
	uv_signal_stop(&sighandler_uv);
	uv_close((uv_handle_t *)&sighandler_uv, NULL);

	uv_run(&loop_uv, UV_RUN_DEFAULT);
#if (UV_VERSION_MAJOR > 0) // Travis...
	uv_loop_close(&loop_uv);
#endif
}
Пример #16
0
int uv_signal_start(uv_signal_t* handle, uv_signal_cb signal_cb, int signum) {
  uv_err_t err;

  /* If the user supplies signum == 0, then return an error already. If the */
  /* signum is otherwise invalid then uv__signal_register will find out */
  /* eventually. */
  if (signum == 0) {
    uv__set_artificial_error(handle->loop, UV_EINVAL);
    return -1;
  }

  /* Short circuit: if the signal watcher is already watching {signum} don't */
  /* go through the process of deregistering and registering the handler. */
  /* Additionally, this avoids pending signals getting lost in the (small) */
  /* time frame that handle->signum == 0. */
  if (signum == handle->signum) {
    handle->signal_cb = signal_cb;
    return 0;
  }

  /* If the signal handler was already active, stop it first. */
  if (handle->signum != 0) {
    int r = uv_signal_stop(handle);
    /* uv_signal_stop is infallible. */
    assert(r == 0);
  }

  EnterCriticalSection(&uv__signal_lock);

  err = uv__signal_register(signum);
  if (err.code != UV_OK) {
    /* Uh-oh, didn't work. */
    handle->loop->last_err = err;
    LeaveCriticalSection(&uv__signal_lock);
    return -1;
  }

  handle->signum = signum;
  RB_INSERT(uv_signal_tree_s, &uv__signal_tree, handle);

  LeaveCriticalSection(&uv__signal_lock);

  handle->signal_cb = signal_cb;
  uv__handle_start(handle);

  return 0;
}
Пример #17
0
/* Stops the server.
 *
 * Parameters:
 * 		server: The UvTcpServer to stop.
 */
void UvTcpServer_stop(UvTcpServer* server)
{
	uv_async_t* wake_handle;
	if(server && server->handle && !uv_is_closing((uv_handle_t*)server->handle))
		uv_close((uv_handle_t*)server->handle, close_server_cb);

	wake_handle = malloc(sizeof(uv_async_t));
	if(wake_handle)
	{
		uv_signal_stop(&server->sig_handle);

		if(uv_async_init(server->loop, wake_handle, NULL) || uv_async_send(wake_handle))
			free(wake_handle);
		else
			uv_close((uv_handle_t*)wake_handle, free_wake_handle);
	}
}
Пример #18
0
/// Releases job control resources and terminates running jobs
void job_teardown(void)
{
  // Stop all jobs
  for (int i = 0; i < MAX_RUNNING_JOBS; i++) {
    Job *job;
    if ((job = table[i]) != NULL) {
      uv_kill(job->pid, SIGTERM);
      job->term_sent = true;
      job_stop(job);
    }
  }

  // Wait until all jobs are closed
  event_poll_until(-1, !stop_requests);
  uv_signal_stop(&schld);
  uv_close((uv_handle_t *)&schld, NULL);
  // Close the timer
  uv_close((uv_handle_t *)&job_stop_timer, NULL);
}
Пример #19
0
void App::onSignal(uv_signal_t *handle, int signum)
{
    switch (signum)
    {
    case SIGHUP:
        LOG_WARN("SIGHUP received, exiting");
        break;

    case SIGTERM:
        LOG_WARN("SIGTERM received, exiting");
        break;

    case SIGINT:
        LOG_WARN("SIGINT received, exiting");
        break;

    default:
        break;
    }

    uv_signal_stop(handle);
    m_self->close();
}
Пример #20
0
extern "C" int
rust_uv_signal_stop(uv_signal_t* handle) {
  return uv_signal_stop(handle);
}
Пример #21
0
static void signal_handler(uv_signal_t *handle, int signum)
{
	uv_stop(uv_default_loop());
	uv_signal_stop(handle);
}
Пример #22
0
 void _stop() noexcept {
     uv_signal_stop( this->handle());
 }
Пример #23
0
static void
close_signal() {
    for (int i = 0; i < 2; i++) {
        uv_signal_stop(&signals[i].sig);
    }
}
Пример #24
0
static void signal2_cb(uv_signal_t* handle, int signum) {
  ASSERT(signum == SIGUSR2);
  increment_counter(&signal2_cb_counter);
  uv_signal_stop(handle);
}
Пример #25
0
static void on_read( uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf)
{
#else
static void on_read( uv_stream_t* handle, ssize_t nread, uv_buf_t bufstruct)
{
	const uv_buf_t* buf = &bufstruct;
#endif
	strus_connection_t* conn = (strus_connection_t*)( handle->data);
	unsigned char* dp;
	unsigned int nn;
	unsigned int bufidx = 0;

	if (nread > 0)
	{
		switch (conn->state)
		{
			case CTX_READDATASIZE:
				dp = (unsigned char*)&conn->readbufsize + conn->hdrbytes;
				nn = (unsigned int)nread;
				if (nn > sizeof(int32_t) - conn->hdrbytes)
				{
					nn = sizeof(int32_t) - conn->hdrbytes;
				}
				conn->hdrbytes += nn;
				memcpy( dp, buf->base, nn);
				bufidx += nn;
				if (conn->hdrbytes == sizeof(int32_t))
				{
					conn->state = CTX_READDATA;
					conn->readbufsize = ntohl( conn->readbufsize);
					if (conn->readbufsize > CONNECTION_MAXBUFSIZE)
					{
						log_error_conn( conn, "request message size out of range");
						uv_close( (uv_handle_t*)handle, on_close);
						return;
					}
					conn->readbuf = (unsigned char*)malloc( conn->readbufsize);
					if (conn->readbuf == NULL)
					{
						log_error_conn( conn, "memory allocation error (request buffer)");
						uv_close( (uv_handle_t*)handle, on_close);
						return;
					}
				}
				else
				{
					return;
				}
				/*no break here!*/
			case CTX_READDATA:
				if (buf->len < nread)
				{
					nn = buf->len - bufidx;
				}
				else
				{
					nn = nread - bufidx;
				}
				if (nn > conn->readbufsize - conn->readbufpos)
				{
					log_error_conn( conn, "data size mismatch in request");
					uv_close( (uv_handle_t*)handle, on_close);
					return;
				}
				memcpy( conn->readbuf + conn->readbufpos, (unsigned char*)buf->base + bufidx, nn);
				conn->readbufpos += nn;
				if (conn->readbufpos < conn->readbufsize)
				{
					/* ... have to read more */
					return;
				}
				conn->state = CTX_PROCESS;
				uv_read_stop( handle);
				/*no break here!*/
			case CTX_PROCESS:
				push_work_queue( conn);
				break;
			case CTX_TERMINATED:
				log_error_conn( conn, "got request data after termination");
				uv_close( (uv_handle_t*)handle, on_close);
				break;
		}
	}
	else
	{
		if (nread == UV_EOF)
		{
#ifdef STRUS_LOWLEVEL_DEBUG
			log_message_conn( conn, "got eof");
#endif
			conn->state = CTX_TERMINATED;
			uv_shutdown( &conn->shutdown_req, handle, on_shutdown);
		}
		else
		{
			log_error_conn_sys( conn, "disconnected", nread);
			uv_close( (uv_handle_t*)handle, on_close);
		}
	}
}

static void on_connected( uv_stream_t* stream, int status)
{
	static int connection_id_cnt = 0;
	strus_connection_t* conn = 0;
	int res = 0;

	if (status != 0)
	{
		log_error_sys( "connection refused", status);
		return;
	}
	conn = (strus_connection_t*)calloc( 1, sizeof( strus_connection_t));
	if (!conn)
	{
		log_error( "connection refused: out of memory");
		goto ERROR_CLEANUP;
	}
	res = uv_tcp_init( stream->loop, &conn->tcp);
	if (res)
	{
		log_error_sys( "connection refused: init tcp context failed", res);
		goto ERROR_CLEANUP;
	}
	res = uv_accept( stream, (uv_stream_t*)&conn->tcp);
	if (res)
	{ 
		log_error_sys( "error in accept connection", res);
		goto ERROR_CLEANUP;
	}
	res = g_glbctx->init_handlerdata( &conn->handlerdata);
	if (res)
	{
		log_error( "error in initializing connection handler data");
		goto ERROR_CLEANUP;
	}
	conn->id = ++connection_id_cnt;
	conn->tcp.data = conn;
	uv_read_start((uv_stream_t*)&conn->tcp, on_alloc, on_read);
	return;

ERROR_CLEANUP:
	strus_free_connection( conn);
}

static void on_signal( uv_signal_t *handle, int signum)
{
	const char* msg = "received signal unknown";
	switch (signum)
	{
		case SIGINT:	msg = "received signal SIGINT"; break;
		case SIGILL:	msg = "received signal SIGILL"; break;
		case SIGABRT:	msg = "received signal SIGABRT"; break;
		case SIGFPE:	msg = "received signal SIGFPE"; break;
		case SIGSEGV:	msg = "received signal SIGSEGV"; break;
		case SIGTERM:	msg = "received signal SIGTERM"; break;
		case SIGHUP:	msg = "received signal SIGHUP"; break;
	}
	if (signum == SIGHUP)
	{
#ifdef STRUS_LOWLEVEL_DEBUG
		log_message( msg);
#endif
	}
	else
	{
		log_message( msg);
		log_message( "shutting down server now ...");
		uv_signal_stop( handle);
		uv_stop( g_server.loop);
	}
}


static void on_work( uv_work_t *req)
{
	strus_connection_t* conn = (strus_connection_t*)( req->data);
	int err = 0;
	uint32_t msghdr;

#ifdef STRUS_LOWLEVEL_DEBUG
	log_message_conn( conn, "started request");
	strus_hexdump( g_glbctx->logf, "REQUEST", conn->readbuf, conn->readbufpos);
#endif
	err = g_glbctx->request_handler(
		&conn->handlerdata, conn->readbuf, conn->readbufpos, sizeof(uint32_t), &conn->output, &conn->outputsize);
	if (err)
	{
		log_error_request( conn, (char*)conn->output);
		uv_close( (uv_handle_t*)&conn->tcp, on_close);
		return;
	}
	memset( &conn->write_req, 0, sizeof( conn->write_req));
	conn->write_req.data = conn;
	conn->write_reqbuf.base = (char*)conn->output;
	conn->write_reqbuf.len = conn->outputsize;
	msghdr = htonl( conn->outputsize - sizeof( uint32_t));
	memcpy( conn->write_reqbuf.base, &msghdr, sizeof( uint32_t));
}
Пример #26
0
 void _stop() {
     uv_signal_stop( &_handle );
 }
Пример #27
0
int broker_start_server(json_t *config) {
    json_incref(config);

    const char *httpHost = NULL;
    char httpPort[8];
    memset(httpPort, 0, sizeof(httpPort));
    {
        json_t *http = json_object_get(config, "http");
        if (http) {
            json_t *enabled = json_object_get(http, "enabled");
            if (!(enabled && json_boolean_value(enabled))) {
                json_decref(config);
                return 0;
            }
            httpHost = json_string_value(json_object_get(http, "host"));

            json_t *jsonPort = json_object_get(http, "port");
            if (jsonPort) {
                json_int_t p = json_integer_value(jsonPort);
                int len = snprintf(httpPort, sizeof(httpPort) - 1,
                                   "%" JSON_INTEGER_FORMAT, p);
                httpPort[len] = '\0';
            }
        }
    }

    int httpActive = 0;
    Server httpServer;
    uv_poll_t httpPoll;
    if (httpHost && httpPort[0] != '\0') {
        mbedtls_net_init(&httpServer.srv);
        httpServer.data_ready = broker_on_data_callback;

        httpActive = start_http_server(&httpServer, httpHost, httpPort,
                                       mainLoop, &httpPoll);
    }

    uv_signal_t sigInt;
    uv_signal_init(mainLoop, &sigInt);
    uv_signal_start(&sigInt, stop_server_handler, SIGINT);

    uv_signal_t sigTerm;
    uv_signal_init(mainLoop, &sigTerm);
    uv_signal_start(&sigTerm, stop_server_handler, SIGTERM);

//    upstream_connect_conn(&loop, "http://10.0.1.158:8080/conn", "dartbroker", "cbroker");

    if (httpActive) {
        uv_run(mainLoop, UV_RUN_DEFAULT);
    }

    uv_signal_stop(&sigInt);
    uv_signal_stop(&sigTerm);

    if (httpActive) {
        uv_poll_stop(&httpPoll);
    }
    uv_loop_close(mainLoop);
#if defined(__unix__) || defined(__APPLE__)
    if (mainLoop && mainLoop->watchers) {
        uv__free(mainLoop->watchers);
    }
#endif

    json_decref(config);
    return 0;
}
Пример #28
0
 error stop()
 {
     return error(uv_signal_stop(get()));
 }
Пример #29
0
void uv__process_close(uv_process_t* handle) {
  QUEUE_REMOVE(&handle->queue);
  uv__handle_stop(handle);
  if (QUEUE_EMPTY(&handle->loop->process_handles))
    uv_signal_stop(&handle->loop->child_watcher);
}
Пример #30
0
static void _SignalFunc(uv_signal_t * handle, int signum)
{
	PutLogList("(!) Shutting down...");
	uv_signal_stop(handle);
	OnDestroy();
}