| 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 IpcConnectionIO : IO |
| 11 | { |
| 12 | IpcConnectionIO(IpcDescriptor *descriptor) : IO(IO_READABLE | IO_WRITABLE, IO_IPC), descriptor(descriptor) {}; |
| 13 | virtual ~IpcConnectionIO() {}; |
| 14 | |
| 15 | protected: |
| 16 | IpcDescriptor *const descriptor; |
| 17 | }; |
| 18 | |
| 19 | /** |
| 20 | * @brief Create a new IPC server |
| 21 | * @param name The name of the server |
| 22 | * @param max_pending_connections The maximum number of pending connections to allow |
| 23 | * @return A new IO object that represents the server, or an error code on failure |
| 24 | * |
| 25 | * @note The IO returned by this function is only to accept new connections or close the server, reading or writing to it will fail. |
| 26 | */ |
| 27 | PtrResult<IO> ipc_create(const char *name, size_t max_pending_connections); |
| 28 | |
| 29 | /** |
| 30 | * @brief Accept a new connection on an IPC server |
| 31 | * @param server The server to accept a connection on |
| 32 | * @return An IO for the server side of the connection, or an error code on failure |
| 33 | */ |
| 34 | PtrResult<IO> ipc_accept(IO *server); |
| 35 | |
| 36 | /** |
| 37 | * @brief Connect to an IPC servers |
| 38 | * @param name The name of the server to connect to |
| 39 | * @param buffer_size The size of a shared-memory buffer to use for the connection |
| 40 | * @return A new IO object that represents the connection, or an error code on failure |
| 41 | */ |
| 42 | PtrResult<IO> ipc_connect(const char *name, size_t buffer_size); |
| 43 | |
| 44 | /** |
| 45 | * @brief Create a new IPC connection io descriptor |
| 46 | * |
| 47 | * @param ipc The IPC object to create the connection for |
| 48 | * @param is_server_side Whether this is the server side of the connection |
| 49 | * @return ipc_conn_io_t* A new IPC connection io descriptor |
| 50 | */ |
| 51 | PtrResult<IpcConnectionIO> ipc_conn_io_create(IpcDescriptor *ipc, bool is_server_side); |
| 52 | |