Server.cc File Reference

#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <sys/param.h>
#include "netdb.h"
#include "TSystem.h"
#include "TApplication.h"
#include "DisplayServer.h"

Go to the source code of this file.

Defines

#define SECS   120

Functions

TROOT server ("ServerROOT","Root of the Server")
void abbruch (int sig)
void pipeBroken (int sig)
void timer (int)
int main (int argc, char **argv)

Variables

const int debFlags = 0x0
ConsumerList conslist ("")
TConsumerInfocurrInfo = 0

Define Documentation

#define SECS   120

Definition at line 31 of file Server.cc.

Referenced by main(), and timer().


Function Documentation

void abbruch ( int  sig  ) 

Definition at line 47 of file Server.cc.

References conslist, ConsumerList::Crashed, ConsumerList::Dead, exit(), ConsumerList::Finished, ConsumerList::setStatus(), and ConsumerList::Unknown.

Referenced by main().

00048   {
00049     //switch to old signalhandler to avoid loops!
00050     signal(SIGSEGV,SIG_DFL);
00051     signal(SIGABRT,SIG_DFL);
00052     signal(SIGTRAP,SIG_DFL);
00053     signal(SIGKILL,SIG_DFL);
00054     signal(SIGTERM,SIG_DFL);
00055   
00056     cout << "Display Server: End with signal " << sig << " ( = ";
00057     switch (sig) { 
00058       case SIGTERM:
00059         cout << "SIGTERM )";
00060         conslist.setStatus(0,ConsumerList::Dead);
00061         break;
00062       case SIGABRT:    
00063         cout << "SIGABRT )";
00064         conslist.setStatus(0,ConsumerList::Dead);
00065         break; 
00066       case SIGTRAP:
00067         cout << "SIGTRAP )";
00068         conslist.setStatus(0,ConsumerList::Crashed);
00069         break;
00070       case SIGSEGV:
00071         cout << "SIGSEGV )";
00072         conslist.setStatus(0,ConsumerList::Crashed);
00073         break;
00074       case SIGINT:
00075         // This should not occur anymore: SIG_IGN defined as signal 'handler'
00076         cout << "SIGINT )";
00077         break;
00078       case SIGKILL:
00079         cout << "SIGKILL )";
00080         conslist.setStatus(0,ConsumerList::Dead);
00081         break;
00082       case -1:
00083         cout << "-1 )" ;
00084         conslist.setStatus(0,ConsumerList::Finished);
00085         break;
00086       case SIGPIPE:
00087         // This should not occur anymore: SIG_IGN defined as signal 'handler'
00088         cout << "SIGPIPE )";
00089         break;
00090       default:    
00091         cout << "??? )";
00092         conslist.setStatus(0,ConsumerList::Unknown);
00093         break;
00094       }
00095     cout << endl;
00096     cout << "Report end to the StateManager" << endl;
00097     //    conslist.sendList("b0dap30.fnal.gov",9090); 
00098     //cout << "open sockets" << endl;
00099     // gROOT->GetListOfSockets()->ls();
00100     TIter next(gROOT->GetListOfSockets());
00101     TSocket* socktmp = 0;
00102     while (( socktmp = (TSocket*)next() )) 
00103       {
00104         socktmp->Close();
00105         gROOT->GetListOfSockets()->Remove(socktmp);
00106         //    // is called by close
00107       }
00108     cout << "sockets closed" << endl;
00109     // gROOT->GetListOfSockets()->ls();
00110     //conslist.print();
00111     exit(sig);
00112   }

int main ( int  argc,
char **  argv 
)

Definition at line 137 of file Server.cc.

References abbruch(), DisplayServer::connectClient(), conslist, debFlags, DisplayServer::errorFlag(), exit(), DisplayServer::getCurrentInfo(), pipeBroken(), DisplayServer::pollClients(), DisplayServer::pollConsumer(), SECS, spaces, and timer().

