fifo_fnc.h

Go to the documentation of this file.
00001 /* 
00002  * $Id$
00003  *
00004  * Copyright (C) 2006 Voice Sistem SRL
00005  *
00006  * This file is part of a module for Kamailio, a free SIP server.
00007  *
00008  * Kamailio is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version
00012  *
00013  * Kamailio is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License 
00019  * along with this program; if not, write to the Free Software 
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  * History:
00023  * --------
00024  * 2006-09-25: first version (bogdan)
00025  */
00026 
00033 #ifndef _FIFO_FNC_H_
00034 #define _FIFO_FNC_H_
00035 
00036 #include <stdio.h>
00037 #include <stdarg.h>
00038 #include <errno.h>
00039 
00040 
00044 #define FIFO_REPLY_RETRIES  4
00045 #define FIFO_REPLY_WAIT     80000
00046 
00047 FILE* mi_init_fifo_server(char *fifo_name, int mode, int uid, int gid,
00048                 char* fifo_reply_dir);
00049 
00050 void  mi_fifo_server(FILE *fifostream);
00051 
00052 int   mi_read_line( char *b, int max, FILE *stream, int *read);
00053 
00054 static inline int mi_fifo_reply( FILE *stream, char *reply_fmt, ... )
00055 {
00056         int r;
00057         va_list ap;
00058 
00059 retry:
00060         va_start(ap, reply_fmt);
00061         r = vfprintf( stream, reply_fmt, ap);
00062         va_end(ap);
00063         if (r<=0) {
00064                 if ((errno==EINTR)||(errno==EAGAIN)||(errno==EWOULDBLOCK)) {
00065                         goto retry;
00066                 }
00067                 LM_ERR("fifo_error: write error: %s\n", strerror(errno));
00068                 return -1;
00069         }
00070         return 0;
00071 }
00072 
00073 
00074 #endif /* _FIFO_FNC_H */
00075