MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / socketpair

Function socketpair

components/net/sal/socket/net_sockets.c:771–804  ·  view source on GitHub ↗

* @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' (

Source from the content-addressed store, hash-verified

769 * @see pipe() Creates an unidirectional communication channel between processes.
770 */
771int 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}
805RTM_EXPORT(socketpair);
806
807/**

Callers 1

sys_socketpairFunction · 0.85

Calls 4

socketFunction · 0.85
closesocketFunction · 0.85
dfs_net_getsocketFunction · 0.85
sal_socketpairFunction · 0.85

Tested by

no test coverage detected