Ejemplo n.º 1
0
int
client_readn(int fd, char *buf, int datalen, int timeout)
{
    size_t nleft;
    ssize_t nread;
    char *ptr;

    ptr = buf;
    nleft = datalen;

    while (nleft > 0) {
        if (timeout > 0 && timeout_wait(fd, timeout, 1) == -1) {
            DERROR("read timeout\n");
            break;
        }
        if ((nread = read(fd, ptr, nleft)) == -1) {
            if (errno == EINTR) {
                nread = 0;
            } else {
                DERROR("readn error: %s\n", strerror(errno));
                return -1;
            }
        } else if (nread == 0) {
            DERROR("read 0, conn cloes\n");
            break;
        }
        nleft -= nread;
        ptr += nread;
    }

    return datalen-nleft;
}
Ejemplo n.º 2
0
int
client_writen(int fd, char *buf, size_t datalen, int timeout)
{
    size_t nleft;
    ssize_t nwritten;
    const char *ptr;

    ptr = buf;
    nleft = datalen;

    while (nleft > 0) {
        if (timeout > 0 && timeout_wait(fd, timeout, 0) == -1) {
            DERROR("write timeout\n");
            break;
        }
        if ((nwritten = write(fd, ptr, nleft)) <= 0) {
            if (nwritten < 0 && errno == EINTR) {
                nwritten = 0;
            } else {
                DERROR("writen error: %s\n", strerror(errno));
                return -1;
            }
        }

        nleft -= nwritten;
        ptr += nwritten;
    }

    return datalen-nleft;
}
Ejemplo n.º 3
0
int timer_test()
{
        int count = 0;

        for (count = 0; count < MAX_COUNT; ++count) {

                kprint("%d\r\n", count);
                usleep(PERIOD);

        }
        kprint("If numbers appeared every PERIOD,\r\n"
                "test passed succecfully\r\n");

        timeout_wait(0 == 0, 10 * PERIOD);
        kprint("first timeout_wait test\r\n");

        timeout_wait(1 == 0, 10 * PERIOD);
        kprint("second timeout_wait test\r\n");

        return 0;
}
Ejemplo n.º 4
0
int
timeout_wait_write(int fd, int timeout)
{
    return timeout_wait(fd, timeout, TRUE);
}
Ejemplo n.º 5
0
int
timeout_wait_read(int fd, int timeout)
{
    return timeout_wait(fd, timeout, FALSE);
}