00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifdef _WIN32
00024 #pragma warning(disable:4786)
00025 #endif
00026 #include <stdio.h>
00027 #include <string>
00028 #include <vector>
00029 #include <map>
00030 #include <signal.h>
00031 #include <socket_include.h>
00032
00033 #include <ListenSocket.h>
00034 #include <SocketHandler.h>
00035 #include "config.h"
00036 #include "MyTcpSocket.h"
00037 #include "RedirWwwSocket.h"
00038 #include "MyHandler.h"
00039
00040
00041 #ifdef _DEBUG
00042 #define DEB(x) x
00043 #else
00044 #define DEB(x)
00045 #endif
00046
00047
00048
00049
00050
00051 #ifdef WIN32
00052 WSADATA libmibWSAdata;
00053 class X
00054 {
00055 public:
00056 X() { SocketStartup(); }
00057 ~X() { SocketCleanup(); }
00058 };
00059 X x;
00060 #endif
00061
00062 static int quit = 0;
00063
00064
00065 #ifndef _WIN32
00066 void sigint(int s)
00067 {
00068 DEB( printf("sigint\n");)
00069 quit++;
00070 }
00071
00072 void sighup(int s)
00073 {
00074 DEB( printf("sighup\n");)
00075 quit++;
00076 }
00077
00078 void sigusr1(int s)
00079 {
00080 }
00081
00082 void sigusr2(int s)
00083 {
00084 }
00085
00086 void sigpipe(int s)
00087 {
00088 }
00089
00090 void siginit(void)
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 }
00098 #endif
00099
00100
00101 int main(int argc,char *argv[])
00102 {
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
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
00124 config["minder_port"] = "9696";
00125 config["next_host_id"] = "1";
00126
00127
00128 parse_config(argc,argv,"minder.cfg");
00129
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 }
00163
00164