27

In socket ssize_t send(int __fd, const void* __buf, size_t __n, int __flags) we got this __flags argument. I'm using MSG_NOSIGNAL flag all through the connection. Is there a way to achieve this flag functionality in write? Since I'm using this flag all through the connection, It could be set when socket is created. Feel free to mention If there are ways to achieve all the __flag functions.

1 Answer 1

44

No. When writing to a socket with write it's the same thing as calling send with the flags argument set to zero.

From the official POSIX reference

If fildes refers to a socket, write() shall be equivalent to send() with no flags set.


There is however a way of "setting" this flag permanently, and that is to ignore the SIGPIPE signal:

signal(SIGPIPE, SIG_IGN);
2
  • this would ignore the signal for all connections by the procees, anyway can u help me with remaining flags? I gave an upvote but can't accept the answer. Thanq!
    – Necktwi
    Nov 14, 2013 at 11:50
  • 1
    @neckTwi The other two official flags (as well as those supported by recv are specific to the message being sent (or received), and not something that can be set on a per-connection or per-socket (or per-process or per-thread) basis. Nov 14, 2013 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.