16 #ifndef __FIFOUTILS_H__
17 #define __FIFOUTILS_H__
33 #include "profileutils.h"
37 #define MAX_FNAME_SZ 256
53 #define ERRMSG(msg) fprintf(stderr, "%s (%s line %i)\n", msg,__FILE__,__LINE__)
56 #define ERRMSG(msg) fifo_error_message(msg, __FILE__, __LINE__)
61 #define RTSIGIO (SIGRTMIN+4)
62 #define RTSIGIGN (SIGRTMIN+5)
63 #define RTSIGPING (SIGRTMIN+6)
125 int set_fifo_channel(fifo_channel *fc,
const char *fin,
const char *fout,
int (*inp_hand)(fifo_channel *),
void *adata);
221 int read_queue_nextpos;
334 #endif //__FIFOUTILS_H__
int timeout
true if last read was a timeout.
char * infname
input file name
int set_fifo_list_rtsig(fifo_list *fl)
Change from SIGIO to real time signals.
int nchan
The number of channels.
fd_set fds
the fd_set for the async SIGIO handler
char * server_response
buffer for the server response after output
The basic fifo_channel structure.
void * auxdata
for passing other data to the handler. note that no memory management is done.
fifo_list * global_fifo_list
The global fifo_list, for signal handling.
int rq_sz
Size of the read_queue.
int open_fifo_channel_out_nolock(fifo_channel *fc)
Opens the output fifo channel for non-blocking writing without an exclusive lock. ...
int * read_queue
Circular buffer which contains the fifo_ch index to read next.
int read_fifo_channel(fifo_channel *fc)
Read data from the input fifo channel.
int init_fifo_list(fifo_list *fl)
Initialize the fifo_list.
int connect_fifo_list_nolock(fifo_list *fl)
Open each fifo in the list, without exclusive locks.
char * outfname
output file name
A structure to hold a list of fifo_channels.
int ropen_async(char *fname, int nolock)
Open a file for non-blocking asynchronous reads.
fifo_channel * fifo_ch
An array of fifo_channels.
time_t last_atime_out
last access time for the output channel, used for clearing timeouts
int init_fifo_list_pending_reads(fifo_list *fl)
Populates the fd_to_fifo_ch_index array.
int open_fifo_channel_in_nolock(fifo_channel *fc)
Opens the input fifo channel for async reading without an exculsive lock.
int set_fifo_channel(fifo_channel *fc, const char *fin, const char *fout, int(*inp_hand)(fifo_channel *), void *adata)
Set the details of the fifo_channel.
int write_fifo_channel_seqmsg(fifo_channel *fc, const char *com, int comlen, char *seqmsg)
Write data to the output channel, including a sequence message.
int open_fifo_channel_out(fifo_channel *fc)
Opens the output fifo channel for non-blocking writing with an exclusive lock.
void fifo_error_message(const char *, const char *, int)
The fifoutils error reporting function.
int wopen_nonblock(char *fname, int nolock)
Open a file for non-blocking writes.
int * pending_reads
An array, with same index as fifo_ch, which tracks number of pending reads on each channel...
void catch_fifo_response_list(int signum)
A SIGIO handler, which uses global_fifo_list to call the appropriate handler.
int maxfile
the maximum file descriptor for the SIGIO handler to worry about.
int create_fifos(fifo_channel *fc)
Creates the fifos if they don't already exist.
int set_fifo_list_channel(fifo_list *fl, int nch, int buffsz, const char *fin, const char *fout, int(*inp_hand)(fifo_channel *), void *adata)
Set the details of one channel in the list.
void catch_fifo_pending_reads(int signum, siginfo_t *siginf, void *ucont)
A handler for a R/T SIGIO, which just updates the pending reads meta data but does no actual signal h...
int(* input_handler)(fifo_channel *)
the handler for input
int RTSIGIO_overflow
flag indicating that the signal queue has overflown.
double get_currt()
Returns time since the Unix epoch in double precision seconds.
char * seqmsg
Pointer to a possible sequence message, normally just the \0 in server_response.
int write_fifo_channel(fifo_channel *fc, const char *com, int comlen)
Write data to the output channel.
int setup_fifo_list(fifo_list *fl, int nch)
Setup a fifo_list.
int init_fifo_channel(fifo_channel *fc)
Initializes the fifo_channel structure.
int fd_out
output file descriptor
int * fd_to_fifo_ch_index
Array mapping a file descriptor to an index in the fifo_ch array.
int fd_in
input file descriptor
void catch_fifo_standard_sigio(int signum)
A handler for normal SIGIO when we should have gotten the R/T SIGIO, implying signal queue overflow...
int sr_sz
size of the server_response
int check_if_in_locked(fifo_channel *fc)
Checks if the output fifo of the channel is locked.
int fifo_list_do_pending_read(fifo_list *fl)
Runs through the pending reads, dispatching each handler in turn.
int setup_fifo_channel(fifo_channel *fc, size_t buffsz)
Allocate the server_response buffer.
int read_queue_pos
The current position in the read_queue.
int open_fifo_channel_in(fifo_channel *fc)
Opens the input fifo channel for async reading with an exculsive lock.
int connect_fifo_list(fifo_list *fl)
Open each fifo in the list, with exclusive lock on the input fifo.
int tot_pending_reads
The total number of pending reads.
time_t last_atime_in
last access time for the input channel, used for clearing timeouts