int stream_deactivate(struct stream_loop *loop, struct stream *s)
{
	struct ev_loop *el = loop->stream_loop;
	ev_io *ei = s->stream_watcher;

	stream_try_io_stop_read(loop, s);
	stream_try_io_stop_write(loop, s);
	s->events |= EV_CLOSE;
	ev_clear_pending(el, &ei[READ_WATCHER]);
	ev_clear_pending(el, &ei[WRITE_WATCHER]);
	if (!(s->events & EV_IN_CB))
		s->close_callback(s);

	return 0;
}
Exemple #2
0
static void
io_event(EV_P_ ev_io *watcher, int revents)
{
  evcom_descriptor *d = watcher->data;

#if EV_MULTIPLICITY
  assert(d->loop == loop);
#endif

  int r = OKAY;

  if (revents & EV_ERROR) {
    d->errorno = 1;
    r = close_asap(d);
  }

  while (r == OKAY && d->action && d->fd >= 0) {
    r = d->action(d);
  }

  if (d->fd < 0) {
    assert(d->action == NULL);
    ev_clear_pending(EV_A_ watcher);
    ev_io_stop(EV_A_ watcher);
    if (d->on_close) d->on_close(d);
  }
}
Exemple #3
0
/**
 * If the timer is pending, return the revents and clear the pending
 * status (so the timer callback won't be called).
 *
 * Usage:
 *   revents = timer:clear_pending(loop)
 *
 * [+1, -0, e]
 */
static int timer_clear_pending(lua_State *L) {
    ev_timer*       timer = check_timer(L, 1);
    struct ev_loop* loop   = *check_loop_and_init(L, 2);

    int revents = ev_clear_pending(loop, timer);
    if ( ! timer->repeat           &&
         ( revents & EV_TIMEOUT ) )
    {
        loop_stop_watcher(L, 2, 1);
    }

    lua_pushnumber(L, revents);
    return 1;
}
Exemple #4
0
/**
 * If the watcher is pending, return the revents and clear the pending
 * status (so the watcher callback won't be called).
 *
 * Usage:
 *   revents = watcher:clear_pending(loop)
 *
 * [+1, -0, e]
 */
static int watcher_clear_pending(lua_State *L) {
    lua_pushnumber(L, ev_clear_pending(*check_loop_and_init(L, 2), check_watcher(L, 1)));
    return 1;
}