Pharos
0.7.23
Modern Web Framework & Web App Hosting Service.
Toggle main menu visibility
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
*/
15
typedef
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. */
19
}
NativeTransportType
;
20
21
/**
22
* @brief Accepted client connection and its resolved transport metadata.
23
*/
24
typedef
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. */
29
}
NativeConnection
;
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
*/
38
void
native_connection_init
(
NativeConnection
*connection);
39
/**
40
* @brief Releases owned transport metadata and resets a connection record.
41
* @param connection Connection record to clear.
42
*/
43
void
native_connection_reset
(
NativeConnection
*connection);
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
*/
51
int
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
*/
59
int
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
*/
67
int
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
*/
73
int
native_connection_flush
(
NativeConnection
*connection);
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
*/
79
int
native_connection_close
(
NativeConnection
*connection);
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
*/
85
int
native_connection_shutdown
(
NativeConnection
*connection);
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
*/
91
const
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
*/
97
const
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
*/
103
NativeTransportType
native_connection_transport_type
(
const
NativeConnection
*connection);
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
*/
109
const
char
*
native_connection_transport_type_name
(
const
NativeConnection
*connection);
110
111
112
/** @} */
113
#endif
native_connection_flush
int native_connection_flush(NativeConnection *connection)
Flushes any buffered connection output when the transport requires it.
Definition
native_connection.c:202
native_connection_close
int native_connection_close(NativeConnection *connection)
Closes a native connection and releases its owned metadata.
Definition
native_connection.c:207
native_connection_accept_next
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.
Definition
native_connection.c:148
native_connection_shutdown
int native_connection_shutdown(NativeConnection *connection)
Shuts down a native connection without discarding the record itself.
Definition
native_connection.c:219
native_connection_write
int native_connection_write(NativeConnection *connection, const void *buffer, size_t len)
Writes bytes to a native connection.
Definition
native_connection.c:187
native_connection_local_info
const char * native_connection_local_info(const NativeConnection *connection)
Returns the printable local endpoint description for a connection.
Definition
native_connection.c:230
native_connection_reset
void native_connection_reset(NativeConnection *connection)
Releases owned transport metadata and resets a connection record.
Definition
native_connection.c:136
NativeTransportType
NativeTransportType
Transport type used by a native connection.
Definition
native_connection.h:15
NATIVE_TRANSPORT_UNIX
@ NATIVE_TRANSPORT_UNIX
Definition
native_connection.h:18
NATIVE_TRANSPORT_UNKNOWN
@ NATIVE_TRANSPORT_UNKNOWN
Definition
native_connection.h:16
NATIVE_TRANSPORT_TCP
@ NATIVE_TRANSPORT_TCP
Definition
native_connection.h:17
native_connection_transport_type_name
const char * native_connection_transport_type_name(const NativeConnection *connection)
Returns a human-readable transport type name for a connection.
Definition
native_connection.c:238
native_connection_init
void native_connection_init(NativeConnection *connection)
Initializes a native connection record to an empty state.
Definition
native_connection.c:126
native_connection_transport_type
NativeTransportType native_connection_transport_type(const NativeConnection *connection)
Returns the resolved transport type for a connection.
Definition
native_connection.c:234
native_connection_read
int native_connection_read(NativeConnection *connection, void *buffer, size_t len)
Reads bytes from a native connection.
Definition
native_connection.c:180
native_connection_peer_info
const char * native_connection_peer_info(const NativeConnection *connection)
Returns the printable remote endpoint description for a connection.
Definition
native_connection.c:226
NativeConnection
Accepted client connection and its resolved transport metadata.
Definition
native_connection.h:24
NativeConnection::peer_info
char * peer_info
Definition
native_connection.h:27
NativeConnection::transport_type
NativeTransportType transport_type
Definition
native_connection.h:26
NativeConnection::fd
int fd
Definition
native_connection.h:25
NativeConnection::local_info
char * local_info
Definition
native_connection.h:28
len
const char size_t len
Definition
yyjson.h:8364
src
native_runtime
c
native_connection.h
Generated by
1.17.0