summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authordeva <deva>2009-07-29 18:17:19 +0000
committerdeva <deva>2009-07-29 18:17:19 +0000
commit270d4794655cc0d8beca5c423488d8211605f6cb (patch)
treed10cb3b5ddc8d45e05b468215c26af5772e2ada8 /server
parentd3b7ad9fed8e98e78a0cb4015c8a6d58a42662bd (diff)
Fixed up the server testprogram a little. Now the program kills its own server process when done.
Diffstat (limited to 'server')
-rw-r--r--server/src/Makefile.am1
-rw-r--r--server/src/server.cc30
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 <sys/types.h>
+#include <signal.h>
+
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;
}