From 7dd51953e820dacf7e2722fbd370aa67a21b2d8f Mon Sep 17 00:00:00 2001 From: kishoramballi Date: Fri, 6 Feb 2009 11:55:49 +0000 Subject: [PATCH] csqlserver starts csql network daemon for network support network can be used through csql client giving -H hostname -P port --- src/network/TCPClient.cxx | 16 ++++++++-------- src/network/TCPServer.cxx | 12 ++++++------ src/tools/csqlserver.cxx | 16 +++++++++++++++- src/tools/csqlsqlserver.cxx | 6 +++--- src/tools/isql.cxx | 37 +++++++++++++++++++++++++++++++++---- test/tools/csql/exp.test001.ksh | 7 +++++-- 6 files changed, 70 insertions(+), 24 deletions(-) diff --git a/src/network/TCPClient.cxx b/src/network/TCPClient.cxx index 3c189a1e..03843333 100644 --- a/src/network/TCPClient.cxx +++ b/src/network/TCPClient.cxx @@ -29,7 +29,7 @@ TCPClient::~TCPClient() DbRetVal TCPClient::send(NetworkPacketType type, char *buf, int len) { DbRetVal rv = OK; - printf("NW:TCP Send\n"); +// printf("NW:TCP Send\n"); void* totalBuffer = malloc(sizeof(PacketHeader)+ len); PacketHeader *hdr= new PacketHeader(); hdr->packetType = type; @@ -42,12 +42,12 @@ DbRetVal TCPClient::send(NetworkPacketType type, char *buf, int len) printError(ErrOS, "Unable to send the packet\n"); return ErrOS; } - printf("Sent bytes %d\n", numbytes); +// printf("Sent bytes %d\n", numbytes); if ((numbytes=os::send(sockfd, buf, len, 0)) == -1) { printError(ErrOS, "Unable to send the packet\n"); return ErrOS; } - printf("Sent bytes %d\n", numbytes); +// printf("Sent bytes %d\n", numbytes); free(totalBuffer); delete hdr; return rv; @@ -55,7 +55,7 @@ DbRetVal TCPClient::send(NetworkPacketType type, char *buf, int len) DbRetVal TCPClient::receive() { DbRetVal rv = OK; - printf("NW:TCP receive\n"); +// printf("NW:TCP receive\n"); fd_set fdset; FD_ZERO(&fdset); FD_SET(sockfd, &fdset); @@ -104,7 +104,7 @@ DbRetVal TCPClient::connect() printError(ErrOS, "Unable to connect to peer site\n"); return ErrOS; } - printf("NW:TCP connecting\n"); +// printf("NW:TCP connecting\n"); fd_set fdset; FD_ZERO(&fdset); FD_SET(sockfd, &fdset); @@ -124,7 +124,7 @@ DbRetVal TCPClient::connect() printf("Unable to receive response from peer\n"); return ErrOS; } - printf("Response from peer site is %d\n", response); +// printf("Response from peer site is %d\n", response); // if (response != 1) return ErrPeerResponse; isConnectedFlag = true; return OK; @@ -133,7 +133,7 @@ DbRetVal TCPClient::connect() DbRetVal TCPClient::disconnect() { if (isConnectedFlag) { - printf("NW:TCP disconnect %s %d\n", hostName, port); +// printf("NW:TCP disconnect %s %d\n", hostName, port); PacketHeader *hdr= new PacketHeader(); hdr->packetType = SQL_NW_PKT_DISCONNECT; hdr->packetLength = 0; @@ -144,7 +144,7 @@ DbRetVal TCPClient::disconnect() printError(ErrOS, "Unable to send the packet\n"); return ErrOS; } else { - printf("Sent bytes %d\n", numbytes); +// printf("Sent bytes %d\n", numbytes); DbRetVal rv = receive(); close(sockfd); delete hdr; diff --git a/src/network/TCPServer.cxx b/src/network/TCPServer.cxx index d089c92f..c30b6a8b 100644 --- a/src/network/TCPServer.cxx +++ b/src/network/TCPServer.cxx @@ -58,7 +58,7 @@ DbRetVal TCPServer::stop() } DbRetVal TCPServer::handleClient() { - printf("PRABA::handling client \n"); +// printf("PRABA::handling client \n"); DbRetVal rv = OK; socklen_t addressLen = sizeof(struct sockaddr); clientfd = accept(sockfd, (struct sockaddr*) &clientAddress, &addressLen); @@ -77,7 +77,7 @@ DbRetVal TCPServer::handleClient() printError(ErrOS, "Unable to communicate to peer\n"); return ErrOS; } - printf("sent connect ack packet to client\n"); +// printf("sent connect ack packet to client\n"); fd_set fdset; struct timeval timeout; SqlNetworkHandler handler; @@ -89,14 +89,14 @@ DbRetVal TCPServer::handleClient() timeout.tv_usec = 0; int ret = os::select(clientfd+1, &fdset, 0, 0, &timeout); if (ret > 0) { - printf("something in fd\n"); +// printf("something in fd\n"); int numbytes = os::recv(clientfd,&header,sizeof(PacketHeader),0); if (numbytes == -1) { printError(ErrOS, "Error reading from socket\n"); return ErrOS; } - printf("HEADER says packet type is %d\n", header.packetType); +// printf("HEADER says packet type is %d\n", header.packetType); char *buffer = NULL; if (header.packetType != SQL_NW_PKT_DISCONNECT && header.packetType != SQL_NW_PKT_COMMIT && @@ -210,12 +210,12 @@ DbRetVal TCPServer::send(NetworkPacketType type, char *buf, int len) printError(ErrOS, "Unable to send the packet\n"); return ErrOS; } - printf("Sent bytes %d\n", numbytes); +// printf("Sent bytes %d\n", numbytes); if ((numbytes=os::send(clientfd, buf, len, 0)) == -1) { printError(ErrOS, "Unable to send the packet\n"); return ErrOS; } - printf("Sent bytes %d\n", numbytes); +// printf("Sent bytes %d\n", numbytes); free(totalBuffer); return rv; } diff --git a/src/tools/csqlserver.cxx b/src/tools/csqlserver.cxx index da5bd259..80165844 100644 --- a/src/tools/csqlserver.cxx +++ b/src/tools/csqlserver.cxx @@ -128,6 +128,18 @@ void startCacheServer() return; } +void startServiceClient() +{ + printf("Starting Csql Network Daemon\n"); + char execName[1024]; + sprintf(execName, "%s/bin/csqlsqlserver", os::getenv("CSQL_INSTALL_ROOT")); + printf("filename is %s\n", execName); + cachepid = os::createProcess(execName, "-s"); + if (cachepid != -1) + printf("Csql Network Daemon Started pid=%d\n", cachepid); + return; +} + void printUsage() { printf("Usage: csqlserver [-c] [-v]\n"); @@ -219,6 +231,7 @@ int main(int argc, char **argv) return 1; } } + if (Conf::config.useReplication()) { printf("Starting Replication Server\n"); @@ -231,9 +244,10 @@ int main(int argc, char **argv) } if (Conf::config.useCache() && Conf::config.useTwoWayCache()) startCacheServer(); - printf("Database server started\n"); + startServiceClient(); + while(!srvStop) { tval.tv_sec = timeout.tv_sec; diff --git a/src/tools/csqlsqlserver.cxx b/src/tools/csqlsqlserver.cxx index 765ca17e..fcda23cc 100644 --- a/src/tools/csqlsqlserver.cxx +++ b/src/tools/csqlsqlserver.cxx @@ -121,7 +121,7 @@ int main(int argc, char **argv) printf("Unable to start the server\n"); return 1; } - printf("Csql network server started\n"); + printf("Csql Network Daemon started\n"); fd_set fdset; int ret = 0; struct timeval timeout, tval; @@ -138,9 +138,9 @@ int main(int argc, char **argv) if (ret > 0) { nwServer->handleClient(); } - printf("Server Waiting for clients\n"); + // printf("Server Waiting for clients\n"); } - printf("Replication Server Exiting\n"); + printf("Csql Network Daemon Exiting\n"); nwServer->stop(); delete SqlNetworkHandler::conn; return 0; diff --git a/src/tools/isql.cxx b/src/tools/isql.cxx index 58eccfa9..ae637dd6 100644 --- a/src/tools/isql.cxx +++ b/src/tools/isql.cxx @@ -18,6 +18,8 @@ #include #include #include +#include +#include #define SQL_STMT_LEN 1024 enum STMT_TYPE { @@ -32,15 +34,19 @@ AbsSqlStatement *stmt; bool gateway=false, silent=false; bool autocommitmode = true; +bool network = false; IsolationLevel isoLevel = READ_COMMITTED; void printHelp(); bool getInput(bool); void printUsage() { - printf("Usage: csql [-u username] [-p passwd] [-s sqlfile] \n"); + printf("Usage: csql [ [-u username] [-p passwd] ] [ [-H hostname] [-P port] ]\n"); + printf(" [-s sqlfile] \n"); printf(" username -> username to connect to database\n"); printf(" password -> password to connect to database\n"); - printf(" sqlfile -> filename containing sql statements\n"); + printf(" hostname -> hostname to connect to database through network\n"); + printf(" port -> port no\n"); + printf(" sqlfile -> filename containing sql statements\n"); return; } @@ -51,10 +57,14 @@ int main(int argc, char **argv) username [0] = '\0'; char password[IDENTIFIER_LENGTH]; password [0] = '\0'; + char hostname[IDENTIFIER_LENGTH]; + hostname[0] = '\0'; + char port[8]; + port[0] ='\0'; char filename[512]; filename [0] ='\0'; int c = 0, opt=0; - while ((c = getopt(argc, argv, "u:p:s:gS?")) != EOF) + while ((c = getopt(argc, argv, "u:p:s:H:P:gS?")) != EOF) { switch (c) { @@ -64,6 +74,10 @@ int main(int argc, char **argv) case '?' : { opt = 1; break; } //print help case 'S' : { silent = true; break; } //silent case 'g' : { gateway = true; break; } //print help + case 'H' : { strcpy (hostname, argv[optind - 1]); + network = true; break; } + case 'P' : { strcpy (port, argv[optind - 1]); + network = true; break; } default: printf("Wrong args\n"); exit(1); } @@ -79,6 +93,10 @@ int main(int argc, char **argv) strcpy(username, "root"); strcpy(password, "manager"); } + if (network) { + if (hostname[0] == '\0') { printUsage(); return 0; } + if (port[0] == '\0') { printUsage(); return 0; } + } bool fileFlag = false; if (filename [0] !='\0') { @@ -94,13 +112,24 @@ int main(int argc, char **argv) DbRetVal rv = OK; if (gateway) conn = SqlFactory::createConnection(CSqlGateway); + else if (network) { + conn = new SqlNwConnection(); + conn->setInnerConnection(NULL); + SqlNwConnection *con = (SqlNwConnection *)conn; + con->setHost(hostname, atoi(port)); + } else conn = SqlFactory::createConnection(CSql); + rv = conn->connect(username,password); if (rv != OK) return 1; if (gateway) stmt = SqlFactory::createStatement(CSqlGateway); - else + else if (network) { + stmt = new SqlNwStatement(); + stmt->setInnerStatement(NULL); + } + else stmt = SqlFactory::createStatement(CSql); stmt->setConnection(conn); //rv = conn->beginTrans(READ_COMMITTED, TSYNC); diff --git a/test/tools/csql/exp.test001.ksh b/test/tools/csql/exp.test001.ksh index 2abbedf1..c9828a4c 100644 --- a/test/tools/csql/exp.test001.ksh +++ b/test/tools/csql/exp.test001.ksh @@ -1,9 +1,12 @@ Case 1: With no option: CSQL>Case 2: With ? option: -Usage: csql [-u username] [-p passwd] [-s sqlfile] +Usage: csql [ [-u username] [-p passwd] ] [ [-H hostname] [-P port] ] + [-s sqlfile] username -> username to connect to database password -> password to connect to database - sqlfile -> filename containing sql statements + hostname -> hostname to connect to database through network + port -> port no + sqlfile -> filename containing sql statements Case 3: With wrong username and wrong password : failed Case 4: With wrong username : -- 2.11.4.GIT