KjSignal.cpp

Go to the documentation of this file.
00001 
00013 /***************************************************************************
00014  *   Copyright (C) 2007 by Jan Koci   *
00015  *   honza.koci@email.cz   *
00016  *   http://kengine.sourceforge.net/tutorial/
00017  *                                                                         *
00018  *   This program is free software; you can redistribute it and/or modify  *
00019  *   it under the terms of the GNU General Public License as published by  *
00020  *   the Free Software Foundation; either version 2 of the License, or     *
00021  *   (at your option) any later version.                                   *
00022  *                                                                         *
00023  *   This program is distributed in the hope that it will be useful,       *
00024  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00025  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00026  *   GNU General Public License for more details.                          *
00027  *                                                                         *
00028  *   You should have received a copy of the GNU General Public License     *
00029  *   along with this program; if not, write to the                         *
00030  *   Free Software Foundation, Inc.,                                       *
00031  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00032  ***************************************************************************/
00033 
00034 
00035 #include "KjSignal.h"
00036 
00037 bool KjSignal::m_bIsSigInt;
00038 bool KjSignal::m_bIsSigQuit;
00039 
00040 KjSignal::KjSignal()
00041 {
00042         sigemptyset (&m_tSa.sa_mask);
00043         m_tSa.sa_flags = 0;
00044         m_bIsSigInt = false;
00045         m_bIsSigQuit = false;
00046 }
00047 
00048 KjSignal::~KjSignal()
00049 {
00050 }
00051 
00054 void KjSignal::CheckSignal(const int _iSignalId)
00055 {
00056     switch (_iSignalId) 
00057         {
00058         case SIGABRT:
00059                 cerr << "Signal Abort - Abnormal termination is initiated by the abort() function !" << endl;
00060                 exit(1);
00061                 break;
00062     case SIGFPE:
00063        cerr << "Signal Floating- Point Exception - zero divide or an operation resulting in overflow !" << endl;
00064                 exit(1);
00065         break;
00066         case SIGKILL:
00067         cerr << "Signal Illegal Instruction - corruption in the code or to an attempt to execute data !" << endl;
00068                 exit(1);
00069         break;
00070         case SIGSEGV:
00071         cerr << "Signal Segmentation Violation - Invalid access to storage: Program tries to read or write outside the memory it is allocated for it. !" << endl;
00072                 exit(1);
00073         break;
00074         case SIGTERM:
00075         cerr << "Signal Terminate - Termination request sent to program !" << endl;
00076                 exit(1);
00077         break;
00078     default:
00079         cerr << "Unpredictable signal !" << endl;
00080                 exit(1);
00081         break;
00082     }
00083 }
00084 
00087 void KjSignal::InitSignal(const int _iSignalId)
00088 {
00089         m_pFunction = signal(_iSignalId, CheckSignal);
00090 }
00091 
00094 void KjSignal::SigIntHandler (const int _iSignalId)
00095 {
00096         if (_iSignalId == SIGINT)
00097         {
00098                 cout << "Signal Interrupt - CTRL-c !" << endl;
00099                 m_bIsSigInt = true;
00100         }
00101 }
00102 
00105 void KjSignal::SigQuitHandler (const int _iSignalId)
00106 {
00107         if (_iSignalId == SIGQUIT)
00108         {
00109                 cout << "Signal Interrupt - CTRL-\\" << endl;
00110                 m_bIsSigQuit = true;
00111         }
00112 }
00113 
00116 void KjSignal::SigChldHandler(const int _iSignalId)
00117 {
00118         int iStatus;
00119         waitpid(-1 , &iStatus, 0);
00120 }
00121 
00123 void KjSignal::InitSignals()
00124 {
00125         // Check next signals
00126         InitSignal(SIGABRT);
00127         InitSignal(SIGFPE);
00128         InitSignal(SIGKILL);
00129         InitSignal(SIGSEGV);
00130         InitSignal(SIGTERM);
00131 
00132         // Register the handler for SIGINT.
00133         m_tSa.sa_handler = SigIntHandler;
00134         sigaction (SIGINT, &m_tSa, 0);
00135         // Register the handler for SIGQUIT.
00136         m_tSa.sa_handler =  SigQuitHandler;
00137         sigaction (SIGQUIT, &m_tSa, 0);
00138         // Register the handler for SIGCHLD
00139         //m_tSa.sa_handler =  SigChldHandler;
00140         //sigaction (SIGCHLD, &m_tSa, 0);
00141 }
00142 
00143 
00144 
00145 
00146 

Generated on Tue Jul 24 10:03:19 2007 for KjSslSocket by  doxygen 1.4.6