|
PatchworkOS
1731ea3
A non-POSIX operating system.
|
Networking and Sockets. More...
Networking and Sockets.
The networking filesystem provides networking and socket IPC functionality to the operating system. It exposes a common interface for various networking protocols and inter-process communication (IPC) mechanisms.
Network families represent different networking protocols or IPC mechanisms. Each family has its own directory in the filesystem, named after the family.
Each family directory contains factory files for creating sockets of different types, including stream, dgram, seqpacket, raw, and rdm.
Additionally, there is an addrs file that lists the addresses of all listening sockets within that family in the format:
Sockets are created by opening a factory file, named after the socket type it will create, located in each socket family's directory. Once a socket is created, it will persist until the namespace that created it is destroyed and there are no more references to it.
For example, to create a local seqpacket socket, open the /local/seqpacket file. This returns a handle that when read returns the socket's ID, which corresponds to the path /<family_name>/<socket_id>/, for example /local/1234/, which stores the files used to interact with the socket.
The socket directory will only be visible in the namespace that created it.
The files used to interact with sockets are listed below.
The /<family_name>/<socket_id>/accept file can be opened on a listening socket to accept incoming connections. Working in an similar way to the POSIX accept() function, the returned file descriptor represents the new connection.
If opened with :nonblock and there are no incoming connections, the open will fail with EAGAIN, otherwise it will block until a connection is available.
The /<family_name>/<socket_id>/ctl file is used to send "commands" to the socket by writing to it. Here is a list of supported commands:
bind <address>: Binds the socket to the specified address. (POSIX bind() function)listen <backlog>: Puts the socket into listening mode with the specified backlog length. (POSIX listen() function)connect <address>: Connects the socket to the specified address. (POSIX connect() function)The /<family_name>/<socket_id>/data file is used to send and receive data using the socket. Writing to this file sends data, reading from it receives data. (POSIX send() and recv() functions)
If opened with :nonblock, read and write operations will fail with EAGAIN if no data is available or there is no buffer space available, respectively. If not opened with :nonblock they will block, waiting for data or buffer space.
Data Structures | |
| struct | socket_t |
| Socket structure. More... | |
| struct | netfs_family_t |
| Socket Family structure. More... | |
Macros | |
| #define | NETFS_NAME "netfs" |
| The name of the networking filesystem. | |
| #define | NETFS_BACKLOG_DEFAULT 128 |
| The default backlog size for listening sockets. | |
Enumerations | |
| enum | socket_type_t { SOCKET_STREAM = 1 << 0 , SOCKET_DGRAM = 1 << 1 , SOCKET_SEQPACKET = 1 << 2 , SOCKET_RAW = 1 << 3 , SOCKET_RDM = 1 << 4 , SOCKET_TYPE_AMOUNT = 5 } |
| Socket types. More... | |
| enum | socket_state_t { SOCKET_NEW , SOCKET_BOUND , SOCKET_LISTENING , SOCKET_CONNECTING , SOCKET_CONNECTED , SOCKET_CLOSING , SOCKET_CLOSED } |
| Socket states. More... | |
Functions | |
| void | netfs_init (void) |
| Initialize the networking filesystem. | |
| uint64_t | netfs_family_register (netfs_family_t *family) |
| Register a network family. | |
| void | netfs_family_unregister (netfs_family_t *family) |
| Unregister a network family. | |
| #define NETFS_NAME "netfs" |
| #define NETFS_BACKLOG_DEFAULT 128 |
Socket types.
| uint64_t netfs_family_register | ( | netfs_family_t * | family | ) |
| void netfs_family_unregister | ( | netfs_family_t * | family | ) |