SafeAPI Backend POSIX
POSIX/Linux OAL backend for safeAPIFreamwork
Loading...
Searching...
No Matches
sapi_posix_backend_ipc.c File Reference

POSIX sapi_ipc backend: one pipe() per channel (ADR-018 section 2.2/2.3 - a mutex+condvar ring buffer would not fit sapi_ipc's 64-byte opaque storage on glibc; a pipe lets the kernel own the queue instead). More...

#include "safeapi/posix_backend/sapi_posix_backend.h"
#include <errno.h>
#include <fcntl.h>
#include <poll.h>
#include <time.h>
#include <unistd.h>
Include dependency graph for sapi_posix_backend_ipc.c:

Go to the source code of this file.

Data Structures

struct  posix_ipc_state_t

Typedefs

typedef char posix_ipc_storage_fits_[(sizeof(posix_ipc_state_t)<=sizeof(sapi_ipc_storage_t)) ? 1 :-1]

Functions

static int remaining_ms (const struct timespec *deadline)
static void compute_deadline (sapi_duration_ms_t timeout_ms, struct timespec *out_deadline)
static sapi_status_t transfer_all (int fd, const void *write_src, void *read_dst, size_t size, sapi_duration_ms_t timeout_ms, bool read_not_write)
static sapi_status_t backend_create (sapi_ipc_storage_t *storage, const sapi_ipc_config_t *config, sapi_ipc_handle_t *out_handle)
static sapi_status_t backend_send (sapi_ipc_handle_t handle, const void *message, size_t message_size, sapi_duration_ms_t timeout_ms)
static sapi_status_t backend_receive (sapi_ipc_handle_t handle, void *out_message, size_t buffer_size, sapi_duration_ms_t timeout_ms)
static sapi_status_t backend_destroy (sapi_ipc_handle_t handle)
const sapi_ipc_backend_t * sapi_posix_backend_ipc (void)
 The POSIX sapi_ipc backend (pipe() per channel).

Variables

static const sapi_ipc_backend_t s_posix_ipc_backend

Detailed Description

POSIX sapi_ipc backend: one pipe() per channel (ADR-018 section 2.2/2.3 - a mutex+condvar ring buffer would not fit sapi_ipc's 64-byte opaque storage on glibc; a pipe lets the kernel own the queue instead).

Known simplification (stated in ADR-018): a message larger than the pipe's remaining buffer that partially transfers before timeout_ms expires leaves a partial message in the pipe for the next receive() - acceptable for a first cut, not hardened for production.

Definition in file sapi_posix_backend_ipc.c.

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE

Definition at line 5 of file sapi_posix_backend_ipc.c.

Typedef Documentation

◆ posix_ipc_storage_fits_

typedef char posix_ipc_storage_fits_[(sizeof(posix_ipc_state_t)<=sizeof(sapi_ipc_storage_t)) ? 1 :-1]

Definition at line 34 of file sapi_posix_backend_ipc.c.

Function Documentation

◆ backend_create()

sapi_status_t backend_create ( sapi_ipc_storage_t * storage,
const sapi_ipc_config_t * config,
sapi_ipc_handle_t * out_handle )
static

Definition at line 132 of file sapi_posix_backend_ipc.c.

◆ backend_destroy()

sapi_status_t backend_destroy ( sapi_ipc_handle_t handle)
static

Definition at line 195 of file sapi_posix_backend_ipc.c.

◆ backend_receive()

sapi_status_t backend_receive ( sapi_ipc_handle_t handle,
void * out_message,
size_t buffer_size,
sapi_duration_ms_t timeout_ms )
static

Definition at line 183 of file sapi_posix_backend_ipc.c.

◆ backend_send()

sapi_status_t backend_send ( sapi_ipc_handle_t handle,
const void * message,
size_t message_size,
sapi_duration_ms_t timeout_ms )
static

Definition at line 171 of file sapi_posix_backend_ipc.c.

◆ compute_deadline()

void compute_deadline ( sapi_duration_ms_t timeout_ms,
struct timespec * out_deadline )
static

Definition at line 56 of file sapi_posix_backend_ipc.c.

◆ remaining_ms()

int remaining_ms ( const struct timespec * deadline)
static

Milliseconds remaining until deadline, clamped to >= 0; -1 if now() itself fails (caller treats that as "no time left").

Definition at line 38 of file sapi_posix_backend_ipc.c.

◆ sapi_posix_backend_ipc()

const sapi_ipc_backend_t * sapi_posix_backend_ipc ( void )

The POSIX sapi_ipc backend (pipe() per channel).

Definition at line 211 of file sapi_posix_backend_ipc.c.

◆ transfer_all()

sapi_status_t transfer_all ( int fd,
const void * write_src,
void * read_dst,
size_t size,
sapi_duration_ms_t timeout_ms,
bool read_not_write )
static

Shared poll-then-transfer loop. read_not_write selects direction; write_src/read_dst are mutually exclusive (only the one matching read_not_write's value is dereferenced) - kept as two parameters rather than one non-const void* so neither caller has to cast away const to use this helper.

Definition at line 73 of file sapi_posix_backend_ipc.c.

Variable Documentation

◆ s_posix_ipc_backend

const sapi_ipc_backend_t s_posix_ipc_backend
static
Initial value:
= { backend_create, backend_send, backend_receive,
backend_destroy }

Definition at line 208 of file sapi_posix_backend_ipc.c.