00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "XrdMon/XrdMonBufferedOutput.hh"
00019 #include "XProtocol/XPtypes.hh"
00020 #include "XrdSys/XrdSysHeaders.hh"
00021 #include <unistd.h>
00022 #include <assert.h>
00023 using namespace std;
00024
00025 int flushFreq = 30;
00026
00027 extern "C"
00028 void* flush2disk(void* arg)
00029 {
00030 XrdMonBufferedOutput* bOut = (XrdMonBufferedOutput*) arg;
00031 assert ( 0 != bOut );
00032
00033 while ( 1 ) {
00034 sleep(flushFreq);
00035 bOut->flush();
00036 }
00037 return (void*) 0;
00038 }
00039
00040 int main(int argc, char* argv[])
00041 {
00042 if ( argc != 2 ) {
00043 cerr << "Expected arg: <outFileName>" << endl;
00044 return 1;
00045 }
00046
00047 const char* fName = argv[1];
00048 const kXR_int32 bufSize = 128*1024;
00049
00050 XrdMonBufferedOutput bOut(fName, (const char*) 0, bufSize);
00051
00052 pthread_t flushThread;
00053 if ( 0 != pthread_create(&flushThread,
00054 0,
00055 flush2disk,
00056 (void*)&bOut) ) {
00057 cerr << "Can't start flush2disk thread" << endl;
00058 return 2;
00059 }
00060
00061 char line[1024];
00062 while ( 1 ) {
00063 cin.getline(line, 1024);
00064 strcat(line, "\n");
00065 bOut.add(line);
00066 }
00067
00068
00069 bOut.flush();
00070 return 0;
00071 }
00072
00073