XrdMonSndFileSenderApp.cc

Go to the documentation of this file.
00001 /*****************************************************************************/
00002 /*                                                                           */
00003 /*                        XrdMonSndDummyXrootdApp.cc                         */
00004 /*                                                                           */
00005 /* (c) 2005 by the Board of Trustees of the Leland Stanford, Jr., University */
00006 /*                            All Rights Reserved                            */
00007 /*       Produced by Jacek Becla for Stanford University under contract      */
00008 /*              DE-AC02-76SF00515 with the Department of Energy              */
00009 /*****************************************************************************/
00010 
00011 // $Id: XrdMonSndFileSenderApp.cc 24468 2008-06-22 16:47:03Z ganis $
00012 
00013 #include "XrdMon/XrdMonArgParser.hh"
00014 #include "XrdMon/XrdMonArgParserConvert.hh"
00015 #include "XrdMon/XrdMonHeader.hh"
00016 #include "XrdMon/XrdMonSndDebug.hh"
00017 #include "XrdMon/XrdMonSndTransmitter.hh"
00018 
00019 #include <assert.h>
00020 #include <unistd.h>  /* usleep */
00021 #include <sys/time.h>
00022 #include <fstream>
00023 #include <iomanip>
00024 #include "XrdSys/XrdSysHeaders.hh"
00025 #include <strings.h>
00026 #include <sstream>
00027 using std::cerr;
00028 using std::cout;
00029 using std::endl;
00030 using std::fstream;
00031 using std::ios;
00032 using std::setfill;
00033 using std::setw;
00034 using std::stringstream;
00035 
00036 
00037 using namespace XrdMonArgParserConvert;
00038 
00039 // known problems with 2 and 4
00040 //const kXR_int64 NOCALLS = 8640000;   24h worth
00041 const kXR_int64 NOCALLS = 1000000000;
00042 const kXR_int16 maxNoXrdMonSndPackets = 5;
00043 const char*     DEFAULT_FILE  = "/tmp/active/rcv";
00044 const kXR_int16 DEFAULT_SLEEP = 0;
00045 
00046 void
00047 printHelp()
00048 {
00049     cout << "\nxrdmonFileSender\n"
00050          << "    [-host <hostName>]\n"
00051          << "    [-port <portNr>]\n"
00052          << "\n"
00053          << "-host <hostName>         Name of the receiver's host.\n"
00054          << "                         Default value is \"" << DEFAULT_HOST << "\".\n"
00055          << "-port <portNr>           Port number of the receiver's host\n"
00056          << "                         Default valus is \"" << DEFAULT_PORT << "\".\n"
00057          << "-inputFile <fileName>    Input file name (with path or without).\n"
00058          << "                         Default value is \"" << DEFAULT_FILE << "\".\n"
00059          << "-sleep <value>           number of miliseconds to sleep between each packet.\n"
00060          << "                         Default value is \"" << DEFAULT_SLEEP << "\".\n"
00061          << endl;
00062 }
00063 
00064 
00065 
00066 int main(int argc, char* argv[])
00067 {
00068     XrdMonArgParser::ArgImpl<const char*, Convert2String>
00069         arg_host("-host", DEFAULT_HOST);
00070     XrdMonArgParser::ArgImpl<int, Convert2Int> 
00071         arg_port("-port", DEFAULT_PORT);
00072     XrdMonArgParser::ArgImpl<const char*, Convert2String>
00073         arg_file("-inputFile", "/tmp/active.rcv");
00074     XrdMonArgParser::ArgImpl<int, Convert2Int> 
00075         arg_sleep("-sleep", DEFAULT_SLEEP);
00076 
00077     try {
00078         XrdMonArgParser argParser;
00079         argParser.registerExpectedArg(&arg_host);
00080         argParser.registerExpectedArg(&arg_port);
00081         argParser.registerExpectedArg(&arg_file);
00082         argParser.registerExpectedArg(&arg_sleep);
00083         argParser.parseArguments(argc, argv);
00084     } catch (XrdMonException& e) {
00085         e.printIt();
00086         printHelp();
00087         return 1;
00088     }
00089 
00090     const char* inFName = arg_file.myVal();
00091     if ( 0 != access(inFName, R_OK) ) {
00092         cerr << "Invalid input file name \"" << inFName << "\"" << endl;
00093         return 2;
00094     }
00095 
00096     kXR_int16 msecSleep = arg_sleep.myVal();
00097 
00098     XrdMonSndDebug::initialize();
00099 
00100     XrdMonSndTransmitter transmitter;
00101 
00102     assert ( !transmitter.initialize(arg_host.myVal(), arg_port.myVal()) );
00103 
00104     fstream _file;
00105     _file.open(inFName, ios::in|ios::binary);
00106     _file.seekg(0, ios::end);
00107     kXR_int64 fSize = _file.tellg();
00108     _file.seekg(0, ios::beg);
00109 
00110     int uniqueId = 0;
00111     
00112     while ( _file && fSize > _file.tellg() ) {
00113         // read header
00114         char hBuffer[HDRLEN];
00115         _file.read(hBuffer, HDRLEN);
00116 
00117         //decode header
00118         XrdMonHeader header;
00119         header.decode(hBuffer);
00120         cout << setw(10) << ++uniqueId << " Sending " << header << endl;
00121 
00122         // read the rest of the packet
00123         char packetData[MAXPACKETSIZE];
00124         _file.read(packetData, header.packetLen()-HDRLEN);
00125 
00126         // assemble the packet
00127         XrdMonSndPacket packet;
00128         packet.init(header.packetLen());
00129         bcopy(hBuffer,     packet.offset(0),      HDRLEN);
00130         bcopy(packetData,  packet.offset(HDRLEN), header.packetLen()-HDRLEN);
00131 
00132         transmitter(packet);
00133 
00134         usleep(msecSleep);
00135     }
00136     
00137     transmitter.shutdown();
00138     
00139     return 0;
00140 }

Generated on Tue Jul 5 14:46:43 2011 for ROOT_528-00b_version by  doxygen 1.5.1