Pharos 0.7.23
Modern Web Framework & Web App Hosting Service.
Loading...
Searching...
No Matches
native_connection.h File Reference

Declares the native connection abstraction and transport metadata helpers. More...

#include <signal.h>
#include <stddef.h>

Go to the source code of this file.

Data Structures

struct  NativeConnection
 Accepted client connection and its resolved transport metadata. More...

Enumerations

enum  NativeTransportType { NATIVE_TRANSPORT_UNKNOWN = 0 , NATIVE_TRANSPORT_TCP = 1 , NATIVE_TRANSPORT_UNIX = 2 }
 Transport type used by a native connection. More...

Functions

Native connection helpers
void native_connection_init (NativeConnection *connection)
 Initializes a native connection record to an empty state.
void native_connection_reset (NativeConnection *connection)
 Releases owned transport metadata and resets a connection record.
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_read (NativeConnection *connection, void *buffer, size_t len)
 Reads bytes from a native connection.
int native_connection_write (NativeConnection *connection, const void *buffer, size_t len)
 Writes bytes to a native connection.
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_shutdown (NativeConnection *connection)
 Shuts down a native connection without discarding the record itself.
const char * native_connection_peer_info (const NativeConnection *connection)
 Returns the printable remote endpoint description for a connection.
const char * native_connection_local_info (const NativeConnection *connection)
 Returns the printable local endpoint description for a connection.
NativeTransportType native_connection_transport_type (const NativeConnection *connection)
 Returns the resolved transport type for a connection.
const char * native_connection_transport_type_name (const NativeConnection *connection)
 Returns a human-readable transport type name for a connection.

Detailed Description

Declares the native connection abstraction and transport metadata helpers.

Definition in file native_connection.h.

Enumeration Type Documentation

◆ NativeTransportType

Transport type used by a native connection.

Enumerator
NATIVE_TRANSPORT_UNKNOWN 

Transport metadata is not yet known.

NATIVE_TRANSPORT_TCP 

Connection is backed by a TCP socket.

NATIVE_TRANSPORT_UNIX 

Connection is backed by a Unix domain socket.

Definition at line 15 of file native_connection.h.

Function Documentation

◆ 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.

Parameters
server_fdListening socket descriptor.
shutdown_requestedShared shutdown flag checked while accepting.
connectionDestination connection record.
Returns
Positive when a client was accepted, 0 when shutdown was requested, or a negative value on error.

Definition at line 148 of file native_connection.c.

References NativeConnection::fd, native_connection_apply_timeouts(), native_connection_close_socket, native_connection_detect_transport(), native_connection_populate_endpoint_info(), native_connection_reset(), and NativeConnection::transport_type.

Referenced by accept_http_request_native().

◆ native_connection_close()

int native_connection_close ( NativeConnection * connection)

Closes a native connection and releases its owned metadata.

Parameters
connectionConnection to close.
Returns
0 on success, or a negative value on error.

Definition at line 207 of file native_connection.c.

References NativeConnection::fd, native_connection_close_socket, and native_connection_reset().

Referenced by accept_http_request_native(), build_worker_context_native(), free_worker_context_native(), serve_runtime_stack_native(), serve_single_app(), and serve_static_root().

◆ native_connection_flush()

int native_connection_flush ( NativeConnection * connection)

Flushes any buffered connection output when the transport requires it.

Parameters
connectionConnection to flush.
Returns
0 on success, or a negative value on error.

Definition at line 202 of file native_connection.c.

◆ native_connection_init()

void native_connection_init ( NativeConnection * connection)

Initializes a native connection record to an empty state.

Parameters
connectionConnection record to initialize.

Definition at line 126 of file native_connection.c.

References NativeConnection::fd, NativeConnection::local_info, NATIVE_TRANSPORT_UNKNOWN, NativeConnection::peer_info, and NativeConnection::transport_type.

Referenced by build_worker_context_native(), serve_runtime_stack_native(), serve_single_app(), and serve_static_root().

◆ native_connection_local_info()

const char * native_connection_local_info ( const NativeConnection * connection)

Returns the printable local endpoint description for a connection.

Parameters
connectionConnection to inspect.
Returns
Pointer to owned local-info text, or NULL when unavailable.

Definition at line 230 of file native_connection.c.

References NativeConnection::local_info.

◆ native_connection_peer_info()

const char * native_connection_peer_info ( const NativeConnection * connection)

Returns the printable remote endpoint description for a connection.

Parameters
connectionConnection to inspect.
Returns
Pointer to owned peer-info text, or NULL when unavailable.

Definition at line 226 of file native_connection.c.

References NativeConnection::peer_info.

◆ native_connection_read()

int native_connection_read ( NativeConnection * connection,
void * buffer,
size_t len )

Reads bytes from a native connection.

Parameters
connectionOpen connection to read from.
bufferDestination buffer.
lenMaximum number of bytes to read.
Returns
Number of bytes read, or a negative value on error.

Definition at line 180 of file native_connection.c.

References NativeConnection::fd, len, and native_connection_recv.

Referenced by native_spool_request_body_to_temp_file(), and parse_http_request_native().

◆ native_connection_reset()

void native_connection_reset ( NativeConnection * connection)

Releases owned transport metadata and resets a connection record.

Parameters
connectionConnection record to clear.

Definition at line 136 of file native_connection.c.

References NativeConnection::fd, NativeConnection::local_info, NATIVE_TRANSPORT_UNKNOWN, NativeConnection::peer_info, and NativeConnection::transport_type.

Referenced by native_connection_accept_next(), and native_connection_close().

◆ native_connection_shutdown()

int native_connection_shutdown ( NativeConnection * connection)

Shuts down a native connection without discarding the record itself.

Parameters
connectionConnection to shut down.
Returns
0 on success, or a negative value on error.

Definition at line 219 of file native_connection.c.

References NativeConnection::fd, and native_connection_shutdown_socket.

◆ native_connection_transport_type()

NativeTransportType native_connection_transport_type ( const NativeConnection * connection)

Returns the resolved transport type for a connection.

Parameters
connectionConnection to inspect.
Returns
Transport type recorded for the connection.

Definition at line 234 of file native_connection.c.

References NATIVE_TRANSPORT_UNKNOWN, and NativeConnection::transport_type.

Referenced by native_connection_transport_type_name().

◆ 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.

Parameters
connectionConnection to inspect.
Returns
Static transport type name string.

Definition at line 238 of file native_connection.c.

References native_connection_transport_type(), NATIVE_TRANSPORT_TCP, and NATIVE_TRANSPORT_UNIX.

◆ native_connection_write()

int native_connection_write ( NativeConnection * connection,
const void * buffer,
size_t len )

Writes bytes to a native connection.

Parameters
connectionOpen connection to write to.
bufferSource bytes to send.
lenNumber of bytes to send.
Returns
Number of bytes written, or a negative value on error.

Definition at line 187 of file native_connection.c.

References NativeConnection::fd, len, and native_connection_send.

Referenced by handle_app_or_runtime_request(), native_connection_printf(), native_dynamic_media_serve_asset(), and native_serve_static_file().