Logo
~Sockets~
~Examples~
~Contact~


small6.cpp

Go to the documentation of this file.
00001 //small.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 #include <signal.h>
00022 #include <ListenSocket.h>
00023 #include <StdoutLog.h>
00024 #include "SmallHandler.h"
00025 #include "SmallSocket.h"
00026 
00027 #define DEB(x) 
00028 
00029 
00030 static  int m_quit = 0;
00031 
00032 
00033 #ifndef _WIN32
00034 void sigint(int s) /* save+quit */
00035 {
00036 DEB(    printf("sigint\n");)
00037         m_quit++;
00038 }
00039 
00040 void sighup(int s) /* quit */
00041 {
00042 DEB(    printf("sighup\n");)
00043         m_quit++;
00044 }
00045 
00046 void sigusr1(int s) /* save */
00047 {
00048 }
00049 
00050 void sigusr2(int s) /* reset all */
00051 {
00052 }
00053 
00054 void sigpipe(int s)
00055 {
00056 }
00057 
00058 void siginit(void)
00059 {
00060         signal(SIGINT, (__sighandler_t)sigint);
00061         signal(SIGHUP, (__sighandler_t)sighup);
00062         signal(SIGUSR1, (__sighandler_t)sigusr1);
00063         signal(SIGUSR2, (__sighandler_t)sigusr2);
00064         signal(SIGPIPE, (__sighandler_t)sigpipe);
00065 }
00066 #endif
00067 
00068 
00069 int main(int argc,char *argv[])
00070 {
00071         time_t t = time(NULL);
00072         time_t osec = t;
00073         SmallHandler h;
00074         ListenSocket<SmallSocket> l(h);
00075         StdoutLog log;
00076 
00077         h.RegStdLog(&log);
00078         srandom(time(NULL));
00079         siginit();
00080 
00081         l.SetIpv6(true);
00082         if (l.Bind(4441))
00083         {
00084                 exit(-1);
00085         }
00086         h.Add(&l);
00087         h.Load();
00088         while (!m_quit)
00089         {
00090                 h.Select(1,0);
00091                 t = time(NULL);
00092                 if (t != osec)
00093                 {
00094                         h.SecTick(t);
00095                         osec = t;
00096                 }
00097         }
00098 }
00099 
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