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>
23 #include <SqlLogStatement.h> //for BindSqlField
24 #include <SqlNetworkHandler.h>
27 static void sigTermHandler(int sig
)
29 printf("Received signal %d\nStopping the server\n", sig
);
35 printf("Usage: csqlreplserver \n");
36 printf("Description: Start the csql replication server.\n");
39 int main(int argc
, char **argv
)
42 while ((c
= getopt(argc
, argv
, "?")) != EOF
)
46 case '?' : { opt
= 10; break; } //print help
57 os::signal(SIGINT
, sigTermHandler
);
58 os::signal(SIGTERM
, sigTermHandler
);
61 SqlNetworkHandler::type
= CSql
;
62 SqlNetworkHandler::conn
= SqlFactory::createConnection(CSql
);
63 DbRetVal rv
= SqlNetworkHandler::conn
->connect("root", "manager");
64 if (rv
!= OK
) return 1;
65 //if (!Conf::config.useReplication())
67 printf("Replication is set to OFF in csql.conf file\n");
68 SqlNetworkHandler::conn
->disconnect();
75 char hostname
[IDENTIFIER_LENGTH
];
77 //fp = fopen(Conf::config.getReplConfigFile(),"r");
79 printError(ErrSysInit
, "Invalid path/filename for REPL_CONFIG_FILE.\n");
80 SqlNetworkHandler::conn
->disconnect();
84 NetworkServer
*nwServer
;
86 nwServer
= new UDPServer();
88 nwServer
->setServerPort(port
);
89 rv
= nwServer
->start();
91 printf("Unable to start the server\n");
94 printf("Replication server started\n");
97 struct timeval timeout
, tval
;
104 FD_SET(nwServer
->getSocket(), &fdset
);
105 tval
.tv_sec
= timeout
.tv_sec
;
106 tval
.tv_usec
= timeout
.tv_usec
;
107 ret
= os::select(nwServer
->getSocket()+1, &fdset
, 0, 0, &tval
);
109 nwServer
->handleClient();
111 printf("Server Waiting for clients\n");
113 printf("Replication Server Exiting\n");
115 SqlNetworkHandler::conn
->disconnect();
116 delete SqlNetworkHandler::conn
;