1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: praba_tuty@databasecache.com *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 ***************************************************************************/
16 #include <AbsSqlConnection.h>
17 #include <AbsSqlStatement.h>
18 #include <SqlConnection.h>
19 #include <SqlStatement.h>
20 #include <SqlFactory.h>
22 #include <SessionImpl.h>
24 #include <SqlLogStatement.h> //for BindSqlField
25 #include <SqlNetworkHandler.h>
29 static void sigTermHandler(int sig
)
31 printf("Received signal %d\nStopping the server\n", sig
);
37 printf("Usage: csqlsqlserver \n");
38 printf("Description: Start the csql network server.\n");
41 int main(int argc
, char **argv
)
44 while ((c
= getopt(argc
, argv
, "g?")) != EOF
)
48 case '?' : { opt
= 10; break; } //print help
49 case 'g' : { gateway
= true; break; }
60 DbRetVal rv
= session
.readConfigFile();
63 printf("Unable to read the configuration file \n");
66 os::signal(SIGINT
, sigTermHandler
);
67 os::signal(SIGTERM
, sigTermHandler
);
71 SqlNetworkHandler::type
= CSqlGateway
;
72 SqlNetworkHandler::conn
= SqlFactory::createConnection(CSqlGateway
);
74 SqlNetworkHandler::type
= CSql
;
75 SqlNetworkHandler::conn
= SqlFactory::createConnection(CSql
);
77 SqlNetworkHandler::stmtID
= 0;
78 if (!Conf::config
.useCsqlSqlServer())
80 printf("Sql Network Server is set to OFF in csql.conf file\n");
86 char hostname[IDENTIFIER_LENGTH];
88 fp = fopen(Conf::config.getReplConfigFile(),"r");
90 printError(ErrSysInit, "Invalid path/filename for REPL_CONFIG_FILE.\n");
91 SqlNetworkHandler::conn->disconnect();
96 fscanf(fp, "%d:%d:%s\n", &nwid, &port, hostname);
97 printf( "%d:%d:%s\n", nwid, port, hostname);
98 if (nwid == Conf::config.getNetworkID()) { found = true; break;}
103 printf("Info not found in REPL_CONFIG_FILE for nwid %d\n",
104 Conf::config.getNetworkID());
105 SqlNetworkHandler::conn->disconnect();
110 if ((port
= Conf::config
.getPort()) <= 1024)
112 printf("Invalid port Number\n");
115 NetworkServer
*nwServer
;
116 nwServer
= new TCPServer();
118 nwServer
->setServerPort(port
);
119 rv
= nwServer
->start();
121 printf("Unable to start the server\n");
124 printf("Csql Network Daemon started\n");
127 struct timeval timeout
, tval
;
134 FD_SET(nwServer
->getSocket(), &fdset
);
135 tval
.tv_sec
= timeout
.tv_sec
;
136 tval
.tv_usec
= timeout
.tv_usec
;
137 ret
= os::select(nwServer
->getSocket()+1, &fdset
, 0, 0, &tval
);
139 nwServer
->handleClient();
141 // printf("Server Waiting for clients\n");
143 printf("Csql Network Daemon Exiting\n");
145 delete SqlNetworkHandler::conn
;