Logo
~Sockets~
~Examples~
~Contact~


stprog.cpp

Go to the documentation of this file.
00001 // stprog.cpp
00002 /*
00003 Copyright (C) 2004  Anders Hedstrom
00004 
00005 This program is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU General Public License
00007 as published by the Free Software Foundation; either version 2
00008 of the License, or (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with this program; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 */
00019 
00020 #include <stdio.h>
00021 
00022 #include <ListenSocket.h>
00023 #include "InSocket.h"
00024 #include "ProxyHandler.h"
00025 #include <signal.h>
00026 //#include <Utility.h>
00027 #include <StdoutLog.h>
00028 
00029 #define DEB(x)
00030 
00031 
00032 static  int m_quit = 0;
00033 
00034 
00035 #ifndef _WIN32
00036 void sigint(int s) /* save+quit */
00037 {
00038 DEB(    printf("sigint\n");)
00039         m_quit++;
00040 }
00041 
00042 void sighup(int s) /* quit */
00043 {
00044 DEB(    printf("sighup\n");)
00045         m_quit++;
00046 }
00047 
00048 void sigusr1(int s) /* save */
00049 {
00050 }
00051 
00052 void sigusr2(int s) /* reset all */
00053 {
00054 }
00055 
00056 void sigpipe(int s)
00057 {
00058 }
00059 
00060 void siginit(void)
00061 {
00062         signal(SIGINT, (__sighandler_t)sigint);
00063         signal(SIGHUP, (__sighandler_t)sighup);
00064         signal(SIGUSR1, (__sighandler_t)sigusr1);
00065         signal(SIGUSR2, (__sighandler_t)sigusr2);
00066         signal(SIGPIPE, (__sighandler_t)sigpipe);
00067 }
00068 #endif
00069 
00070 
00071 void run()
00072 {
00073         size_t sz = 0;
00074         ProxyHandler h;
00075         StdoutLog log;
00076         h.RegStdLog(&log);
00077         ListenSocket<InSocket> l(h);
00078 
00079         if (l.Bind( 8080 ))
00080         {
00081                 exit(-1);
00082         }
00083         h.Add(&l);
00084         while (!m_quit)
00085         {
00086                 h.Select(1, 0);
00087                 if (h.GetCount() != sz)
00088                 {
00089                         sz = h.GetCount();
00090                         h.ViewSockets();
00091                 }
00092         }
00093         printf("Ctrl-C...\n");
00094 }
00095 
00096 
00097 int main(int argc,char *argv[])
00098 {
00099         siginit();
00100         run();
00101 }
00102 
00103 
Page, code, and content Copyright (C) 2006 by Anders Hedström
Generated on Mon Aug 29 20:21:47 2005 for C++ Sockets by  doxygen 1.4.4