Pharos 0.7.23
Modern Web Framework & Web App Hosting Service.
Loading...
Searching...
No Matches
native_connection.h
Go to the documentation of this file.
1/**
2 * @file
3 * @brief Declares the native connection abstraction and transport metadata helpers.
4 */
5
6#ifndef PHAROS_NATIVE_CONNECTION_H
7#define PHAROS_NATIVE_CONNECTION_H
8
9#include <signal.h>
10#include <stddef.h>
11
12/**
13 * @brief Transport type used by a native connection.
14 */
15typedef enum {
16 NATIVE_TRANSPORT_UNKNOWN = 0, /**< Transport metadata is not yet known. */
17 NATIVE_TRANSPORT_TCP = 1, /**< Connection is backed by a TCP socket. */
18 NATIVE_TRANSPORT_UNIX = 2 /**< Connection is backed by a Unix domain socket. */
20
21/**
22 * @brief Accepted client connection and its resolved transport metadata.
23 */
24typedef struct {
25 int fd; /**< Connected socket file descriptor. */
26 NativeTransportType transport_type; /**< Resolved socket transport type. */
27 char *peer_info; /**< Printable remote endpoint description. */
28 char *local_info; /**< Printable local endpoint description. */
30
31/** @name Native connection helpers
32 * @{
33 */
34/**
35 * @brief Initializes a native connection record to an empty state.
36 * @param connection Connection record to initialize.
37 */
39/**
40 * @brief Releases owned transport metadata and resets a connection record.
41 * @param connection Connection record to clear.
42 */
44/**
45 * @brief Accepts the next client connection and records its transport metadata.
46 * @param server_fd Listening socket descriptor.
47 * @param shutdown_requested Shared shutdown flag checked while accepting.
48 * @param connection Destination connection record.
49 * @return Positive when a client was accepted, 0 when shutdown was requested, or a negative value on error.
50 */
51int native_connection_accept_next(int server_fd, volatile sig_atomic_t *shutdown_requested, NativeConnection *connection);
52/**
53 * @brief Reads bytes from a native connection.
54 * @param connection Open connection to read from.
55 * @param buffer Destination buffer.
56 * @param len Maximum number of bytes to read.
57 * @return Number of bytes read, or a negative value on error.
58 */
59int native_connection_read(NativeConnection *connection, void *buffer, size_t len);
60/**
61 * @brief Writes bytes to a native connection.
62 * @param connection Open connection to write to.
63 * @param buffer Source bytes to send.
64 * @param len Number of bytes to send.
65 * @return Number of bytes written, or a negative value on error.
66 */
67int native_connection_write(NativeConnection *connection, const void *buffer, size_t len);
68/**
69 * @brief Flushes any buffered connection output when the transport requires it.
70 * @param connection Connection to flush.
71 * @return 0 on success, or a negative value on error.
72 */
74/**
75 * @brief Closes a native connection and releases its owned metadata.
76 * @param connection Connection to close.
77 * @return 0 on success, or a negative value on error.
78 */
80/**
81 * @brief Shuts down a native connection without discarding the record itself.
82 * @param connection Connection to shut down.
83 * @return 0 on success, or a negative value on error.
84 */
86/**
87 * @brief Returns the printable remote endpoint description for a connection.
88 * @param connection Connection to inspect.
89 * @return Pointer to owned peer-info text, or NULL when unavailable.
90 */
91const char *native_connection_peer_info(const NativeConnection *connection);
92/**
93 * @brief Returns the printable local endpoint description for a connection.
94 * @param connection Connection to inspect.
95 * @return Pointer to owned local-info text, or NULL when unavailable.
96 */
97const char *native_connection_local_info(const NativeConnection *connection);
98/**
99 * @brief Returns the resolved transport type for a connection.
100 * @param connection Connection to inspect.
101 * @return Transport type recorded for the connection.
102 */
104/**
105 * @brief Returns a human-readable transport type name for a connection.
106 * @param connection Connection to inspect.
107 * @return Static transport type name string.
108 */
109const char *native_connection_transport_type_name(const NativeConnection *connection);
110
111
112/** @} */
113#endif
int native_connection_flush(NativeConnection *connection)
Flushes any buffered connection output when the transport requires it.
int native_connection_close(NativeConnection *connection)
Closes a native connection and releases its owned metadata.
int native_connection_accept_next(int server_fd, volatile sig_atomic_t *shutdown_requested, NativeConnection *connection)
Accepts the next client connection and records its transport metadata.
int native_connection_shutdown(NativeConnection *connection)
Shuts down a native connection without discarding the record itself.
int native_connection_write(NativeConnection *connection, const void *buffer, size_t len)
Writes bytes to a native connection.
const char * native_connection_local_info(const NativeConnection *connection)
Returns the printable local endpoint description for a connection.
void native_connection_reset(NativeConnection *connection)
Releases owned transport metadata and resets a connection record.
NativeTransportType
Transport type used by a native connection.
@ NATIVE_TRANSPORT_UNIX
@ NATIVE_TRANSPORT_UNKNOWN
@ NATIVE_TRANSPORT_TCP
const char * native_connection_transport_type_name(const NativeConnection *connection)
Returns a human-readable transport type name for a connection.
void native_connection_init(NativeConnection *connection)
Initializes a native connection record to an empty state.
NativeTransportType native_connection_transport_type(const NativeConnection *connection)
Returns the resolved transport type for a connection.
int native_connection_read(NativeConnection *connection, void *buffer, size_t len)
Reads bytes from a native connection.
const char * native_connection_peer_info(const NativeConnection *connection)
Returns the printable remote endpoint description for a connection.
Accepted client connection and its resolved transport metadata.
NativeTransportType transport_type
const char size_t len
Definition yyjson.h:8364