コード例 #1
0
ファイル: event.c プロジェクト: LiuFeiChen/olivehc
static int event_add(ohc_request_t *r, req_handler_f *handler, int event, time_t timeout)
{
	uint32_t epoll_ev = (event == OHC_EV_READ) ? EPOLLIN : EPOLLOUT;
	int epoll_fd = r->worker_thread ? r->worker_thread->epoll_fd : master_epoll_fd;
	ohc_timer_t *timer;

	if(r->events == event) {
		timer_update(&r->tnode, timeout);

	} else if(r->events) {
		if(epoll_mod(epoll_fd, r->sock_fd, epoll_ev, r) != 0) {
			return OHC_ERROR;
		}
		if(timer_update(&r->tnode, timeout) != 0) {
			return OHC_ERROR;
		}
	} else {
		timer = r->worker_thread ? &r->worker_thread->timer : &master_timer;
		if(epoll_add(epoll_fd, r->sock_fd, epoll_ev, r) != 0) {
			return OHC_ERROR;
		}
		if(timer_add(timer, &r->tnode, timeout) != 0) {
			return OHC_ERROR;
		}
	}

	r->events = event;
	r->event_handler = handler;
	return OHC_OK;
}
コード例 #2
0
ファイル: main.c プロジェクト: avtobiff/ombud
/**
 * Process read (client) command.
 */
static void
do_read_cmd (const int epollfd, struct command * command)
{
    uint8_t buf[BUFLEN] = { 0 };
    ssize_t readbytes;

    /* read command(s) from client */
    if ((readbytes = read (command->cfd, buf, BUFLEN)) <= 0) {
        if (readbytes == 0) {
            /* EOF, client closed socket */
            ;
        } else {
            perror ("ctrlsock read error");
        }
        close (command->cfd); /* also removes from epoll */
    }
    /* send from cache or defer relay */
    else {
        uint8_t **services = extract_cmds (buf);

        for (; services && *services; ++services) {
            uint8_t *service = *services;

            /* try sending from cache, upon miss defer remote host read */
            if (!cache_sendfile (command->cfd, service))
            {
                int rsock;
                if ((rsock = connect_remote_host (service, readbytes)) < 0) {
                    warn ("could not connect to host");
                    return;
                }

                struct command *newcmd = calloc (1, sizeof (struct command));
                /* add command to read remote host data to event queue */
                newcmd->cmd = READ_REMOTE;
                newcmd->cfd = command->cfd;
                newcmd->rfd = rsock;
                newcmd->service = service;

                /* add command to event queue */
                epoll_add (epollfd, newcmd);
            }
        }

        /* processed all commands, back to READ_CMD */
        struct command *readcmd = calloc (1, sizeof (struct command));

        readcmd->cmd = READ_CMD;
        readcmd->cfd = command->cfd;

        epoll_mod (epollfd, readcmd);
    }
}
コード例 #3
0
ファイル: vfs_so.c プロジェクト: zhangyinuo/otttt
void modify_fd_event(int fd, int events)
{
	events = EPOLLIN|events;
	epoll_mod(epfd, fd, events);
	LOG(glogfd, LOG_TRACE, "fd [%d] be modify!\n", fd);
}