Hi again

I've now rewritten my code, but it still returns instantly.


#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/poll.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>

int main () {
    int vcsa = open("/dev/vcsa", O_RDONLY);
    if (vcsa == -1) {
        printf("Error: %s\n", strerror(errno));
        exit(EXIT_FAILURE);
    }
    struct pollfd fd = {
        .fd = vcsa,
        .events = POLLIN
    };
    uint8_t header[4];
    for(int i = 0; i < 30; i++) {
        if (read(vcsa, header, sizeof(header)) == -1) {
            printf("Error: %s\n", strerror(errno));
            exit(EXIT_FAILURE);
        }
        if (lseek(vcsa, 0, SEEK_SET) == -1) {
            printf("Error: %s\n", strerror(errno));
            exit(EXIT_FAILURE);
        }
        if(poll(&fd, 1, -1) == -1) {
            printf("Error: %s\n", strerror(errno));
            exit(EXIT_FAILURE);
        }
        printf("%d header: %d, %d, %d, %d\n", fd.revents, header[0], header[1], header[2], header[3]);
    }
    printf("\nPOLLIN = %d POLLERR = %d\n", POLLIN, POLLERR);
    return 0;
}

I ran the program as root. The output looks like this:
9 header: 37, 100, 0, 35
1 header: 37, 100, 0, 35
1 header: 37, 100, 0, 35
1 header: 37, 100, 0, 35
...
POLLERR = 8 POLLIN = 1

So the first call to poll indicates some error because the "POLLERR" bit is set. Subsiquent calls are fine because they only sets the POLLIN bit.

But the real problem is that poll still returns instantly and doesn't wait for any changes to occur.

Thanks in advance,
Tage

_______________________________________________
This message was sent via the BRLTTY mailing list.
To post a message, send an e-mail to: [email protected]
For general information, go to: http://brltty.app/mailman/listinfo/brltty

Reply via email to