예제 #1
0
liMemcachedCon* li_memcached_con_new(liEventLoop *loop, liSocketAddress addr) {
	liMemcachedCon* con = g_slice_new0(liMemcachedCon);

	con->refcount = 1;
	con->addr = li_sockaddr_dup(addr);
	con->tmpstr = g_string_sized_new(511);

	con->fd = -1;
	li_event_io_init(loop, "memcached", &con->con_watcher, memcached_io_cb, -1, 0);
	li_event_set_keep_loop_alive(&con->con_watcher, FALSE);

	memcached_connect(con);

	return con;
}
예제 #2
0
liErrorPipe* li_error_pipe_new(liServer *srv, liErrorPipeCB cb, gpointer ctx) {
    liErrorPipe *epipe;
    int fds[2];

    if (-1 == pipe(fds)) {
        ERROR(srv, "Couldn't create pipe: %s", g_strerror(errno));
        return NULL;
    }

    epipe = g_slice_new0(liErrorPipe);
    epipe->srv = srv;
    epipe->cb = cb;
    epipe->ctx = ctx;
    li_event_io_init(&srv->loop, &epipe->fd_watcher, error_pipe_cb, fds[0], LI_EV_READ);
    epipe->fds[0] = fds[0];
    epipe->fds[1] = fds[1];

    li_fd_init(fds[0]);

    return epipe;
}