Is anyone aware of an equivalent to setsockopt() that works on non-socket based file descriptors?
Specifically, consider this block of code:
int on = 1;
setsockopt(socketfd, SOL_SOCKET, SO_NOSIGPIPE, &on, sizeof(int));
All fine and dandy, and now we can avoid SIGPIPE and refer to EPIPE when writing instead. But this only works on socket file descriptors opened with accept(), socket(), etc.
I'm trying to gain similar functionality for a file descriptor opened by a pipe() call, which setsockopt() promptly rejects as being a non-socket file descriptor.
Is there an equivalent to the above (setsockopt()) for descriptors opened by pipe() or open()?
There is no equivalent, but you could use socketpair
to create a Unix socket instead.