Defines | Functions | Variables

src/ach.c File Reference

#include <time.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
#include <ctype.h>
#include <stdbool.h>
#include <sys/stat.h>
#include <inttypes.h>
#include "ach.h"

Defines

#define DEBUGF(fmt, a...)   fprintf(stderr, (fmt), ## a )
 macro to print debug messages
#define DEBUG_PERROR(a)   perror(a)
 Call perror() when debugging.
#define IFDEBUG(x)   (x)
 macro to do things when debugging

Functions

const char * ach_result_to_string (ach_status_t result)
 Converts return code from ach call to a human readable string;.
void ach_create_attr_init (ach_create_attr_t *attr)
 Initialize attributes for creating channels.
enum ach_status ach_create (const char *channel_name, size_t frame_cnt, size_t frame_size, ach_create_attr_t *attr)
 Creates a new channel.
enum ach_status ach_open (ach_channel_t *chan, const char *channel_name, ach_attr_t *attr)
 Opens a handle to channel.
enum ach_status ach_get (ach_channel_t *chan, void *buf, size_t size, size_t *frame_size, const struct timespec *ACH_RESTRICT abstime, int options)
 Pulls a message from the channel.
enum ach_status ach_flush (ach_channel_t *chan)
 Discards all previously received messages for this handle.
enum ach_status ach_put (ach_channel_t *chan, void *buf, size_t len)
 Writes a new message in the channel.
enum ach_status ach_close (ach_channel_t *chan)
 Closes the shared memory block.
void ach_dump (ach_header_t *shm)
 Prints information about the channel shm to stderr.
void ach_attr_init (ach_attr_t *attr)
 Initialize attributes for opening channels.
enum ach_status ach_chmod (ach_channel_t *chan, mode_t mode)
 Sets permissions of chan to specified mode.
enum ach_status ach_unlink (const char *name)
 Delete an ach channel.

Variables

size_t ach_channel_size = sizeof(ach_channel_t)
 Size of ach_channel_t.
size_t ach_attr_size = sizeof(ach_attr_t)
 Size of ach_attr_t.

Detailed Description

Author:
Neil T. Dantam

Function Documentation

void ach_attr_init ( ach_attr_t attr  ) 

Initialize attributes for opening channels.

enum ach_status ach_close ( ach_channel_t chan  ) 

Closes the shared memory block.

Precondition:
chan is an initialized ach channel with open shared memory area
Postcondition:
the shared memory file for chan is closed
enum ach_status ach_create ( const char *  channel_name,
size_t  frame_cnt,
size_t  frame_size,
ach_create_attr_t attr 
)

Creates a new channel.

Parameters:
channel_name Name of the channel
frame_cnt number of frames to hold in circular buffer
frame_size nominal size of each frame
attr options
void ach_create_attr_init ( ach_create_attr_t attr  ) 

Initialize attributes for creating channels.

void ach_dump ( ach_header_t shm  ) 

Prints information about the channel shm to stderr.

This function is mostly for internal debugging.

enum ach_status ach_flush ( ach_channel_t chan  ) 

Discards all previously received messages for this handle.

Does not change the actual channel, just resets the sequence number in the handle.

enum ach_status ach_get ( ach_channel_t chan,
void *  buf,
size_t  size,
size_t *  frame_size,
const struct timespec *ACH_RESTRICT  abstime,
int  options 
)

Pulls a message from the channel.

Precondition:
chan has been opened with ach_open()
Postcondition:
If buf is big enough to hold the next frame, buf contains the data for the last frame and chan.seq_num is set to the last frame. If buf is too small to hold the next frame, no side effects occur. The seq_num field of chan will be set to the latest sequence number (that of the gotten frame).
Parameters:
chan The previously opened channel handle
buf Buffer to store data
size Length of buffer in bytes
frame_size The number of bytes copied to buf, or the size of the desired frame if buf is too small.
abstime An absolute timeout if ACH_O_WAIT is specified. Take care that abstime is given in the correct clock. The default is defined by ACH_DEFAULT_CLOCK.
options Option flags
enum ach_status ach_put ( ach_channel_t chan,
void *  buf,
size_t  len 
)

Writes a new message in the channel.

Precondition:
chan has been opened with ach_open()
Postcondition:
The contents of buf are copied into the channel and the sequence number of the channel is incremented.
Parameters:
chan (action) The channel to write to
buf The buffer containing the data to copy into the channel
len number of bytes in buf to copy, len > 0
Returns:
ACH_OK on success.