msgRead.h File Reference

#include "msgCommon.h"

Go to the source code of this file.

Functions

int msgLogReadInit ()
int msgRead (mdMsgLogBuffer *msgbuffer, char *ip, const int maxiplen)

Function Documentation

int msgLogReadInit (  ) 

Definition at line 40 of file msgLogLib/msgRead.c.

References adr_srvr, DAQ_LOG_FACILITY, DAQ_MSG_IP, lSocket, MSGLOG_DEFAULT_IP, MSGLOG_PORT, and port.

Referenced by MAIN_FUNCTION().

00041 {
00042 #ifdef VxWorks
00043   return -1;
00044 #else
00045   int z=0;
00046   int port = MSGLOG_PORT;
00047   const char* ip = getenv(DAQ_MSG_IP);
00048   const char* portenv=0;
00049   if(ip==NULL)
00050     {
00051       ip = MSGLOG_DEFAULT_IP;
00052     }
00053   memset(&adr_srvr, 0, sizeof(adr_srvr));
00054   adr_srvr.sin_family = AF_INET;
00055   portenv = getenv("DAQ_MSG_PORT");
00056   if(portenv!=NULL)
00057     {
00058       sscanf(portenv, "%d", &port);
00059     }
00060 
00061   adr_srvr.sin_port = htons(port);
00062   adr_srvr.sin_addr.s_addr = htonl(INADDR_ANY);
00063 
00064   if(adr_srvr.sin_addr.s_addr == INADDR_NONE)
00065     {
00066       syslog(DAQ_LOG_FACILITY |LOG_ERR, "Bad address, unable to open msgLog socket");
00067       return -1;
00068     }
00069   
00070   lSocket = socket(AF_INET, SOCK_DGRAM, 0);
00071   if(lSocket==-1)
00072     {
00073       syslog(DAQ_LOG_FACILITY |LOG_ERR, "Unable to create msgRead socket:%s", strerror(errno));
00074       return -1;
00075     }
00076 
00077   z = bind(lSocket, (struct sockaddr *)&adr_srvr, sizeof(adr_srvr));
00078   if(z==-1)
00079     {
00080       syslog(DAQ_LOG_FACILITY |LOG_ERR, "bind() failed: %s", strerror(errno));
00081       close(lSocket);
00082       lSocket=-1;
00083       return -1;
00084     }
00085   return 0;
00086 #endif
00087 }

int msgRead ( mdMsgLogBuffer msgbuffer,
char *  ip,
const int  maxiplen 
)

Definition at line 90 of file msgLogLib/msgRead.c.

References adr_clnt, DAQ_LOG_FACILITY, len, lSocket, and MSG_NOSIGNAL.

Referenced by MAIN_FUNCTION().

00091 {
00092 #ifdef VxWorks
00093   return -1;
00094 #else
00095   int len=0;
00096   unsigned int len_inet = sizeof(adr_clnt);
00097   struct timeval to;
00098   static fd_set socketlist;
00099   int rc=0;
00100   if(lSocket<=0) return -1;
00101   /*check that there is data waiting*/
00102   FD_ZERO(&socketlist);
00103   FD_SET(lSocket, &socketlist);
00104   to.tv_sec = 0;
00105   to.tv_usec = 10; /* 10000; */
00106   rc = select(lSocket+1, &socketlist, 0, &socketlist, &to);
00107   if(rc==0) return 0;
00108   if(rc==-1) return -1;
00109 
00110   if(FD_ISSET(lSocket, &socketlist)) return 0;
00111     
00112     len = recvfrom(lSocket,
00113                    msgbuffer, 
00114                    sizeof(mdMsgLogBuffer),
00115                    MSG_NOSIGNAL ,
00116                    (struct sockaddr*)&adr_clnt,
00117                    &(len_inet));
00118   if(len<0)
00119         {
00120           syslog(DAQ_LOG_FACILITY |LOG_ERR, "recvfrom() failed: %s", strerror(errno));
00121           return len;
00122         } 
00123   
00124   /*fill in ip details*/
00125   strncpy(ip, inet_ntoa(adr_clnt.sin_addr), maxiplength);
00126   return len;
00127 #endif
00128 }


Generated on 22 Nov 2017 for loon by  doxygen 1.6.1