Google
Web alhem.net
Main Page | Alphabetical List | Class List | File List | Class Members | File Members

minder.cpp File Reference

#include <stdio.h>
#include <string>
#include <vector>
#include <map>
#include <signal.h>
#include <socket_include.h>
#include <ListenSocket.h>
#include <SocketHandler.h>
#include "config.h"
#include "MyTcpSocket.h"
#include "RedirWwwSocket.h"
#include "MyHandler.h"

Include dependency graph for minder.cpp:

Include dependency graph

Go to the source code of this file.

Defines

#define DEB(x)

Functions

void sigint (int s)
void sighup (int s)
void sigusr1 (int s)
void sigusr2 (int s)
void sigpipe (int s)
void siginit (void)
int main (int argc, char *argv[])

Variables

int quit = 0


Define Documentation

#define DEB  ) 
 

File ......... minder.cpp Published .... 2004-04-18 Author ....... grymse@alhem.net

Definition at line 44 of file minder.cpp.

Referenced by main(), TestSocket::OnConnect(), RedirWwwSocket::OnLine(), MyTcpSocket::OnLine(), sighup(), sigint(), and MyHandler::ViewHosts().


Function Documentation

int main int  argc,
char *  argv[]
 

Definition at line 101 of file minder.cpp.

References MyHandler::CheckTimeout(), config, DEB, parse_config(), quit, and siginit().

00102 {
00103         // open listen socket
00104         // commands:
00105         //  init (state = startup)
00106         //  online (state = online)
00107         //  keepalive
00108         //  exit
00109         //  route (traceroute from host to minder)
00110         // sent as:
00111         //  http://minder.alhem.net:9696/init?ip&port
00112         //  http://minder.alhem.net:9696/route?10.0.0.1&10.0.0.2&...
00113         time_t t = time(NULL);
00114         MyHandler h;
00115         ListenSocket<MyTcpSocket> l(h);
00116         ListenSocket<RedirWwwSocket> l2(h);
00117         port_t redir_port = 0;
00118 
00119 #ifndef _WIN32
00120         siginit();
00121 #endif
00122 
00123         // default values
00124         config["minder_port"] = "9696";
00125         config["next_host_id"] = "1";
00126         // config["redir_port"] = "9666";
00127 
00128         parse_config(argc,argv,"minder.cfg");
00129 //      config["progname"] = argv[0];
00130 
00131         if (l.Bind(atoi(config["minder_port"].c_str()), 20) != 0)
00132         {
00133 DEB(            printf("Bind() failed\n");)
00134                 exit(-1);
00135         }
00136         redir_port = atoi(config["redir_port"].c_str());
00137         if (redir_port > 0)
00138         {
00139                 if (l2.Bind(redir_port, 20))
00140                 {
00141 DEB(                    perror("Bind() failed");)
00142                         exit(-2);
00143                 }
00144         }
00145 
00146         h.Add(&l);
00147         if (redir_port > 0)
00148         {
00149                 h.Add(&l2);
00150         }
00151 
00152         while (!quit)
00153         {
00154                 h.Select(1,0);
00155                 if (time(NULL) - t > 60)
00156                 {
00157                         h.CheckTimeout();
00158                 }
00159         }
00160 
00161         return 0;
00162 }

void sighup int  s  ) 
 

Definition at line 72 of file minder.cpp.

References DEB, and quit.

Referenced by siginit().

00073 {
00074 DEB(    printf("sighup\n");)
00075         quit++;
00076 }

void siginit void   ) 
 

Definition at line 90 of file minder.cpp.

References sighup(), sigint(), sigpipe(), sigusr1(), and sigusr2().

Referenced by main().

00091 {
00092         signal(SIGINT, (__sighandler_t)sigint);
00093         signal(SIGHUP, (__sighandler_t)sighup);
00094         signal(SIGUSR1, (__sighandler_t)sigusr1);
00095         signal(SIGUSR2, (__sighandler_t)sigusr2);
00096         signal(SIGPIPE, (__sighandler_t)sigpipe);
00097 }

void sigint int  s  ) 
 

Definition at line 66 of file minder.cpp.

References DEB, and quit.

Referenced by siginit().

00067 {
00068 DEB(    printf("sigint\n");)
00069         quit++;
00070 }

void sigpipe int  s  ) 
 

Definition at line 86 of file minder.cpp.

Referenced by siginit().

00087 {
00088 }

void sigusr1 int  s  ) 
 

Definition at line 78 of file minder.cpp.

Referenced by siginit().

00079 {
00080 }

void sigusr2 int  s  ) 
 

Definition at line 82 of file minder.cpp.

Referenced by siginit().

00083 {
00084 }


Variable Documentation

int quit = 0 [static]
 

Definition at line 62 of file minder.cpp.

Referenced by main(), sighup(), and sigint().


Generated on Tue Oct 3 23:47:05 2006 for The Minder by doxygen 1.3.6