| 1 |
/* |
| 2 |
xfermem: unidirectional fast pipe |
| 3 |
|
| 4 |
copyright ?-2006 by the mpg123 project - free software under the terms of the LGPL 2.1 |
| 5 |
see COPYING and AUTHORS files in distribution or http://mpg123.org |
| 6 |
initially written by Oliver Fromme |
| 7 |
old timestamp: Sat Mar 29 04:41:34 MET 1997 |
| 8 |
|
| 9 |
This is a stand-alone module which implements a unidirectional, |
| 10 |
fast pipe using mmap(). Its primary use is to transfer large |
| 11 |
amounts of data from a parent process to its child process, |
| 12 |
with a buffer in between which decouples blocking conditions |
| 13 |
on both sides. Control information is transferred between the |
| 14 |
processes through a socketpair. See xftest.c for an example on |
| 15 |
how to use this module. |
| 16 |
|
| 17 |
note: xftest not there anymore |
| 18 |
*/ |
| 19 |
|
| 20 |
#ifndef _XFERMEM_H_ |
| 21 |
#define _XFERMEM_H_ |
| 22 |
|
| 23 |
#include "../compat/compat.h" |
| 24 |
|
| 25 |
typedef struct { |
| 26 |
size_t freeindex; /* [W] next free index */ |
| 27 |
size_t readindex; /* [R] next index to read */ |
| 28 |
int fd[2]; |
| 29 |
char *data; |
| 30 |
char *metadata; |
| 31 |
size_t size; |
| 32 |
size_t metasize; |
| 33 |
} txfermem; |
| 34 |
/* |
| 35 |
* [W] -- May be written to by the writing process only! |
| 36 |
* [R] -- May be written to by the reading process only! |
| 37 |
* All other entries are initialized once. |
| 38 |
*/ |
| 39 |
|
| 40 |
void INT123_xfermem_init (txfermem **xf, size_t bufsize, size_t msize, size_t skipbuf); |
| 41 |
void INT123_xfermem_init_writer (txfermem *xf); |
| 42 |
void INT123_xfermem_init_reader (txfermem *xf); |
| 43 |
|
| 44 |
size_t INT123_xfermem_get_freespace (txfermem *xf); |
| 45 |
size_t INT123_xfermem_get_usedspace (txfermem *xf); |
| 46 |
|
| 47 |
/* Unless otherwise noted, each command demands a reponse if issued from the |
| 48 |
writer. The reader does not expect responses, only orders. */ |
| 49 |
enum xf_cmd_code |
| 50 |
{ |
| 51 |
XF_CMD_PING = 1 /**< Wake up and give a response, not changing any state. */ |
| 52 |
, XF_CMD_PONG /**< The response to a ping. */ |
| 53 |
, XF_CMD_DATA /**< Re-check the amount of data available without response. */ |
| 54 |
, XF_CMD_TERMINATE /**< Stop operation. */ |
| 55 |
, XF_CMD_DROP /**< Drop current buffer contents. */ |
| 56 |
, XF_CMD_DRAIN /**< Consume current buffer contents now. */ |
| 57 |
, XF_CMD_PAUSE /**< Pause operation, wait for next command. */ |
| 58 |
, XF_CMD_CONTINUE /**< Continue operation. */ |
| 59 |
, XF_CMD_IGNLOW /**< Ignore situation with low buffer fill. */ |
| 60 |
, XF_CMD_OK /**< Response from reader: Operation succeeded. */ |
| 61 |
, XF_CMD_ERROR /**< Response from reader: Operation failed. */ |
| 62 |
, XF_CMD_CUSTOM1 /**< Some custom command to be filled with meaning. */ |
| 63 |
, XF_CMD_CUSTOM2 /**< Some custom command to be filled with meaning. */ |
| 64 |
, XF_CMD_CUSTOM3 /**< Some custom command to be filled with meaning. */ |
| 65 |
, XF_CMD_CUSTOM4 /**< Some custom command to be filled with meaning. */ |
| 66 |
, XF_CMD_CUSTOM5 /**< Some custom command to be filled with meaning. */ |
| 67 |
, XF_CMD_CUSTOM6 /**< Some custom command to be filled with meaning. */ |
| 68 |
, XF_CMD_CUSTOM7 /**< Some custom command to be filled with meaning. */ |
| 69 |
, XF_CMD_CUSTOM8 /**< Some custom command to be filled with meaning. */ |
| 70 |
}; |
| 71 |
|
| 72 |
#define XF_WRITER 0 |
| 73 |
#define XF_READER 1 |
| 74 |
int INT123_xfermem_getcmd(int fd, int block); |
| 75 |
int INT123_xfermem_getcmds(int fd, int block, byte* cmds, int count); |
| 76 |
int INT123_xfermem_putcmd(int fd, byte cmd); |
| 77 |
int INT123_xfermem_writer_block(txfermem *xf); |
| 78 |
/* returns TRUE for being interrupted */ |
| 79 |
int INT123_xfermem_write(txfermem *xf, void *buffer, size_t bytes); |
| 80 |
|
| 81 |
void INT123_xfermem_done (txfermem *xf); |
| 82 |
#define xfermem_done_writer INT123_xfermem_init_reader |
| 83 |
#define xfermem_done_reader INT123_xfermem_init_writer |
| 84 |
|
| 85 |
|
| 86 |
#endif |