* @brief Creates a pair of connected sockets. * * The 'socketpair()' function creates two connected sockets, which can be used for bidirectional * communication between processes or threads on the same machine. This is commonly used for inter-process * communication (IPC) in UNIX-like operating systems. * * @param domain The communication domain (or protocol family). Typically, 'AF_UNIX' (
| 769 | * @see pipe() Creates an unidirectional communication channel between processes. |
| 770 | */ |
| 771 | int socketpair(int domain, int type, int protocol, int *fds) |
| 772 | { |
| 773 | rt_err_t ret = 0; |
| 774 | int sock_fds[2]; |
| 775 | |
| 776 | fds[0] = socket(domain, type, protocol); |
| 777 | if (fds[0] < 0) |
| 778 | { |
| 779 | fds[0] = 0; |
| 780 | return -1; |
| 781 | } |
| 782 | |
| 783 | fds[1] = socket(domain, type, protocol); |
| 784 | if (fds[1] < 0) |
| 785 | { |
| 786 | closesocket(fds[0]); |
| 787 | fds[0] = 0; |
| 788 | fds[1] = 0; |
| 789 | return -1; |
| 790 | } |
| 791 | |
| 792 | sock_fds[0] = dfs_net_getsocket(fds[0]); |
| 793 | sock_fds[1] = dfs_net_getsocket(fds[1]); |
| 794 | |
| 795 | ret = sal_socketpair(domain, type, protocol, sock_fds); |
| 796 | |
| 797 | if (ret < 0) |
| 798 | { |
| 799 | closesocket(fds[0]); |
| 800 | closesocket(fds[1]); |
| 801 | } |
| 802 | |
| 803 | return ret; |
| 804 | } |
| 805 | RTM_EXPORT(socketpair); |
| 806 | |
| 807 | /** |
no test coverage detected