1 | // SPDX-License-Identifier: GPL-3.0-or-later |
2 | |
3 | #pragma once |
4 | |
5 | #include "mos/io/io.hpp" |
6 | #include "mos/ipc/ipc.hpp" |
7 | |
8 | #include <mos/allocator.hpp> |
9 | |
10 | struct ipc_conn_io_t : mos::NamedType<"IPC.ConnectionIO" > |
11 | { |
12 | io_t io; |
13 | IPCDescriptor *ipc; |
14 | }; |
15 | |
16 | /** |
17 | * @brief Create a new IPC server |
18 | * @param name The name of the server |
19 | * @param max_pending_connections The maximum number of pending connections to allow |
20 | * @return A new io_t object that represents the server, or an error code on failure |
21 | * |
22 | * @note The io_t returned by this function is only to accept new connections or close the server, reading or writing to it will fail. |
23 | */ |
24 | PtrResult<io_t> ipc_create(const char *name, size_t max_pending_connections); |
25 | |
26 | /** |
27 | * @brief Accept a new connection on an IPC server |
28 | * @param server The server to accept a connection on |
29 | * @return An io_t for the server side of the connection, or an error code on failure |
30 | */ |
31 | PtrResult<io_t> ipc_accept(io_t *server); |
32 | |
33 | /** |
34 | * @brief Connect to an IPC servers |
35 | * @param name The name of the server to connect to |
36 | * @param buffer_size The size of a shared-memory buffer to use for the connection |
37 | * @return A new io_t object that represents the connection, or an error code on failure |
38 | */ |
39 | PtrResult<io_t> ipc_connect(const char *name, size_t buffer_size); |
40 | |
41 | /** |
42 | * @brief Create a new IPC connection io descriptor |
43 | * |
44 | * @param ipc The IPC object to create the connection for |
45 | * @param is_server_side Whether this is the server side of the connection |
46 | * @return ipc_conn_io_t* A new IPC connection io descriptor |
47 | */ |
48 | PtrResult<ipc_conn_io_t> ipc_conn_io_create(IPCDescriptor *ipc, bool is_server_side); |
49 | |