The code works now!

The problem was that I have to reinitialize the pollfd-struct for every call to poll.

How ever, I have still one question.

Revents is allways set to 10. Wich means that both the POLLPRI and POLLERR flags are set.

Why is the POLLERR flag set? Is there still a problem with my code?


Thae code follows:

#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("OpenError: %s\n", strerror(errno));
        exit(EXIT_FAILURE);
    }
    uint8_t header[4];
    for(int i = 0; i < 30; i++) {
        struct pollfd fd = {
            .fd = vcsa,
            .events = POLLPRI
        };
        if (pread(vcsa, header, sizeof(header), 0) == -1) {
            printf("PreadError: %s\n", strerror(errno));
            exit(EXIT_FAILURE);
        }
        int ret = poll(&fd, 1, -1);
        if(ret == -1) {
            printf("PollError: %s\n", strerror(errno));
            exit(EXIT_FAILURE);
        }
        else if (ret == 0) {
            printf("PollError: poll timed out unexpectedly.\n");
            exit(EXIT_FAILURE);
        }
        else if (ret != 1) {
            printf("PollError: bad return value from poll %d\n", ret);
            exit(EXIT_FAILURE);
        }
        printf("%d header: %d, %d, %d, %d\n", fd.revents, header[0], header[1], header[2], header[3]);
    }
    printf("\nPOLLPRI = %d POLLERR = %d\n", POLLPRI, POLLERR);
    exit(EXIT_SUCCESS);
}

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