From 270d4794655cc0d8beca5c423488d8211605f6cb Mon Sep 17 00:00:00 2001 From: deva Date: Wed, 29 Jul 2009 18:17:19 +0000 Subject: Fixed up the server testprogram a little. Now the program kills its own server process when done. --- server/src/Makefile.am | 1 - server/src/server.cc | 30 ++++++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/server/src/Makefile.am b/server/src/Makefile.am index baecd73..c7a2cfc 100644 --- a/server/src/Makefile.am +++ b/server/src/Makefile.am @@ -233,7 +233,6 @@ TEST_SERVER_FILES = \ $(BASICFILES) test_server: $(TEST_SERVER_FILES) @../../tools/test $(TEST_SERVER_FILES) $(BASICFLAGS) $(LUA_LIBS) $(DBFLAGS) $(PARSERFLAGS) - @sleep 1s; killall -9 test_server TEST_PRACRODAOPGSQL_FILES = \ pracrodaopgsql.cc \ diff --git a/server/src/server.cc b/server/src/server.cc index 8e5e938..3ddb795 100644 --- a/server/src/server.cc +++ b/server/src/server.cc @@ -430,6 +430,9 @@ void server() #ifdef TEST_SERVER +#include +#include + bool pracro_is_running = true; char request[] = @@ -440,27 +443,46 @@ char request[] = int main() { - switch(fork()) { + Conf::xml_basedir = "../xml/"; + Conf::server_port = 32100; // Make sure wo don't interrupt an already running server. + pid_t pid = fork(); + + switch(pid) { case -1: // error + perror("fork() failed!\n"); return 1; case 0: // child - server(); + try { + server(); + } catch(Exception &e) { + printf(e.what()); + return 1; + } return 0; default: // parent - { + try { + // sleep(1); // Make sure the server is started. TCPSocket socket; socket.connect("localhost", Conf::server_port); socket.write(request); + + // sleep(1); // Make sure the server has handled the request. char buf[32]; memset(buf, 0, sizeof(buf)); - while(socket.read(buf, 31, 1000)) { + // while(socket.read(buf, 31, 1000)) { + while(socket.read(buf, 31, 1000000)) { printf(buf); fflush(stdout); memset(buf, 0, sizeof(buf)); } + } catch(Exception &e) { + printf(e.what()); + kill(pid, SIGKILL); // Kill the server again. + return 1; } + kill(pid, SIGKILL); // Kill the server again. return 0; } -- cgit v1.2.3