|
ginnOS
The reference: libc, the libraries and the kernel
|
Unix domain stream sockets, with file descriptor passing. More...
Go to the source code of this file.
Data Structures | |
| struct | ksockaddr_un_t |
| struct | kiovec_t |
| struct | kmsghdr_t |
| struct | kcmsghdr_t |
Macros | |
| #define | AF_UNIX 1 |
| #define | SOCK_STREAM 1 |
| #define | SOCK_NONBLOCK 0x00000800 |
| #define | SOCK_CLOEXEC 0x00080000 |
| #define | SOL_SOCKET 1 |
| #define | SCM_RIGHTS 1 |
| #define | MSG_CTRUNC 0x0008 |
| #define | MSG_DONTWAIT 0x0040 |
| #define | MSG_NOSIGNAL 0x4000 |
| #define | MSG_CMSG_CLOEXEC 0x40000000 |
| #define | UNIX_PATH_MAX 108 |
| #define | SOCKET_MAX_FDS 16 |
Typedefs | |
| typedef struct unix_socket | unix_socket_t |
Functions | |
| kerr_t | unix_socket_create (uint32_t flags, struct file **out) |
| make a new, unconnected socket and its open file. | |
| kerr_t | unix_socket_pair (uint32_t flags, struct file **a, struct file **b) |
| make two connected sockets (socketpair). | |
| unix_socket_t * | unix_socket_of (struct file *file) |
| the socket of an open file, or NULL if the file is not a socket. | |
| int32_t | unix_socket_bind (unix_socket_t *socket, const char *path) |
| give a socket a name. | |
| int32_t | unix_socket_listen (unix_socket_t *socket, uint32_t backlog) |
| let a bound socket take connections. | |
| int32_t | unix_socket_connect (unix_socket_t *socket, const char *path) |
| connect to the listening socket with this name. | |
| int32_t | unix_socket_accept (struct file *listener, uint32_t flags, struct file **out) |
| take the next connection of a listening socket (blocks unless the file is non-blocking). | |
| int32_t | unix_socket_send (struct file *file, const kiovec_t *iov, uint32_t iov_count, struct file **files, uint32_t file_count, bool dontwait) |
| send data from user memory, with files to pass (may be 0 of them). | |
| int32_t | unix_socket_receive (struct file *file, const kiovec_t *iov, uint32_t iov_count, struct file **files, uint32_t *file_count, bool dontwait) |
| receive data into user memory, and the files passed with its first byte. | |
Unix domain stream sockets, with file descriptor passing.
a server binds a socket to a name and listens; a client connects to the name and gets a connected pair. each side writes into the other's receive buffer. sendmsg can pass open files (SCM_RIGHTS): they travel with the first byte of the message, and recvmsg installs them as new fds in the receiver. this is how an app hands its window buffer (a shared memory fd) to the compositor.
the names are kept in a kernel table, not as files in the filesystem: any path works as a name, and nothing shows up in the directory.
the layouts below are the user ABI (<sys/socket.h>, <sys/un.h>, <sys/uio.h> in libc); they are the same as Linux's.
| #define AF_UNIX 1 |
| #define SOCK_STREAM 1 |
| #define SOCK_NONBLOCK 0x00000800 |
| #define SOCK_CLOEXEC 0x00080000 |
| #define SOL_SOCKET 1 |
| #define SCM_RIGHTS 1 |
| #define MSG_CTRUNC 0x0008 |
| #define MSG_DONTWAIT 0x0040 |
| #define MSG_NOSIGNAL 0x4000 |
| #define MSG_CMSG_CLOEXEC 0x40000000 |
| #define UNIX_PATH_MAX 108 |
| #define SOCKET_MAX_FDS 16 |
| typedef struct unix_socket unix_socket_t |
make a new, unconnected socket and its open file.
| flags | O_NONBLOCK or 0. |
make two connected sockets (socketpair).
| unix_socket_t * unix_socket_of | ( | struct file * | file | ) |
the socket of an open file, or NULL if the file is not a socket.
| int32_t unix_socket_bind | ( | unix_socket_t * | socket, |
| const char * | path ) |
give a socket a name.
the name must not be in use.
| int32_t unix_socket_listen | ( | unix_socket_t * | socket, |
| uint32_t | backlog ) |
let a bound socket take connections.
| int32_t unix_socket_connect | ( | unix_socket_t * | socket, |
| const char * | path ) |
connect to the listening socket with this name.
take the next connection of a listening socket (blocks unless the file is non-blocking).
| flags | O_NONBLOCK or 0, for the new socket's file. |
| out | receives the open file of the new connection. |
| int32_t unix_socket_send | ( | struct file * | file, |
| const kiovec_t * | iov, | ||
| uint32_t | iov_count, | ||
| struct file ** | files, | ||
| uint32_t | file_count, | ||
| bool | dontwait ) |
send data from user memory, with files to pass (may be 0 of them).
| files | the files (the socket takes a reference to each). |
| dontwait | do not block, as if the file were non-blocking. |
| int32_t unix_socket_receive | ( | struct file * | file, |
| const kiovec_t * | iov, | ||
| uint32_t | iov_count, | ||
| struct file ** | files, | ||
| uint32_t * | file_count, | ||
| bool | dontwait ) |
receive data into user memory, and the files passed with its first byte.
a call stops before the first byte of another message that passes files, so each message's files come with their own data.
| files | receives the passed files (the caller owns the references). |
| file_count | receives their number (0 if none). |