#include #include #include #define dprintf(format, args...) fprintf(stderr, format, ##args) #define MAX_WIN_SIZE 32 #define MAX_APP_SIZE 1024 typedef struct rps_hdr_type { unsigned int sig; /* tv_usec at creation time */ unsigned short magic; /* 0x1a2b in net byte order */ unsigned short len; /* payload length excludes hdr */ unsigned char seq; /* seq # of this packet */ unsigned char ack; /* seq # of next rcv packet */ unsigned char win; /* # of free receive buffers */ unsigned char flags; /* See bit defs above. */ } rps_hdr_t; /* This structure defines an element of the send or receive */ /* ring buffer. */ typedef struct rps_buf_type { double ts; /* Transmit time stamp */ rps_hdr_t hdr; /* rps hdr */ unsigned char data[MAX_APP_SIZE]; /* the app data */ } rps_buf_t; /* This structure defines a ring buffer. Each rps */ /* has both a sender ring and a receiver ring. */ typedef struct ring_type { int shutdown; /* 1 -> connection shutdown */ int nextin; /* next producer slot */ int nextout; /* next consumer item */ int slots; /* # of free slots */ int items; /* # of free items */ pthread_cond_t slot_cv; /* synchronization structs */ pthread_mutex_t slot_mtx; pthread_cond_t item_cv; pthread_mutex_t item_mtx; rps_buf_t bufs[MAX_WIN_SIZE]; /* ring buffers */ } ring_t;