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

Function sys_socket

components/lwp/lwp_syscall.c:6198–6225  ·  view source on GitHub ↗

* @brief Creates a new socket for communication. * * This system call creates a new socket endpoint for communication and returns a file descriptor * that can be used for subsequent socket operations, such as binding, connecting, or data transfer. * * @param[in] domain Specifies the protocol family to be used for the socket. Common values include: * - `AF_INET`: IPv4 I

Source from the content-addressed store, hash-verified

6196 * @see sys_bind(), sys_connect(), sys_accept(), sys_close()
6197 */
6198sysret_t sys_socket(int domain, int type, int protocol)
6199{
6200 int fd = -1;
6201 int nonblock = 0;
6202 /* not support SOCK_CLOEXEC type */
6203 if (type & SOCK_CLOEXEC)
6204 {
6205 type &= ~SOCK_CLOEXEC;
6206 }
6207 if (type & SOCK_NONBLOCK)
6208 {
6209 nonblock = 1;
6210 type &= ~SOCK_NONBLOCK;
6211 }
6212
6213 fd = socket(domain, type, protocol);
6214 if (fd < 0)
6215 {
6216 goto out;
6217 }
6218 if (nonblock)
6219 {
6220 fcntl(fd, F_SETFL, O_NONBLOCK);
6221 }
6222
6223out:
6224 return (fd < 0 ? GET_ERRNO() : fd);
6225}
6226
6227/**
6228 * @brief Creates a pair of connected sockets.

Callers

nothing calls this directly

Calls 2

socketFunction · 0.85
fcntlFunction · 0.50

Tested by

no test coverage detected