Exemple #1
0
static void
libev_ctx_del(void *ctx, const verto_ev *ev, void *evpriv)
{
    switch (verto_get_type(ev)) {
        case VERTO_EV_TYPE_IO:
            ev_io_stop(ctx, evpriv);
            break;
        case VERTO_EV_TYPE_TIMEOUT:
            ev_timer_stop(ctx, evpriv);
            break;
        case VERTO_EV_TYPE_IDLE:
            ev_idle_stop(ctx, evpriv);
            break;
        case VERTO_EV_TYPE_SIGNAL:
            ev_signal_stop(ctx, evpriv);
            break;
        case VERTO_EV_TYPE_CHILD:
            ev_child_stop(ctx, evpriv);
            break;
        default:
            break;
    }

    free(evpriv);
}
Exemple #2
0
void ev_flux_stop (struct ev_loop *loop, struct ev_flux *w)
{
    ev_prepare_stop (loop, &w->prepare_w);
    ev_check_stop (loop, &w->check_w);
    ev_io_stop (loop, &w->io_w);
    ev_idle_stop (loop, &w->idle_w);
}
Exemple #3
0
void idle_cb(struct ev_loop *loop, ev_idle *w, int revents)
{
    int listsize;
    

    listsize=PyList_Size(pydeferqueue);
    if (listsize>0)
    {
        PyObject *pyelem=PySequence_GetItem(pydeferqueue,0); 
        PyObject *pyfct=PySequence_GetItem(pyelem,0);
        PyObject *pyfctargs=PySequence_GetItem(pyelem,1);
        //execute the python code
        if (debug) printf("Execute 1 python function in defer mode:%i\n", listsize);
        PyObject *response = PyObject_CallFunctionObjArgs(pyfct, pyfctargs, NULL); 
        if (response==NULL) 
        {
            printf("ERROR!!!! Defer callback function as a problem. \nI remind that it takes always one argumet\n");
            PyErr_Print();
            //exit(1);
        }
        Py_XDECREF(response);
        Py_DECREF(pyfct);
        Py_DECREF(pyfctargs);
        Py_DECREF(pyelem);
        //remove the element
        PySequence_DelItem(pydeferqueue,0); // don't ask me why, but the delitem has to be after the decrefs
    } else
    {
        //stop idle if queue is empty
        if (debug) printf("stop ev_idle\n");
        ev_idle_stop(loop, w);
        Py_DECREF(pydeferqueue);
        pydeferqueue=NULL;
    }
}
Exemple #4
0
static void
eio_on_done_poll (EV_P_ ev_async *watcher, int revents)
{
	manos_data_t *data = (manos_data_t *) watcher->data;
	if (eio_poll () != -1)
		ev_idle_stop (EV_A_ &eio_idle_watcher);
}
Exemple #5
0
static void
IO_connfailimmediate_callback(struct ev_loop *loop,
			      ev_idle *watcher,
			      int revents)
{
	AsyncIO *IO = watcher->data;

	SetEVState(IO, eIOConnfailNow);
	SET_EV_TIME(IO, event_base);
	ev_idle_stop (event_base, &IO->conn_fail_immediate);

	if (IO->SendBuf.fd != 0)
	{
		close(IO->SendBuf.fd);
		IO->SendBuf.fd = IO->RecvBuf.fd = 0;
	}
	become_session(IO->CitContext);

	assert(IO->ConnFail);
	switch (IO->ConnFail(IO))
	{
	case eAbort:
		ShutDownCLient(IO);
	default:
		break;

	}
}
Exemple #6
0
void uv__finish_close(uv_handle_t* handle) {
    assert(uv_flag_is_set(handle, UV_CLOSING));
    assert(!uv_flag_is_set(handle, UV_CLOSED));
    uv_flag_set(handle, UV_CLOSED);

    switch (handle->type) {
    case UV_TCP:
        /* XXX Is it necessary to stop these watchers here? weren't they
         * supposed to be stopped in uv_close()?
         */
        ev_io_stop(EV_DEFAULT_ &handle->write_watcher);
        ev_io_stop(EV_DEFAULT_ &handle->read_watcher);

        assert(!ev_is_active(&handle->read_watcher));
        assert(!ev_is_active(&handle->write_watcher));

        close(handle->fd);
        handle->fd = -1;

        if (handle->accepted_fd >= 0) {
            close(handle->accepted_fd);
            handle->accepted_fd = -1;
        }
        break;

    case UV_PREPARE:
        assert(!ev_is_active(&handle->prepare_watcher));
        break;

    case UV_CHECK:
        assert(!ev_is_active(&handle->check_watcher));
        break;

    case UV_IDLE:
        assert(!ev_is_active(&handle->idle_watcher));
        break;

    case UV_ASYNC:
        assert(!ev_is_active(&handle->async_watcher));
        break;

    case UV_TIMER:
        assert(!ev_is_active(&handle->timer_watcher));
        break;

    default:
        assert(0);
        break;
    }

    ev_idle_stop(EV_DEFAULT_ &handle->next_watcher);

    if (handle->close_cb) {
        handle->close_cb(handle, 0);
    }

    ev_unref(EV_DEFAULT_UC);
}
Exemple #7
0
void uv__finish_close(uv_handle_t* handle) {
    uv_loop_t* loop = handle->loop;

    assert(handle->flags & UV_CLOSING);
    assert(!(handle->flags & UV_CLOSED));
    handle->flags |= UV_CLOSED;

    switch (handle->type) {
    case UV_PREPARE:
        assert(!ev_is_active(&((uv_prepare_t*)handle)->prepare_watcher));
        break;

    case UV_CHECK:
        assert(!ev_is_active(&((uv_check_t*)handle)->check_watcher));
        break;

    case UV_IDLE:
        assert(!ev_is_active(&((uv_idle_t*)handle)->idle_watcher));
        break;

    case UV_ASYNC:
        assert(!ev_is_active(&((uv_async_t*)handle)->async_watcher));
        break;

    case UV_TIMER:
        assert(!ev_is_active(&((uv_timer_t*)handle)->timer_watcher));
        break;

    case UV_NAMED_PIPE:
    case UV_TCP:
        assert(!ev_is_active(&((uv_stream_t*)handle)->read_watcher));
        assert(!ev_is_active(&((uv_stream_t*)handle)->write_watcher));
        break;

    case UV_UDP:
        assert(!ev_is_active(&((uv_udp_t*)handle)->read_watcher));
        assert(!ev_is_active(&((uv_udp_t*)handle)->write_watcher));
        assert(((uv_udp_t*)handle)->fd == -1);
        uv__udp_destroy((uv_udp_t*)handle);
        break;

    case UV_PROCESS:
        assert(!ev_is_active(&((uv_process_t*)handle)->child_watcher));
        break;

    default:
        assert(0);
        break;
    }

    ev_idle_stop(loop->ev, &handle->next_watcher);

    if (handle->close_cb) {
        handle->close_cb(handle);
    }

    ev_unref(loop->ev);
}
Exemple #8
0
static void
defer_free(struct pa_defer_event *ev)
{
	lem_debug("freeing event %p", ev);
	if (ev->destroy)
		ev->destroy(&loop_api, ev, ev->w.data);
	ev_idle_stop(LEM_ &ev->w);
	free(ev);
}
Exemple #9
0
void
manos_shutdown (manos_data_t *data)
{
	ev_async_stop (data->loop, &eio_want_poll_watcher);
	ev_async_stop (data->loop, &eio_done_poll_watcher);
	ev_idle_stop (data->loop, &eio_idle_watcher);

	free (data);
}
Exemple #10
0
/**
 * Stops the idle so it won't be called by the specified event loop.
 *
 * Usage:
 *     idle:stop(loop)
 *
 * [+0, -0, e]
 */
