Blame src/libout123/xfermem.h

Packit c32a2d
/*
Packit c32a2d
	xfermem: unidirectional fast pipe
Packit c32a2d
Packit c32a2d
	copyright ?-2006 by the mpg123 project - free software under the terms of the LGPL 2.1
Packit c32a2d
	see COPYING and AUTHORS files in distribution or http://mpg123.org
Packit c32a2d
	initially written by Oliver Fromme
Packit c32a2d
	old timestamp: Sat Mar 29 04:41:34 MET 1997
Packit c32a2d
Packit c32a2d
	This is a stand-alone module which implements a unidirectional,
Packit c32a2d
	fast pipe using mmap().  Its primary use is to transfer large
Packit c32a2d
	amounts of data from a parent process to its child process,
Packit c32a2d
	with a buffer in between which decouples blocking conditions
Packit c32a2d
	on both sides.  Control information is transferred between the
Packit c32a2d
	processes through a socketpair.  See xftest.c for an example on
Packit c32a2d
	how to use this module.
Packit c32a2d
Packit c32a2d
	note: xftest not there anymore
Packit c32a2d
*/
Packit c32a2d
Packit c32a2d
#ifndef _XFERMEM_H_
Packit c32a2d
#define _XFERMEM_H_
Packit c32a2d
Packit c32a2d
#include "compat.h"
Packit c32a2d
Packit c32a2d
typedef struct {
Packit c32a2d
	size_t freeindex;	/* [W] next free index */
Packit c32a2d
	size_t readindex;	/* [R] next index to read */
Packit c32a2d
	int fd[2];
Packit c32a2d
	char *data;
Packit c32a2d
	char *metadata;
Packit c32a2d
	size_t size;
Packit c32a2d
	size_t metasize;
Packit c32a2d
} txfermem;
Packit c32a2d
/*
Packit c32a2d
 *   [W] -- May be written to by the writing process only!
Packit c32a2d
 *   [R] -- May be written to by the reading process only!
Packit c32a2d
 *   All other entries are initialized once.
Packit c32a2d
 */
Packit c32a2d
Packit c32a2d
void xfermem_init (txfermem **xf, size_t bufsize, size_t msize, size_t skipbuf);
Packit c32a2d
void xfermem_init_writer (txfermem *xf);
Packit c32a2d
void xfermem_init_reader (txfermem *xf);
Packit c32a2d
Packit c32a2d
size_t xfermem_get_freespace (txfermem *xf);
Packit c32a2d
size_t xfermem_get_usedspace (txfermem *xf);
Packit c32a2d
Packit c32a2d
/* Unless otherwise noted, each command demands a reponse if issued from the
Packit c32a2d
   writer. The reader does not expect responses, only orders. */
Packit c32a2d
enum xf_cmd_code
Packit c32a2d
{
Packit c32a2d
	XF_CMD_PING = 1  /**< Wake up and give a response, not changing any state. */
Packit c32a2d
,	XF_CMD_PONG      /**< The response to a ping. */
Packit c32a2d
,	XF_CMD_DATA      /**< Re-check the amount of data available without response. */
Packit c32a2d
,	XF_CMD_TERMINATE /**< Stop operation. */
Packit c32a2d
,	XF_CMD_DROP      /**< Drop current buffer contents. */
Packit c32a2d
,	XF_CMD_DRAIN     /**< Consume current buffer contents now. */
Packit c32a2d
,	XF_CMD_PAUSE     /**< Pause operation, wait for next command. */
Packit c32a2d
,	XF_CMD_CONTINUE  /**< Continue operation. */
Packit c32a2d
,	XF_CMD_IGNLOW    /**< Ignore situation with low buffer fill. */
Packit c32a2d
,	XF_CMD_OK        /**< Response from reader: Operation succeeded. */
Packit c32a2d
,	XF_CMD_ERROR     /**< Response from reader: Operation failed.  */
Packit c32a2d
,	XF_CMD_CUSTOM1   /**< Some custom command to be filled with meaning. */
Packit c32a2d
,	XF_CMD_CUSTOM2   /**< Some custom command to be filled with meaning. */
Packit c32a2d
,	XF_CMD_CUSTOM3   /**< Some custom command to be filled with meaning. */
Packit c32a2d
,	XF_CMD_CUSTOM4   /**< Some custom command to be filled with meaning. */
Packit c32a2d
,	XF_CMD_CUSTOM5   /**< Some custom command to be filled with meaning. */
Packit c32a2d
,	XF_CMD_CUSTOM6   /**< Some custom command to be filled with meaning. */
Packit c32a2d
,	XF_CMD_CUSTOM7   /**< Some custom command to be filled with meaning. */
Packit c32a2d
,	XF_CMD_CUSTOM8   /**< Some custom command to be filled with meaning. */
Packit c32a2d
};
Packit c32a2d
Packit c32a2d
#define XF_WRITER 0
Packit c32a2d
#define XF_READER 1
Packit c32a2d
int xfermem_getcmd(int fd, int block);
Packit c32a2d
int xfermem_getcmds(int fd, int block, byte* cmds, int count);
Packit c32a2d
int xfermem_putcmd(int fd, byte cmd);
Packit c32a2d
int xfermem_writer_block(txfermem *xf);
Packit c32a2d
/* returns TRUE for being interrupted */
Packit c32a2d
int xfermem_write(txfermem *xf, void *buffer, size_t bytes);
Packit c32a2d
Packit c32a2d
void xfermem_done (txfermem *xf);
Packit c32a2d
#define xfermem_done_writer xfermem_init_reader
Packit c32a2d
#define xfermem_done_reader xfermem_init_writer
Packit c32a2d
Packit c32a2d
Packit c32a2d
#endif