Subversion Repositories shark

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 1
/*
2
 *   xfermem.h
3
 *
4
 *   Oliver Fromme  <oliver.fromme@heim3.tu-clausthal.de>
5
 *   Sat Mar 29 04:41:34 MET 1997
6
 *
7
 *   This is a stand-alone module which implements a unidirectional,
8
 *   fast pipe using mmap().  Its primary use is to transfer large
9
 *   amounts of data from a parent process to its child process,
10
 *   with a buffer in between which decouples blocking conditions
11
 *   on both sides.  Control information is transferred between the
12
 *   processes through a socketpair.  See xftest.c for an example on
13
 *   how to use this module.
14
 */
15
 
16
#ifndef TRUE
17
#define FALSE 0
18
#define TRUE  1
19
#endif
20
 
21
typedef unsigned char byte;
22
 
23
typedef struct {
24
        int freeindex;  /* [W] next free index */
25
        int readindex;  /* [R] next index to read */
26
        int fd[2];
27
        int wakeme[2];
28
        byte *data;
29
        byte *metadata;
30
        int size;
31
        int metasize;
32
} txfermem;
33
/*
34
 *   [W] -- May be written to by the writing process only!
35
 *   [R] -- May be written to by the reading process only!
36
 *   All other entries are initialized once.
37
 */
38
 
39
void xfermem_init (txfermem **xf, int bufsize, int msize);
40
void xfermem_init_writer (txfermem *xf);
41
void xfermem_init_reader (txfermem *xf);
42
 
43
int  xfermem_write (txfermem *xf, byte *data, int count);
44
int  xfermem_read  (txfermem *xf, byte *data, int count);
45
 
46
int xfermem_get_freespace (txfermem *xf);
47
int xfermem_get_usedspace (txfermem *xf);
48
#define XF_CMD_WAKEUP    0x02
49
#define XF_CMD_TERMINATE 0x03
50
#define XF_WRITER 0
51
#define XF_READER 1
52
int xfermem_getcmd (int fd, int block);
53
int xfermem_putcmd (int fd, byte cmd);
54
int xfermem_block (int fd, txfermem *xf);
55
 
56
void xfermem_done (txfermem *xf);
57
#define xfermem_done_writer xfermem_init_reader
58
#define xfermem_done_reader xfermem_init_writer
59
 
60
/* EOF */