common.h
///////////////////////////////////////////////////////////////////////////////
// Filename: common.h
///////////////////////////////////////////////////////////////////////////////
// Purpose: includes common other include files, including non-std. ones
///////////////////////////////////////////////////////////////////////////////
// History:
// ========
//
// Date Time Name Description
// -------- -------- -------- ------------------------------------------------
// 96/02/05 23:24:53 muellerg: created
//
///////////////////////////////////////////////////////////////////////////////
#ifndef __COMMON_H__
#define __COMMON_H__
// not all compilers have buildin bool, so provide it if necessary
#ifndef linux
#ifndef __GNUC__
#ifndef DEFINED_BOOL
#define DEFINED_BOOL
enum bool { false = 0, true = 1};
#endif /* DEFINED_BOOL */
#endif /* __GNUC__ */
#endif /* linux */
// Feature test switches ///////////////////////////// Feature test switches //
/* NONE */
// System headers /////////////////////////////////////////// System headers //
#include <stdlib.h>
#include <iostream.h>
#include <fstream.h>
#include <sys/types.h>
// Local headers ///////////////////////////////////////////// Local headers //
#include "common/errors.h"
#include "common/clocktimer.h"
#include "common/cputimer.h"
#include "common/measurement.h"
#ifdef sun
// sun has not defined these
#ifndef INADDR_NONE
#define INADDR_NONE ((unsigned long)0xffffffff) /* -1 return */
#endif
// this is missing in unistd.h
extern "C" {
int gethostname(char *hostname, size_t size);
}
// sun does not have strings.h. This is the contents of strings.h:
extern "C" {
extern char *index(const char *, char);
extern char *rindex(const char *, char);
extern void bcopy(const char *, char *, int);
extern int bcmp(const char *, const char *, int);
extern void bzero(char *, int);
extern int ffs(int);
}
#endif /* sun */
// Macros /////////////////////////////////////////////////////////// Macros //
// needed for TLI examples
#define DEV_UDP "/dev/udp" /* TLI udp device name */
#define DEV_TCP "/dev/tcp" /* TLI tcp device name */
#ifdef sun
#define WAIT_ANY ((pid_t)-1)
#endif
#ifdef hpux
#define WAIT_ANY ((pid_t)-1)
#endif
// used in various example programs as maximum length of lines
#define MAXLINE 255 /* maximum line length */
// File scope objects /////////////////////////////////// File scope objects //
/* NONE */
// External variables, functions, and classes ///////////// External objects //
/* common/readline.h */
// reads a line with recognizing EOF immediately
int readline(istream &in, char *buf, int max_len);
/* common/readn.c */
// read numbytes bytes, even if individual read()s are not fully successful
int readn(int fd, char* ptr, int numbytes);
/* common/writen.h */
// write numbytes bytes, even if individual write()s are not fully successful
int writen(int fd, char* ptr, int numbytes);
/* common/readline2.h */
// read a line from a file descriptor
int readline(int fd, char* ptr, int maxlen);
/* local/synchronize.c */
// Initialize everything (set up signal handler etc.)
void synchronization_init(void);
// Send signal from child to parent process
void synchronization_signal_parent(pid_t pid);
// Send signal from parent to child
void synchronization_signal_child(pid_t pid);
// wait for signal (from parent or child)
void synchronization_wait(void);
// reset signal mask to how it was when calling synchronization_init()
void synchronization_reset(void);
/* if readdata() and writedata() should be synchronized via
* signals, both have to be initialized by synchronization_init()!
*/
/* local/readdata.c */
// reads data generated by writedata() and measures how long this takes
bool readdata(char *basename, char *ext, int fd, pid_t pid=0);
/* local/writedata.c */
// writes data for readdata() and measures how long this takes
bool writedata(char *basename, char *ext, int fd, pid_t pid=0);
/* common/ssleep.c */
// sleep for usecs microseconds
void ssleep(int usecs);
/* common/catchchildren.c */
// install a SIGCHLD catching function so zombies are avoided
void catch_children(void);
/* distSOCK/safesend.c */
// safe sendto(), same parameters
int safesendto(int s, const void *msg, int len, unsigned int flags,
const struct sockaddr *to, int tolen);
// safe recvfrom(), same parameters
int saferecvfrom(int s, void *buf, int len, unsigned int flags,
struct sockaddr *from, int *fromlen);
// Signal catching functions ///////////////////// Signal catching functions //
/* NONE */
// Structures, unions, and class definitions /////////////////// Definitions //
/* NONE */
// Functions and class implementation /// Functions and class implementation //
inline int max(int a, int b)
{
return (a>b) ? a : b;
}
// Main /////////////////////////////////////////////////////////////// Main //
/* NONE */
#endif /* __COMMON_H__ */