#include <AbsSqlConnection.h>
#include <AbsSqlStatement.h>
#include <SqlConnection.h>
#include <SqlStatement.h>
#include <SqlFactory.h>
#include <CSql.h>
#include <Network.h>
#include <SqlLogStatement.h>
#include <SqlNetworkHandler.h>
Include dependency graph for csqlreplserver.cxx:
Go to the source code of this file.
Functions | |
static void | sigTermHandler (int sig) |
void | printUsage () |
int | main (int argc, char **argv) |
Variables | |
int | srvStop = 0 |
int main | ( | int | argc, | |
char ** | argv | |||
) |
Definition at line 39 of file csqlreplserver.cxx.
References Conf::config, SqlNetworkHandler::conn, AbsSqlConnection::connect(), SqlFactory::createConnection(), CSql, AbsSqlConnection::disconnect(), ErrSysInit, fp, NetworkServer::getSocket(), NetworkServer::handleClient(), IDENTIFIER_LENGTH, OK, printError, printUsage(), os::select(), NetworkServer::setServerPort(), os::signal(), sigTermHandler(), srvStop, NetworkServer::start(), NetworkServer::stop(), and SqlNetworkHandler::type.
00040 { 00041 int c = 0, opt = 0; 00042 while ((c = getopt(argc, argv, "?")) != EOF) 00043 { 00044 switch (c) 00045 { 00046 case '?' : { opt = 10; break; } //print help 00047 default: opt=10; 00048 00049 } 00050 }//while options 00051 00052 if (opt == 10) { 00053 printUsage(); 00054 return 0; 00055 } 00056 00057 os::signal(SIGINT, sigTermHandler); 00058 os::signal(SIGTERM, sigTermHandler); 00059 00060 bool end = false; 00061 SqlNetworkHandler::type = CSql; 00062 SqlNetworkHandler::conn = SqlFactory::createConnection(CSql); 00063 DbRetVal rv = SqlNetworkHandler::conn->connect("root", "manager"); 00064 if (rv != OK) return 1; 00065 if (!Conf::config.useReplication()) 00066 { 00067 printf("Replication is set to OFF in csql.conf file\n"); 00068 SqlNetworkHandler::conn->disconnect(); 00069 return 1; 00070 } 00071 00072 00073 FILE *fp = NULL; 00074 int nwid =0; 00075 char hostname[IDENTIFIER_LENGTH]; 00076 int port=0; 00077 fp = fopen(Conf::config.getReplConfigFile(),"r"); 00078 if( fp == NULL ) { 00079 printError(ErrSysInit, "Invalid path/filename for REPL_CONFIG_FILE.\n"); 00080 SqlNetworkHandler::conn->disconnect(); 00081 return 1; 00082 } 00083 bool found =false; 00084 while(!feof(fp)) { 00085 fscanf(fp, "%d:%d:%s\n", &nwid, &port, hostname); 00086 printf( "%d:%d:%s\n", nwid, port, hostname); 00087 if (nwid == Conf::config.getNetworkID()) { found = true; break;} 00088 } 00089 fclose(fp); 00090 if (!found) 00091 { 00092 printf("Info not found in REPL_CONFIG_FILE for nwid %d\n", 00093 Conf::config.getNetworkID()); 00094 SqlNetworkHandler::conn->disconnect(); 00095 return 1; 00096 } 00097 NetworkServer *nwServer; 00098 00099 nwServer = new UDPServer(); 00100 00101 nwServer->setServerPort(port); 00102 rv = nwServer->start(); 00103 if (rv != OK) { 00104 printf("Unable to start the server\n"); 00105 return 1; 00106 } 00107 printf("Replication server started\n"); 00108 fd_set fdset; 00109 int ret = 0; 00110 struct timeval timeout, tval; 00111 timeout.tv_sec = 5; 00112 timeout.tv_usec = 0; 00113 00114 while(!srvStop) 00115 { 00116 FD_ZERO(&fdset); 00117 FD_SET(nwServer->getSocket(), &fdset); 00118 tval.tv_sec = timeout.tv_sec; 00119 tval.tv_usec = timeout.tv_usec; 00120 ret = os::select(nwServer->getSocket()+1, &fdset, 0, 0, &tval); 00121 if (ret > 0) { 00122 nwServer->handleClient(); 00123 } 00124 printf("Server Waiting for clients\n"); 00125 } 00126 printf("Replication Server Exiting\n"); 00127 nwServer->stop(); 00128 SqlNetworkHandler::conn->disconnect(); 00129 delete SqlNetworkHandler::conn; 00130 return 0; 00131 }
Here is the call graph for this function:
void printUsage | ( | ) |
Definition at line 33 of file csqlreplserver.cxx.
00034 { 00035 printf("Usage: csqlreplserver \n"); 00036 printf("Description: Start the csql replication server.\n"); 00037 return; 00038 }
static void sigTermHandler | ( | int | sig | ) | [static] |
Definition at line 27 of file csqlreplserver.cxx.
References srvStop.
00028 { 00029 printf("Received signal %d\nStopping the server\n", sig); 00030 srvStop = 1; 00031 }
int srvStop = 0 |
Definition at line 26 of file csqlreplserver.cxx.