static int idle_stop(lua_State *L) {
    ev_idle*        idle   = check_idle(L, 1);
    struct ev_loop* loop   = *check_loop_and_init(L, 2);

    loop_stop_watcher(L, 2, 1);
    ev_idle_stop(loop, idle);

    return 0;
}
Exemple #11
0
/*---------------------------Idle------------------------*/
static void Idle (struct ev_loop *loop, ev_idle *w, int revents) {
	if (SHUTDOWN) {
		LogDebug("Idle processing (SHUTDOWN=%d)", SHUTDOWN);
		ev_idle_stop(loop, w);
		ev_unloop (loop, EVUNLOOP_ALL);
	} else {
		ev_tstamp yieldtime = 0.10;
		ev_sleep(yieldtime);
	}
}
Exemple #12
0
int uv_idle_stop(uv_idle_t* idle) {
  int was_active = ev_is_active(&idle->idle_watcher);

  ev_idle_stop(idle->loop->ev, &idle->idle_watcher);

  if (was_active) {
    ev_ref(idle->loop->ev);
  }

  return 0;
}
Exemple #13
0
static void
defer_enable(struct pa_defer_event *ev, int b)
{
	if (b) {
		lem_debug("starting");
		ev_idle_start(LEM_ &ev->w);
	} else {
		lem_debug("stopping");
		ev_idle_stop(LEM_ &ev->w);
	}
}
Exemple #14
0
int uv_idle_stop(uv_handle_t* handle) {
    int was_active = ev_is_active(&handle->idle_watcher);

    ev_idle_stop(EV_DEFAULT_UC_ &handle->idle_watcher);

    if (was_active) {
        ev_ref(EV_DEFAULT_UC);
    }

    return 0;
}
Exemple #15
0
static void check_cb (struct ev_loop *loop, ev_check *w, int revents)
{
    struct ev_flux *fw = (struct ev_flux *)((char *)w
                            - offsetof (struct ev_flux, check_w));
    int events = get_pollevents (fw->h);

    ev_io_stop (loop, &fw->io_w);
    ev_idle_stop (loop, &fw->idle_w);

    if ((events & fw->events) || (events & EV_ERROR))
        fw->cb (loop, fw, events);
}
Exemple #16
0
void
DB_PerformNext(struct ev_loop *loop, ev_idle *watcher, int revents)
{
	AsyncIO *IO = watcher->data;

	SetEVState(IO, eDBNext);
	SET_EV_TIME(IO, event_db);
	EV_syslog(LOG_DEBUG, "%s()", __FUNCTION__);
	become_session(IO->CitContext);

	ev_idle_stop(event_db, &IO->db_unwind_stack);

	assert(IO->NextDBOperation);
	switch (IO->NextDBOperation(IO))
	{
	case eSendReply:
		ev_cleanup_stop(loop, &IO->db_abort_by_shutdown);
		QueueAnEventContext(IO);
		break;
	case eDBQuery:
		break;
	case eSendDNSQuery:
	case eReadDNSReply:
	case eConnect:
	case eSendMore:
	case eSendFile:
	case eReadMessage:
	case eReadMore:
	case eReadPayload:
	case eReadFile:
		ev_cleanup_stop(loop, &IO->db_abort_by_shutdown);
		break;
	case eTerminateConnection:
	case eAbort:
		ev_idle_stop(event_db, &IO->db_unwind_stack);
		ev_cleanup_stop(loop, &IO->db_abort_by_shutdown);
		ShutDownDBCLient(IO);
	}
}
Exemple #17
0
void StopClientWatchers(AsyncIO *IO, int CloseFD)
{
	EVM_syslog(LOG_DEBUG, "EVENT StopClientWatchers");
	
	DestructCAres(IO);

	ev_timer_stop (event_base, &IO->rw_timeout);
	ev_timer_stop(event_base, &IO->conn_fail);
	ev_idle_stop(event_base, &IO->unwind_stack);
	ev_cleanup_stop(event_base, &IO->abort_by_shutdown);

	ev_io_stop(event_base, &IO->conn_event);
	ev_io_stop(event_base, &IO->send_event);
	ev_io_stop(event_base, &IO->recv_event);

	if (CloseFD && (IO->SendBuf.fd > 0)) {
		close(IO->SendBuf.fd);
		IO->SendBuf.fd = 0;
		IO->RecvBuf.fd = 0;
	}
}
Exemple #18
0
void StopCurlWatchers(AsyncIO *IO)
{
	EVM_syslog(LOG_DEBUG, "EVENT StopCurlWatchers \n");

	ev_timer_stop (event_base, &IO->rw_timeout);
	ev_timer_stop(event_base, &IO->conn_fail);
	ev_idle_stop(event_base, &IO->unwind_stack);
	ev_cleanup_stop(event_base, &IO->abort_by_shutdown);

	ev_io_stop(event_base, &IO->conn_event);
	ev_io_stop(event_base, &IO->send_event);
	ev_io_stop(event_base, &IO->recv_event);

	curl_easy_cleanup(IO->HttpReq.chnd);
	IO->HttpReq.chnd = NULL;

	if (IO->SendBuf.fd != 0) {
		close(IO->SendBuf.fd);
	}
	IO->SendBuf.fd = 0;
	IO->RecvBuf.fd = 0;
}
Exemple #19
0
static void
repeat (EV_P_ ev_idle *w, int revents)
{
  if (eio_poll () != -1)
    ev_idle_stop (EV_A_ w);
}
Exemple #20
0
Fichier : lem.c Projet : esmil/lem
static void
runqueue_pop(EV_P_ struct ev_idle *w, int revents)
{
	struct lem_runqueue_slot *slot;
	lua_State *T;
	int nargs;

	(void)revents;

	if (rq.first == rq.last) { /* queue is empty */
		lem_debug("runqueue is empty, collecting..");
#if 0
		if (lua_gc(L, LUA_GCSTEP, 0)) {
			lem_debug("done collecting");
			ev_idle_stop(EV_A_ w);
		}
#else
		ev_idle_stop(EV_A_ w);
		lua_gc(L, LUA_GCCOLLECT, 0);
#endif
		return;
	}

	lem_debug("running thread...");

	slot = &rq.queue[rq.first];
	T = slot->T;
	nargs = slot->nargs;

	rq.first++;
	rq.first &= rq.mask;

	/* run Lua thread */
	switch (lua_resume(T, NULL, nargs)) {
	case LUA_OK: /* thread finished successfully */
		lem_debug("thread finished successfully");
		lem_forgetthread(T);
		return;

	case LUA_YIELD: /* thread yielded */
		lem_debug("thread yielded");
		return;

	case LUA_ERRERR: /* error running error handler */
		lem_debug("thread errored while running error handler");
	case LUA_ERRGCMM:
		lem_debug("error in __gc metamethod");
	case LUA_ERRRUN: /* runtime error */
		lem_debug("thread errored");
		thread_error(T);
		break;

	case LUA_ERRMEM: /* out of memory */
		oom();

	default: /* this shouldn't happen */
		lem_debug("lua_resume: unknown error");
		lua_pushliteral(L, "unknown error");
		break;
	}
	lem_exit(EXIT_FAILURE);
}
Exemple #21
0
static void idle_stop (void *impl, flux_watcher_t *w)
{
    assert (w->signature == IDLE_SIG);
    ev_idle_stop (w->r->loop, (ev_idle *)impl);
}
Exemple #22
0
 ~RunOnceEvent() {
   struct ev_loop *loop = EV_DEFAULT;
   ev_idle_stop(EV_A_ &event);
 }
