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.
The only difference between recv() and read(2) is the presence of flags. With a zero flags argument, recv() is generally equivalent to read(2) (but see NOTES).
The only difference between send() and write(2) is the presence of flags. With a zero flags argument, send() is equivalent to write(2). Also, the following call send(sockfd, buf, len, flags); is equivalent to sendto(sockfd, buf, len, flags, NULL, 0); The argument sockfd is the file descriptor of the sending socket.
Generally speaking, send() is used for TCP SOCK_STREAM connected sockets, and sendto() is used for UDP SOCK_DGRAM unconnected datagram sockets.
Unlike the recv() call, which can only be used on a connected stream socket or bound datagram socket, recvfrom() can be used to receive data on a socket whether or not it is connected. If no messages are available at the socket, the recvfrom() call waits for a message to arrive unless the socket is nonblocking.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With