SHMFIFO
Shared Memory Block FIFO Pipe Implementation Library
|
Latest version 1.0
21 September 2004
Download!
|
|
- About shmfifo
SHMFIFO library provides easy to use interface to shared mem for programs
where one process needs to send blocks of data to other process. It was
developed because pipe(2) and mkfifo(3) has very small buffer size (4k) and
unsuitable for many applications.
Shmfifo allows to put block of data in shared memory, get oldest block of
data from shared memory, and has additional feature to share one instance of
private data structure among all processes which uses library.
- How to use shmfifo
Before using, shared memory should be created. After creating shared memory,
process which wants to use it, should attach to memory. Then it can put and
get blocks to FIFO. After process is finished working with FIFO, it calls
shfifo_detach. When no processes will use FIFO, shared memory should be
deallocated.
Usally, lifecycle of shmfifo-based program is following:
- [parent] shmfifo_create
- [parent] fork(2)
- [both] shmfifo_attach
- [both] shmfifo_put, shmfifo_get (many times)
- [both] shmfifo_detach
- [parent] wait(2) or waitpid(2)
- [child] exit
- [parent] shmfifo_dealloc
shmfifo comes with test.c program, which is good sample of how to write
programs with shmfifo. It forks into 2 processes, parent generated
variable-length blocks, writes checksum into each block and put it into
FIFO. Child gets blocks from fifo, check if checksum is valid (it's always
valid if there is no bug in program) and prints debug info. after large
number of blocks gets transferred, both processes are exit.
Additionally, shmfifo allows processes to share one private structure.
test.c uses this structure to store counter, which is increased each time
when parent cannot put block to FIFO because it's already full and has to
wait until child will get block. If small amount of memory allocated for
FIFO, then parent will wait more often.
- Functions of shmfifo
struct shmhandle *shmfifo_create(int npages, int privsz);
- Allocated shared memory, semaphores, and performs initialization of
internal structures. Returns ptr to allocated shmhandle struct of NULL if
there were errors. npages is number of 4k pages which should be used for
shared memory. privsz is size of private structure if you want to use it.
shmfifo_create should be called from main process and shmhandle should
exists in all processes which will work with library functions.
int shmfifo_attach(struct shmhandle *shm);
- Attaches process to fifo. Returns -1 if error and 1 if ok.
void shmfifo_detach(struct shmhandle *shm);
- Detaches.
void shmfifo_dealloc(struct shmhandle *shm);
- Deallocates all shared memory. Should be called in main process after all
children (and main process) called detach function.
int shmfifo_put(struct shmhandle *shm, void *data, int sz);
- creates block in shared memory of size 'sz' and content copied from data.
returns sz if successful or -1 if failed (e.g. if no enough free space in
fifo).
int shmfifo_get(struct shmhandle *shm, void *data,int sz);
- gets block from fifo. data points to area where it will be copies, sz is
size of this area. Returns size of copied data or -2 if sz is less then
blocksize and -1 if any other error.
void shmfifo_setpriv(struct shmhandle *shm, void *priv);
void shmfifo_getpriv(struct shmhandle *shm, void *priv);
- copies private structure to shared memory and back from shared memory to
usual process memory.
int shmfifo_empty(struct shmhandle *shm);
- returns 1 if FIFO is empty.
|
| Free installation and support for evaluation version of MailRecon
|
Want to control your SMTP traffic? Want to prevent leaking of commercial
information? In other words, want to use
MailRecon
?
Contact us
and we will be happy to answer all your questions and install evaluation version on your servers for free!
|
| MailRecon 1.3 released
|
Now with Linux and FreeBSD support!
(and surely, few bugs are fixed)
|
| ShmFIFO 1.0 released
|
|
Library which implements FIFO functionality via shared memory for
interprocess communications - ShmFIFO 1.0 released with GNU General Public License.
|
|
|
|
© 2004 World Wide Web Security.
http://www-security.com/
info@www-security.com
|