[Send/sendto/sendmsg System Call]
Function Description:
Send a message. Send can only be used for connection-based sockets. The only difference between send and write is the existence of a flag. When the flag is 0, send is equivalent to write. Sendto and sendmsg can be used for both connectionless sockets and connection-based sockets. Except for the non-blocking mode, the call will be blocked until the data is sent.
Usage:
# Include <sys/types. h>
# Include <sys/socket. h>
Ssize_t send (INT sock, const void * Buf, size_t Len, int flags );
Ssize_t sendto (INT sock, const void * Buf, size_t Len, int flags, const struct sockaddr * To, socklen_t tolen );
Ssize_t sendmsg (INT sock, const struct msghdr * MSG, int flags );
Parameters:
Sock: index the socket from which data will be sent.
Buf: indicates the buffer to be sent.
Len: the length of the buffer above.
Flags: a combination of the following zero or multiple flags, which can be connected through the or operation.
Msg_dontroute: Do not use a gateway to send packets, but send packets to directly connected hosts. This flag is mainly used for diagnosis or routing.
Msg_dontwait: The operation will not be blocked.
Msg_eor: terminate a record.
Msg_more: The caller needs to send more data.
Msg_nosignal: when the other end terminates the connection, the request should not send the sigpipe signal on the stream-based error socket.
MSG_OOB: Send out-of-band data (data to be processed preferentially), and the current protocol must support this operation.
To: point to the region where the acceptor address is stored. It can be null.
Tolen: the length of the above memory area, which can be 0.
MSG: refers to the memory buffer that stores the sending message header. The structure is as follows:
Struct msghdr {
Void * msg_name;
Socklen_t msg_namelen;
Struct iovec * msg_iov;
Size_t msg_iovlen;
Void * msg_control;
Socklen_t msg_controllen;
Int msg_flags;
};
Possible data structures are:
Struct cmsghdr {
Socklen_t cmsg_len;
Int cmsg_level;
Int cmsg_type;
};
Return description:
When execution is successful, the number of sent bytes is returned. -1 is returned for failure, and errno is set to one of the following values
Eacces: for Unix domain sockets, writing to the target socket file is not allowed, or a directory node of the path precursor cannot be searched.
Eagain, ewouldblock: the socket is marked as non-blocking, And the sending operation is blocked.
Ebadf: sock is not a valid descriptive word.
Econnreset: the connection is reset by the user.
Edestaddrreq: the socket is not in connection mode and the peer address is not specified.
Efault: memory space access error
Eintr: The operation is interrupted.
Einval: the parameter is invalid.
Eisconn: the connection-based socket has been connected and the receiving object is specified.
Emsgsize: the message size is too large.
Enomem: insufficient memory
Enotconn: the socket is not connected, and the target is not given
Enotsock: the sock index is not a socket
Epipe: The local connection is closed.