GSI Object Oriented Online Offline (Go4)  GO4-6.1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4SocketSignalHandler.cxx
Go to the documentation of this file.
1 // $Id: TGo4SocketSignalHandler.cxx 2627 2019-10-01 08:02:45Z linev $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
15 
16 
17 Int_t TGo4SocketSignalHandler::fgiLastSignal = 0; // unix signal id
18 
20 {
21  SetSignalAction(signum,enabled);
22 }
23 
25 {
26 }
27 
28 
30 {
31  SetSignalAction(signum,0);
32  //std::cout << "got a signal " << signum << " ("<< getpid() << ") Id: ";
33 // optional part:
34 // if(signum == SIGWINCH)
35 // {
36 // //std::cout << "got a SIGWINCH\n";
37 // //TGo4SocketSignalHandler::fgiLastSignal = SIGWINCH;
38 //
39 // }
40 // end optional part
42  SetSignalAction(signum,1);
43 }
44 
45 #ifndef WIN32
46 
47 #include <signal.h>
48 
50 {
51  SetSignalAction(SIGWINCH, enabled);
52 }
53 
54 void TGo4SocketSignalHandler::SetSignalAction(Int_t signum, Bool_t enabled)
55 {
56  struct sigaction new_action, old_action;
57 
58  /* Set up the structure to specify the new action. */
59  if(enabled)
60  new_action.sa_handler = TGo4SocketSignalHandler::Handle;
61  else
62  new_action.sa_handler = SIG_IGN;
63 
64  sigemptyset (&new_action.sa_mask);
65  new_action.sa_flags = 0;
66  sigaction (signum, NULL, &old_action);
67  if(enabled)
68  sigaction (signum, &new_action, NULL);
69 }
70 
72 {
73  signal(SIGPIPE, SIG_IGN);
74 }
75 
77 {
78  return GetLastSignal() == SIGWINCH;
79 }
80 
81 #else
82 
83 // do nothing in windows
84 
85 void TGo4SocketSignalHandler::SetSignalAction(Int_t signum, Bool_t enabled)
86 {
87 }
88 
90 {
91 }
92 
94 {
95 }
96 
98 {
99  return false;
100 }
101 
102 #endif
103 
105 {
106  return fgiLastSignal;
107 }
108 
110 {
111  fgiLastSignal = v;
112 }
113 
114 
static void SetLastSignal(Int_t v=0)
static void SetSigWINCH(Bool_t enabled=kTRUE)
static void SetSignalAction(Int_t signum, Bool_t enabled=kTRUE)