Feb 22, 2020 at 12:06pm UTC
How can I set timeout for write() on linux pipe ?
example code:
int fd_pipe = open("/run/some/pipe", O_RDWR);
// here i need to set timeout for 3 seconds somehow, if can't write, code will continue...
write(fd_pipe, something, strlen(something));
// continue executing..
thanks
Feb 23, 2020 at 12:52am UTC
1. use non-blocking file descriptors
2. use asynchronous i/o
3. submit the write
4. if it hasn't completed in 3 seconds, cancel the request and treat it as your timeout error.
Feb 25, 2020 at 12:21am UTC
That isn't what you asked for. You asked for a write timeout.
That code waits for the socket to be writeable before attempting the write. But some OS' (like BSD) are always ready to write.
That write is a blocking write, and you have your write timeout problem all over again.
Have you considered trying to implement what I suggested? I'm not going to write the code for you.
Last edited on Feb 25, 2020 at 12:23am UTC