performance/fifoserver.c
///////////////////////////////////////////////////////////////////////////////
// Filename: fifoserver.c
///////////////////////////////////////////////////////////////////////////////
// Purpose: measures performance of fifos (together with fifoclient.c)
///////////////////////////////////////////////////////////////////////////////
// History:
// ========
//
// Date Time Name Description
// -------- -------- -------- ------------------------------------------------
// 96/02/29 06:43:04 muellerg: created
//
///////////////////////////////////////////////////////////////////////////////
// Feature test switches ///////////////////////////// Feature test switches //
/* NONE */
// System headers /////////////////////////////////////////// System headers //
#include <sys/types.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
// Local headers ///////////////////////////////////////////// Local headers //
#include "../common.h"
// Macros /////////////////////////////////////////////////////////// Macros //
/* NONE */
// File scope objects /////////////////////////////////// File scope objects //
const char *fifo_file="example_fifo";
const mode_t permission =
(S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
// = 0666 = rw-rw-rw
// External variables, functions, and classes ///////////// External objects //
/* NONE */
// Signal catching functions ///////////////////// Signal catching functions //
/* NONE */
// Structures, unions, and class definitions /////////////////// Definitions //
/* NONE */
// Functions and class implementation /// Functions and class implementation //
/* NONE */
// Main /////////////////////////////////////////////////////////////// Main //
/* NONE */
int
main(int argc, char *argv[])
{
error.set_program_name(argv[0]);
char buffer[10];
umask(0);
mkfifo(fifo_file, permission);
// this would be equivalent:
// mknod(fifo_file, S_IFIFO|permission, 0);
int fd = open(fifo_file, O_RDONLY);
if(fd)
{
// wait for a client
read(fd, buffer, 2);
// and do measurements
readdata(argv[0], "read", fd, 0); // we don't know clients pid
}
else
error.system("can't open fifo");
if( unlink(fifo_file) == -1)
error.system("can't remove special fifo file");
return(EXIT_SUCCESS);
}