Exemple #1
0
static void mgmt_event_handler(int accept_fd, int events, void *data)
{
    int fd, err;
    struct mgmt_task *mtask;

    fd = ipc_accept(accept_fd);
    if (fd < 0) {
        eprintf("failed to accept a socket\n");
        return;
    }

    err = ipc_perm(fd);
    if (err < 0) {
        eprintf("permission error\n");
        goto out;
    }

    err = set_non_blocking(fd);
    if (err) {
        eprintf("failed to set a socket non-blocking\n");
        goto out;
    }

    mtask = zalloc(sizeof(*mtask));
    if (!mtask) {
        eprintf("can't allocate mtask\n");
        goto out;
    }

    mtask->buf = zalloc(BUFSIZE);
    if (!mtask->buf) {
        eprintf("can't allocate mtask buffer\n");
        free(mtask);
        goto out;
    }

    mtask->bsize = BUFSIZE;
    mtask->mtask_state = MTASK_STATE_HDR_RECV;
    err = tgt_event_add(fd, EPOLLIN, mtask_handler, mtask);
    if (err) {
        eprintf("failed to add a socket to epoll %d\n", fd);
        free(mtask->buf);
        free(mtask);
        goto out;
    }

    return;
out:
    if (fd > 0)
        close(fd);

    return;
}
Exemple #2
0
static void mgmt_event_handler(int accept_fd, int events, void *data)
{
	int fd, err;
	struct mgmt_task *mtask;

	fd = ipc_accept(accept_fd);
	if (fd < 0) {
		eprintf("failed to accept a socket\n");
		return;
	}

	err = ipc_perm(fd);
	if (err < 0) {
		eprintf("permission error\n");
		goto out;
	}

	err = set_non_blocking(fd);
	if (err) {
		eprintf("failed to set a socket non-blocking\n");
		goto out;
	}

	mtask = mtask_alloc();
	if (!mtask)
		goto out;

	err = tgt_event_add(fd, EPOLLIN, mtask_recv_send_handler, mtask);
	if (err) {
		eprintf("failed to add a socket to epoll %d\n", fd);
		mtask_free(mtask);
		goto out;
	}

	return;
out:
	if (fd > 0)
		close(fd);

	return;
}