00138 {
00139   const string myName("Display Server");
00140   bool useRootTimer = true;
00141   int consumerPort=9050;
00142   int timerFlag = 2;
00143   // timerFlag = 0  => Do not use any timer.
00144   // timerFlag = 1  => Use the SIGALRM timer.
00145   // timerFlag = 2  => Use the ROOT timer.    
00146 
00147   signal(SIGABRT,abbruch);
00148   signal(SIGTERM,abbruch);
00149   signal(SIGINT,SIG_IGN);
00150   signal(SIGSEGV,abbruch);
00151   signal(SIGTRAP,abbruch);
00152   signal(SIGKILL,abbruch);
00153   signal(SIGPIPE,pipeBroken);
00154   signal(SIGALRM,SIG_IGN);
00155 
00156   // dp hack (6/9/02) - start Server in batch mode
00157 
00158   gROOT->SetBatch(kTRUE);
00159 
00160   TApplication app("Server",&argc,argv);
00161 
00162   //-----------------------------------------------------------------------
00163   // Analyse the command line argument and open socket connection to 
00164   // the consumer. 
00165   if (argc<2) {
00166     cerr << "Display server: There was no consumer port number given in "
00167          << "the command line\n"
00168          << spaces << "==>> RETURN NOW !" << endl;
00169     exit(-1);
00170   }  
00171   if (!(consumerPort=atoi(argv[1]))) {
00172     cerr << "Display Server: Command line argument argv[1] is not an integer.\n"
00173          << "==>> RETURN NOW !" << endl;
00174     exit(-2);
00175   }
00176   if (argc > 2) {
00177     timerFlag = atoi(argv[2]);
00178     if (timerFlag == 2) useRootTimer = true;
00179     else                useRootTimer = false;
00180   }
00181 
00182   gROOT->cd();  
00183 
00184   // The following assumes that the display server runs on the same
00185   // machine as the consumer itself.
00186   char hostName[MAXHOSTNAMELEN];
00187   gethostname(hostName, MAXHOSTNAMELEN); 
00188         
00189   DisplayServer ds(hostName, consumerPort, gROOT, &conslist, useRootTimer);
00190   if (ds.errorFlag() < 0) {
00191     cerr << myName << ": Failure when instantiating the DisplayServer object.\n"
00192          << "==>> EXIT NOW !" << endl;
00193     exit(-1);
00194   }
00195   //-----------------------------------------------------------------------
00196   //activate timer; update WWW page every SECS s
00197   if (timerFlag == 1) {
00198     signal(SIGALRM,timer);
00199     alarm(SECS);
00200   }
00201   //-----------------------------------------------------------------------
00202   // Indefinite loop: Polling for active sockets which have received messages.
00203   // Polling between consumer and client monitors alternates.
00204   int consStat = 1;
00205   while (1) {
00206     consStat = ds.pollConsumer();
00207     if (consStat == 1) currInfo = ds.getCurrentInfo();
00208     if (consStat < 0) {
00209       cerr << "Display Server: ERROR: poll consumer returned with: "
00210            << consStat << endl;
00211     }
00212     if (consStat == 2) {  // Exit
00213       if (debFlags & 0x1) { 
00214         cerr << "Display Server: There is no active socket from the consumer.\n"
00215              << spaces << "==> going to RETURN NOW !" << endl;
00216       }
00217       TIter allSock(gROOT->GetListOfSockets());
00218       TSocket* socktmp = 0;
00219       while (( socktmp = (TSocket*)allSock() )) {
00220         socktmp->Close();
00221         gROOT->GetListOfSockets()->Remove(socktmp);
00222       }
00223       // return(0); // leads to a segfault
00224       exit(0);
00225     } 
00226     //------------------------------------------------------
00227     ds.connectClient(); 
00228     //------------------------------------------------------
00229     ds.pollClients();
00230   }
00231 }

void pipeBroken ( int  sig  ) 

Definition at line 114 of file Server.cc.

Referenced by main().

00115   {    
00116     cerr << "Display Server: Got signal SIGPIPE (" << sig << ")."  << endl;  
00117   } 

TROOT server ( "ServerROOT"  ,
"Root of the Server"   
)
void timer ( int   ) 

Variable Documentation

Referenced by abbruch(), main(), and timer().

Definition at line 41 of file Server.cc.

Referenced by DisplayServer::DisplayServer().

const int debFlags = 0x0

Definition at line 38 of file Server.cc.

Referenced by main().


Generated on 24 Jul 2018 for loon by  doxygen 1.6.1