コード例 #1
0
ファイル: ab_event.c プロジェクト: dracarys13/ab
int ab_event_poll(int timer) {

    int i;
    int rc;
    int events;
    ab_connection_t *c;

    rc = epoll_wait(ep, event_list, nevents, timer);
    ab_log_debug("ab_event.c->ab_event_poll->epoll_wait() return:%d", rc);
    if (-1 == rc) {
        if (EINTR == errno) {
            return 0;
        }
        ab_log_error("ab_event.c->ab_event_poll->epoll_wait() failed, return:%d, errno:%d", rc, errno);
        return -1;
    }

    for (i = 0; i < rc; i++) {
        c = event_list[i].data.ptr;
        events = event_list[i].events;
        if (events & EPOLLIN) {
            c->event_read = 1;
        }
        if (events & EPOLLOUT) {
            c->event_write = 1;
        }
        if (events & (EPOLLERR | EPOLLHUP)) {
            c->event_error = 1;
        }
        ab_connection_handler(c);
    }

    return 0;
}
コード例 #2
0
ファイル: ab_connection.c プロジェクト: lqhh/Apache-Benchmark
void
ab_connection_recv(ab_connection_t *c) {

    ab_buf_t *buf;
    int rc, n;

    buf = c->rcv_buf;
    while (1) {
        n = buf->last - buf->pos;
        if (n <= 0) {
            buf = ab_buf_enlarge(buf);
            if (buf == NULL) {
                ab_log_error("ab_buf_enlarge() failed %d", c->idx);
                c->error = 1;
                break;
            }
            /* recalucate available space */
            n = buf->last - buf->pos;
        }

        ab_log_debug("recv buf %d", n);
        rc = recv(c->fd, buf->pos, n, 0);
        
        if (rc == 0) {
            ab_log_info("server close connection %d", c->idx);
            c->closed = 1;
            break;
        }
        
        if (rc < 0) {
            if (errno != EAGAIN && errno != EINTR) {
                ab_log_error("recv(%d) failed", c->fd);
                c->error = 1;
            }
            break;
        }

        ab_log_debug("recv %d bytes", rc);

        /* rc > 0 */
        buf->pos += rc;
    }
}