Esempio n. 1
0
static void read_server_setup_reply_cb(EV_P_ ev_io *w, int revents) {
    struct connstate *connstate = (struct connstate *)w->data;
    xcb_setup_failed_t setup_failed;
    must_read(readall_into(&setup_failed, sizeof(setup_failed), w->fd));

    switch (setup_failed.status) {
        case 0:
            errx(EXIT_FAILURE, "error authenticating at the X11 server");

        case 2:
            errx(EXIT_FAILURE, "two-factor auth not implemented");

        case 1:
            must_write(writeall(connstate->clientw->fd, &setup_failed, sizeof(xcb_setup_failed_t)));
            const size_t len = (setup_failed.length * 4);
            void *buf = smalloc(len);
            must_read(readall_into(buf, len, w->fd));
            must_write(writeall(connstate->clientw->fd, buf, len));
            free(buf);

            ev_set_cb(connstate->clientw, read_client_x11_packet_cb);
            ev_set_cb(connstate->serverw, read_server_x11_packet_cb);
            ev_io_start(EV_A_ connstate->clientw);
            break;

        default:
            errx(EXIT_FAILURE, "X11 protocol error: expected setup_failed.status in [0..2], got %d", setup_failed.status);
    }
}
Esempio n. 2
0
int fiber_sleep(uint32_t seconds, uint32_t useconds)
{
    if(!fiber_loop) {
        fiber_do_real_sleep(seconds, useconds);
        return FIBER_SUCCESS;
    }

    //this code should really use ev_timer_init(), but ev_timer_init has compile warnings.
    ev_timer timer_event = {};
    ev_set_cb(&timer_event, &timer_trigger);
    const double sleep_time = seconds + useconds * 0.000001;
    timer_event.at = sleep_time;
    timer_event.repeat = 0;

    fiber_spinlock_lock(&fiber_loop_spinlock);

    fiber_manager_t* const manager = fiber_manager_get();
    fiber_t* const this_fiber = manager->current_fiber;

    timer_event.data = this_fiber;

    ev_timer_start(fiber_loop, &timer_event);

    this_fiber->state = FIBER_STATE_WAITING;
    manager->spinlock_to_unlock = &fiber_loop_spinlock;

    fiber_manager_yield(manager);

    return FIBER_SUCCESS;
}
Esempio n. 3
0
int uv_tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb) {
  int r;

  assert(tcp->fd >= 0);

  if (tcp->delayed_error) {
    uv_err_new((uv_handle_t*)tcp, tcp->delayed_error);
    return -1;
  }

  r = listen(tcp->fd, backlog);
  if (r < 0) {
    uv_err_new((uv_handle_t*)tcp, errno);
    return -1;
  }

  tcp->connection_cb = cb;

  /* Start listening for connections. */
  ev_io_set(&tcp->read_watcher, tcp->fd, EV_READ);
  ev_set_cb(&tcp->read_watcher, uv__server_io);
  ev_io_start(EV_DEFAULT_ &tcp->read_watcher);

  return 0;
}
Esempio n. 4
0
File: udp.c Progetto: nuxleus/libuv
static void uv__udp_stop_watcher(uv_udp_t* handle, ev_io* w) {
  if (!ev_is_active(w)) return;
  ev_ref(handle->loop->ev);
  ev_io_stop(handle->loop->ev, w);
  ev_io_set(w, -1, 0);
  ev_set_cb(w, NULL);
}
Esempio n. 5
0
int fiber_wait_for_event(int fd, uint32_t events)
{
    ev_io fd_event = {};
    int poll_events = 0;
    if(events & FIBER_POLL_IN) {
        poll_events |= EV_READ;
    }
    if(events & FIBER_POLL_OUT) {
        poll_events |= EV_WRITE;
    }
    //this code should really use ev_io_init(), but ev_io_init has compile warnings.
    ev_set_cb(&fd_event, &fd_ready);
    ev_io_set(&fd_event, fd, poll_events);

    fiber_spinlock_lock(&fiber_loop_spinlock);

    fiber_manager_t* const manager = fiber_manager_get();
    manager->event_wait_count += 1;
    fiber_t* const this_fiber = manager->current_fiber;

    fd_event.data = this_fiber;
    ev_io_start(fiber_loop, &fd_event);

    this_fiber->state = FIBER_STATE_WAITING;
    manager->spinlock_to_unlock = &fiber_loop_spinlock;

    fiber_manager_yield(manager);

    return FIBER_SUCCESS;
}
Esempio n. 6
0
static void
send_request(struct ev_loop *loop, domain_t * domain) {

    debug("send_request %s, search = %s", domain->domain, search_path[domain->index_search]);

    char buf[MAXLINE];

    ev_io_set(&domain->io, domain->io.fd, EV_READ);
    ev_set_cb(&domain->io, recv_handler);

    ev_timer_set(&domain->tw, MAXRECVTIME, 0);


    size_t len = snprintf(buf, sizeof (buf), http_get, search_path[domain->index_search], domain->domain); /* this is safe */



    if (len == writen(domain->io.fd, buf, len)) {

        //bzero(domain->data.buffer, sizeof(domain->data.buffer));
        domain->data.len = 0;

        ev_io_start(loop, &domain->io);
        ev_timer_start(loop, &domain->tw);

    } else {
        free_domain(domain);
    }
}
Esempio n. 7
0
void li_event_timer_init(liEventLoop *loop, liEventTimer *timer, liEventCallback callback) {
	memset(timer, 0, sizeof(*timer));
	timer->base.type = LI_EVT_TIMER;
	timer->base.keep_loop_alive = 1;
	timer->base.callback = callback;
	ev_init(&timer->libevmess.w, NULL);
	ev_set_cb(&timer->libevmess.timer, event_timer_cb);

	if (NULL != loop) li_event_attach(loop, timer);
}
Esempio n. 8
0
File: udp.c Progetto: nuxleus/libuv
static void uv__udp_start_watcher(uv_udp_t* handle,
                                  ev_io* w,
                                  void (*cb)(EV_P_ ev_io*, int),
                                  int flags) {
  if (ev_is_active(w)) return;
  ev_set_cb(w, cb);
  ev_io_set(w, handle->fd, flags);
  ev_io_start(handle->loop->ev, w);
  ev_unref(handle->loop->ev);
}
Esempio n. 9
0
File: io.c Progetto: erickt/libuv
void uv__io_watcher_stop(uv_handle_t* handle, uv_io_t* io, ev_io* w) {
  int flags;

  assert(w == &io->read_watcher || w == &io->write_watcher);
  flags = (w == &io->read_watcher ? EV_READ : EV_WRITE);

  ev_io_stop(handle->loop->ev, w);
  ev_io_set(w, -1, flags);
  ev_set_cb(w, NULL);
  w->data = (void*)0xDEADBABE;
}
Esempio n. 10
0
void li_event_check_init(liEventLoop *loop, liEventCheck *check, liEventCallback callback) {
	memset(check, 0, sizeof(*check));
	check->base.type = LI_EVT_CHECK;
	check->base.keep_loop_alive = 0;
	check->base.callback = callback;
	ev_init(&check->libevmess.w, NULL);
	ev_set_cb(&check->libevmess.check, event_check_cb);

	if (NULL != loop) li_event_attach(loop, check);
	li_event_start(check);
}
Esempio n. 11
0
void li_event_prepare_init(liEventLoop *loop, liEventPrepare *prepare, liEventCallback callback) {
	memset(prepare, 0, sizeof(*prepare));
	prepare->base.type = LI_EVT_PREPARE;
	prepare->base.keep_loop_alive = 0;
	prepare->base.callback = callback;
	ev_init(&prepare->libevmess.w, NULL);
	ev_set_cb(&prepare->libevmess.prepare, event_prepare_cb);

	if (NULL != loop) li_event_attach(loop, prepare);
	li_event_start(prepare);
}
Esempio n. 12
0
void li_event_async_init(liEventLoop *loop, liEventAsync *async, liEventCallback callback) {
	memset(async, 0, sizeof(*async));
	async->base.type = LI_EVT_ASYNC;
	async->base.keep_loop_alive = 0;
	async->base.callback = callback;
	ev_init(&async->libevmess.w, NULL);
	ev_set_cb(&async->libevmess.async, event_async_cb);

	if (NULL != loop) li_event_attach(loop, async);
	li_event_start(async);
}
Esempio n. 13
0
void li_event_signal_init(liEventLoop *loop, liEventSignal *sig, liEventCallback callback, int signum) {
	memset(sig, 0, sizeof(*sig));
	sig->base.type = LI_EVT_SIGNAL;
	sig->base.keep_loop_alive = 0;
	sig->base.callback = callback;
	ev_init(&sig->libevmess.w, NULL);
	ev_signal_set(&sig->libevmess.sig, signum);
	ev_set_cb(&sig->libevmess.sig, event_signal_cb);

	if (NULL != loop) li_event_attach(loop, sig);
	li_event_start(sig);
}
Esempio n. 14
0
void li_event_child_init(liEventLoop *loop, liEventChild *child, liEventCallback callback, int pid) {
	memset(child, 0, sizeof(*child));
	child->base.type = LI_EVT_CHILD;
	child->base.keep_loop_alive = 1;
	child->base.callback = callback;
	ev_init(&child->libevmess.w, NULL);
	ev_child_set(&child->libevmess.child, pid, 0);
	ev_set_cb(&child->libevmess.child, event_child_cb);

	if (NULL != loop) li_event_attach(loop, child);
	li_event_start(child);
}
Esempio n. 15
0
void li_event_io_init(liEventLoop *loop, liEventIO *io, liEventCallback callback, int fd, int events) {
	memset(io, 0, sizeof(*io));
	io->base.type = LI_EVT_IO;
	io->base.keep_loop_alive = 1;
	io->base.callback = callback;
	io->events = events;
	ev_init(&io->libevmess.w, NULL);
	ev_io_set(&io->libevmess.io, fd, io_events_to_libev(events));
	ev_set_cb(&io->libevmess.io, event_io_cb);

	if (NULL != loop) li_event_attach(loop, io);
}
Esempio n. 16
0
static void uv__udp_watcher_start(uv_udp_t* handle, ev_io* w) {
  int flags;

  assert(w == &handle->read_watcher
      || w == &handle->write_watcher);

  flags = (w == &handle->read_watcher ? EV_READ : EV_WRITE);

  w->data = handle;
  ev_set_cb(w, uv__udp_io);
  ev_io_set(w, handle->fd, flags);
  ev_io_start(handle->loop->ev, w);
}
Esempio n. 17
0
File: io.c Progetto: erickt/libuv
void uv__io_watcher_start(
    uv_handle_t* handle,
    uv_io_t* io,
    ev_io* w,
    uv_io_cb cb) {
  int flags;

  assert(w == &io->read_watcher || w == &io->write_watcher);
  flags = (w == &io->read_watcher ? EV_READ : EV_WRITE);

  w->data = handle;
  ev_set_cb(w, cb);
  ev_io_set(w, handle->fd, flags);
  ev_io_start(handle->loop->ev, w);
}
Esempio n. 18
0
void uv__udp_watcher_stop(uv_udp_t* handle, ev_io* w) {
  int flags;

  if (!ev_is_active(w)) {
    return;
  }

  assert(w == &handle->read_watcher
      || w == &handle->write_watcher);

  flags = (w == &handle->read_watcher ? EV_READ : EV_WRITE);

  ev_ref(handle->loop->ev);
  ev_io_stop(handle->loop->ev, w);
  ev_io_set(w, -1, flags);
  ev_set_cb(w, NULL);
  w->data = (void*)0xDEADBABE;
}
Esempio n. 19
0
static int fdevent_libev_poll(fdevents *ev, int timeout_ms) {
	union {
		struct ev_watcher w;
		struct ev_timer timer;
	} timeout_watcher;

	if (!timeout_ms) timeout_ms = 1;

	ev_init(&timeout_watcher.w, NULL);
	ev_set_cb(&timeout_watcher.timer, timeout_watcher_cb);
	timeout_watcher.timer.repeat = ((ev_tstamp) timeout_ms)/1000.0;
	assert(timeout_watcher.timer.repeat);
	ev_timer_again(ev->libev_loop, &timeout_watcher.timer);

	ev_loop(ev->libev_loop, EVLOOP_ONESHOT);

	ev_timer_stop(ev->libev_loop, &timeout_watcher.timer);

	return 0;
}
Esempio n. 20
0
int uv_tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb) {
  int r;

  if (tcp->delayed_error) {
    uv_err_new(tcp->loop, tcp->delayed_error);
    return -1;
  }

  if (tcp->fd < 0) {
    if ((tcp->fd = uv__socket(AF_INET, SOCK_STREAM, 0)) == -1) {
      uv_err_new(tcp->loop, errno);
      return -1;
    }

    if (uv__stream_open((uv_stream_t*)tcp, tcp->fd, UV_READABLE)) {
      uv__close(tcp->fd);
      tcp->fd = -1;
      return -1;
    }
  }

  assert(tcp->fd >= 0);

  r = listen(tcp->fd, backlog);
  if (r < 0) {
    uv_err_new(tcp->loop, errno);
    return -1;
  }

  tcp->connection_cb = cb;

  /* Start listening for connections. */
  ev_io_set(&tcp->read_watcher, tcp->fd, EV_READ);
  ev_set_cb(&tcp->read_watcher, uv__server_io);
  ev_io_start(tcp->loop->ev, &tcp->read_watcher);

  return 0;
}
Esempio n. 21
0
int uv_listen(uv_handle_t* handle, int backlog, uv_accept_cb cb) {
    assert(handle->fd >= 0);

    if (handle->delayed_error) {
        uv_err_new(handle, handle->delayed_error);
        return -1;
    }

    int r = listen(handle->fd, backlog);
    if (r < 0) {
        uv_err_new(handle, errno);
        return -1;
    }

    handle->accept_cb = cb;

    /* Start listening for connections. */
    ev_io_set(&handle->read_watcher, handle->fd, EV_READ);
    ev_set_cb(&handle->read_watcher, uv__server_io);
    ev_io_start(EV_DEFAULT_ &handle->read_watcher);

    return 0;
}