Exemple #23
0
static void
eio_on_idle (EV_P_ ev_idle *watcher, int revents)
{
	if (eio_poll () != -1)
		ev_idle_stop (EV_A_ watcher);
}
Exemple #24
0
void StopDBWatchers(AsyncIO *IO)
{
	SetEVState(IO, eDBStop);
	ev_cleanup_stop(event_db, &IO->db_abort_by_shutdown);
	ev_idle_stop(event_db, &IO->db_unwind_stack);
}
Exemple #25
0
Fichier : lem.c Projet : halfd/lem
static void
runqueue_pop(EV_P_ struct ev_idle *w, int revents)
{
	struct lem_runqueue_slot *slot;
	lua_State *T;
	int nargs;

	(void)revents;

	if (rq.first == rq.last) { /* queue is empty */
		lem_debug("runqueue is empty, collecting..");
#if 0
		if (lua_gc(L, LUA_GCSTEP, 0)) {
			lem_debug("done collecting");
			ev_idle_stop(EV_A_ w);
		}
#else
		ev_idle_stop(EV_A_ w);
		lua_gc(L, LUA_GCCOLLECT, 0);
#endif
		return;
	}

	lem_debug("running thread...");

	slot = &rq.queue[rq.first];
	T = slot->T;
	nargs = slot->nargs;

	rq.first++;
	rq.first &= rq.mask;

	/* run Lua thread */
#if LUA_VERSION_NUM >= 502
	switch (lua_resume(T, NULL, nargs)) {
#else
	switch (lua_resume(T, nargs)) {
#endif
	case LUA_OK: /* thread finished successfully */
		lem_debug("thread finished successfully");
		lem_forgetthread(T);
		return;

	case LUA_YIELD: /* thread yielded */
		lem_debug("thread yielded");
		return;

	case LUA_ERRERR: /* error running error handler */
		lem_debug("thread errored while running error handler");
#if LUA_VERSION_NUM >= 502
	case LUA_ERRGCMM:
		lem_debug("error in __gc metamethod");
#endif
	case LUA_ERRRUN: /* runtime error */
		lem_debug("thread errored");
		thread_error(T);
		break;

	case LUA_ERRMEM: /* out of memory */
		oom();

	default: /* this shouldn't happen */
		lem_debug("lua_resume: unknown error");
		lua_pushliteral(L, "unknown error");
		break;
	}
	lem_exit(EXIT_FAILURE);
}

#include "pool.c"

static int
queue_file(int argc, char *argv[], int fidx)
{
	lua_State *T = lem_newthread();
	const char *filename;
	int i;

	if (fidx < argc)
		filename = argv[fidx];
	else
		filename = LEM_LDIR "lem/repl.lua";

	switch (luaL_loadfile(T, filename)) {
	case LUA_OK: /* success */
		break;

	case LUA_ERRMEM:
		oom();

	default:
		lem_log_error("lem: %s", lua_tostring(T, 1));
		return -1;
	}

	lua_createtable(T, argc, 0);
	for (i = 0; i < argc; i++) {
		lua_pushstring(T, argv[i]);
		lua_rawseti(T, -2, i - fidx);
	}
	lua_setglobal(T, "arg");

	lem_queue(T, 0);
	return 0;
}