|
Pharos 0.7.23
Modern Web Framework & Web App Hosting Service.
|
Wraps accepted sockets with transport metadata and provides connection IO and lifecycle helpers. More...
#include "native_connection.h"#include <stdio.h>#include <stdlib.h>#include <string.h>#include <arpa/inet.h>#include <netinet/in.h>#include <sys/socket.h>#include <sys/time.h>#include <sys/un.h>#include <unistd.h>Go to the source code of this file.
Macros | |
| #define | native_connection_close_socket close |
| #define | native_connection_shutdown_socket(fd) |
| #define | native_connection_recv(fd, buffer, len) |
| #define | native_connection_send(fd, buffer, len) |
| #define | NATIVE_CONNECTION_IO_TIMEOUT_SECONDS 15 |
| #define | native_connection_strdup strdup |
Functions | |
| static char * | native_connection_format_sockaddr (const struct sockaddr *addr, socklen_t addr_len) |
| static NativeTransportType | native_connection_detect_transport (int fd) |
| static void | native_connection_apply_timeouts (int fd) |
| static void | native_connection_populate_endpoint_info (NativeConnection *connection) |
| 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. | |
Wraps accepted sockets with transport metadata and provides connection IO and lifecycle helpers.
Definition in file native_connection.c.
| #define native_connection_close_socket close |
Definition at line 26 of file native_connection.c.
Referenced by native_connection_accept_next(), and native_connection_close().
| #define NATIVE_CONNECTION_IO_TIMEOUT_SECONDS 15 |
Definition at line 32 of file native_connection.c.
Referenced by native_connection_apply_timeouts().
| #define native_connection_recv | ( | fd, | |
| buffer, | |||
| len ) |
Definition at line 28 of file native_connection.c.
Referenced by native_connection_read().
| #define native_connection_send | ( | fd, | |
| buffer, | |||
| len ) |
Definition at line 29 of file native_connection.c.
Referenced by native_connection_write().
| #define native_connection_shutdown_socket | ( | fd | ) |
Definition at line 27 of file native_connection.c.
Referenced by native_connection_shutdown().
| #define native_connection_strdup strdup |
Definition at line 37 of file native_connection.c.
Referenced by native_connection_format_sockaddr(), and native_connection_populate_endpoint_info().
| 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.
| server_fd | Listening socket descriptor. |
| shutdown_requested | Shared shutdown flag checked while accepting. |
| connection | Destination connection record. |
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().
|
static |
Definition at line 84 of file native_connection.c.
References NATIVE_CONNECTION_IO_TIMEOUT_SECONDS.
Referenced by native_connection_accept_next().
| int native_connection_close | ( | NativeConnection * | connection | ) |
Closes a native connection and releases its owned metadata.
| connection | Connection to close. |
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().
|
static |
Definition at line 66 of file native_connection.c.
References NATIVE_TRANSPORT_TCP, NATIVE_TRANSPORT_UNIX, and NATIVE_TRANSPORT_UNKNOWN.
Referenced by native_connection_accept_next().
| int native_connection_flush | ( | NativeConnection * | connection | ) |
Flushes any buffered connection output when the transport requires it.
| connection | Connection to flush. |
Definition at line 202 of file native_connection.c.
|
static |
Definition at line 40 of file native_connection.c.
References native_connection_strdup.
Referenced by native_connection_populate_endpoint_info().
| void native_connection_init | ( | NativeConnection * | connection | ) |
Initializes a native connection record to an empty state.
| connection | Connection 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().
| const char * native_connection_local_info | ( | const NativeConnection * | connection | ) |
Returns the printable local endpoint description for a connection.
| connection | Connection to inspect. |
Definition at line 230 of file native_connection.c.
References NativeConnection::local_info.
| const char * native_connection_peer_info | ( | const NativeConnection * | connection | ) |
Returns the printable remote endpoint description for a connection.
| connection | Connection to inspect. |
Definition at line 226 of file native_connection.c.
References NativeConnection::peer_info.
|
static |
Definition at line 98 of file native_connection.c.
References NativeConnection::fd, NativeConnection::local_info, native_connection_format_sockaddr(), native_connection_strdup, and NativeConnection::peer_info.
Referenced by native_connection_accept_next().
| int native_connection_read | ( | NativeConnection * | connection, |
| void * | buffer, | ||
| size_t | len ) |
Reads bytes from a native connection.
| connection | Open connection to read from. |
| buffer | Destination buffer. |
| len | Maximum number of bytes to read. |
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().
| void native_connection_reset | ( | NativeConnection * | connection | ) |
Releases owned transport metadata and resets a connection record.
| connection | Connection 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().
| int native_connection_shutdown | ( | NativeConnection * | connection | ) |
Shuts down a native connection without discarding the record itself.
| connection | Connection to shut down. |
Definition at line 219 of file native_connection.c.
References NativeConnection::fd, and native_connection_shutdown_socket.
| NativeTransportType native_connection_transport_type | ( | const NativeConnection * | connection | ) |
Returns the resolved transport type for a connection.
| connection | Connection to inspect. |
Definition at line 234 of file native_connection.c.
References NATIVE_TRANSPORT_UNKNOWN, and NativeConnection::transport_type.
Referenced by 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.
| connection | Connection to inspect. |
Definition at line 238 of file native_connection.c.
References native_connection_transport_type(), NATIVE_TRANSPORT_TCP, and NATIVE_TRANSPORT_UNIX.
| int native_connection_write | ( | NativeConnection * | connection, |
| const void * | buffer, | ||
| size_t | len ) |
Writes bytes to a native connection.
| connection | Open connection to write to. |
| buffer | Source bytes to send. |
| len | Number of bytes to send. |
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().