UdpLogger.h

Go to the documentation of this file.
00001 // Copyright CERN 2012 - Developed in collaboration with GSI
00002 //
00003 // UdpLogger.h: interface of a simple UDP Logger object.
00004 //
00005 //
00006 // Author: FESA team
00008 //
00009 //  May 2007
00010 //      - added to the FESA Framework for the DIAGNOSTIC protoyping
00011 //
00012 #ifndef __UdpLogger__H__
00013 #define __UdpLogger__H__
00014 
00015 #include <stdlib.h>
00016 #include <stdio.h>
00017 #include <sys/types.h>
00018 #include <sys/socket.h>
00019 #include <unistd.h>
00020 #include <fcntl.h>
00021 #include <netinet/in.h>
00022 #include <netinet/tcp.h>
00023 #include <netdb.h>
00024 #include <arpa/inet.h>
00025 #include <errno.h>
00026 #include <fesa-core/Exception/FesaException.h>
00027 
00028 //UDP frame cannot exceed 8Kb.
00029 //Loop is required for large udp frame (ie: diagnostic Config/State)
00030 #define MAX_UDP_SEND_SIZE       8000 //less than (8*1024) just for security
00031 namespace fesa
00032 {
00033 
00034     class UdpLogger
00035     {
00036 
00037         private:
00038             // UDP socket
00039             int32_t udpSock;
00040             // UDP attributes
00041             struct sockaddr_in udpAttr;
00042             //connected mode = true: to receive ICMP "not reachable" if nobody is listening
00043             bool udpConn;
00044 
00045         public:
00052             UdpLogger(const char* hostname, unsigned short& port, const bool connectMode);
00053             ~UdpLogger();
00054 
00055             /* Send string message to UPD channel
00056              * . for perfomance aspect, the UdpLogger is not thread safe, it does not use synchonization mechanism.
00057              * . it's recommended to limit the message size to the network MTU (1480 bytes for Ethernet)
00058              * return -1 on failure (no listener)
00059              */
00060             int32_t sendStr(const char* msg);
00061 
00062     };
00063 }
00064 
00065 #endif // __UdpLogger__H__

Generated on 18 Jan 2013 for Fesa by  doxygen 1.6.1