When to check for EINTR and repeat the function call?

后端 未结 4 1925
攒了一身酷
攒了一身酷 2020-12-05 01:43

I am programming a user application for a embedded Linux system, and I am using the common functions such as open, close, read, ioctl, etc. for the devices. Now, I read abou

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-05 02:39

    I had a similar problem when waiting for input from a named pipe with read().

    I found an explanation and a useful macro for primitives in GNU libc documentation: TEMP_FAILURE_RETRY

    Example:

    TEMP_FAILURE_RETRY (read_return = read((int)example_fifo, buffer, (size_t)n));
    if (read_return==-1){
        fprintf(stderr, "reader.c: read_fifo: read(): %s \n", strerror(errno));
        fflush(stderr);
    }
    

提交回复
热议问题