timeout on write() for linux pipe

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..

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.
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
Topic archived. No new replies allowed.