[Tux4kids-commits] r1606 - tuxmath/trunk/src
David Bruce
dbruce-guest at alioth.debian.org
Mon Oct 26 16:55:35 UTC 2009
Author: dbruce-guest
Date: 2009-10-26 16:55:35 +0000 (Mon, 26 Oct 2009)
New Revision: 1606
Modified:
tuxmath/trunk/src/menu.c
tuxmath/trunk/src/server.c
tuxmath/trunk/src/server.h
Log:
prevent server launch if it is already running to avoid crash (not complete fix)
Modified: tuxmath/trunk/src/menu.c
===================================================================
--- tuxmath/trunk/src/menu.c 2009-10-24 14:40:08 UTC (rev 1605)
+++ tuxmath/trunk/src/menu.c 2009-10-26 16:55:35 UTC (rev 1606)
@@ -582,6 +582,13 @@
char* argv[3];
int chosen_lesson = -1;
+ /* For now, only allow one server instance: */
+ if(ServerRunning())
+ {
+ ShowMessage(_("The server is already running"), NULL, NULL, NULL);
+ return 0;
+ }
+
NameEntry(server_name, _("Enter Server Name:"), _("(limit 50 characters)"));
argv[0] = "tuxmathserver";
argv[1] = "--name";
Modified: tuxmath/trunk/src/server.c
===================================================================
--- tuxmath/trunk/src/server.c 2009-10-24 14:40:08 UTC (rev 1605)
+++ tuxmath/trunk/src/server.c 2009-10-26 16:55:35 UTC (rev 1606)
@@ -90,7 +90,7 @@
/* ------------ "Local globals" for server.c: ---------- */
-char server_name[NAME_SIZE]; /* User-visible name for server selection */
+char server_name[NAME_SIZE]; /* User-visible name for server selection */
int need_server_name = 1;
UDPsocket udpsock = NULL; /* Used to listen for client's server autodetection */
TCPsocket server_sock = NULL; /* Socket descriptor for server to accept client TCP sockets. */
@@ -99,6 +99,7 @@
static client_type client[MAX_CLIENTS];
static int num_clients = 0;
static int game_in_progress = 0;
+static int server_running = 0;
static int quit = 0;
MC_FlashCard flash;
int local_argc;
@@ -118,7 +119,8 @@
/* FIXME this isn't thread-safe - we need to return gracefully if we */
/* find that the server is already running, instead of calling cleanup() */
-/* and crashing the program. */
+/* and crashing the program. Some of the setup and cleanup will have to */
+/* be called from main() rather than from here. */
int RunServer(int argc, char* argv[])
{
Uint32 timer = 0;
@@ -135,7 +137,8 @@
return EXIT_FAILURE;
}
-
+ server_running = 1;
+
printf("Waiting for clients to connect:\n>");
fflush(stdout);
@@ -155,6 +158,8 @@
/* CPU from 100% to ~2% on my desktop - DSB */
Throttle(5, &timer); //min loop time 5 msec
}
+
+ server_running = 0;
/* ----- Free resources before exiting: ------- */
cleanup_server();
@@ -210,6 +215,7 @@
void* run_server_local_args(void)
{
+
RunServer(local_argc, local_argv);
pthread_exit(NULL);
return NULL;
@@ -1227,6 +1233,9 @@
+int ServerRunning(void)
+{
+ return server_running;
+}
-
Modified: tuxmath/trunk/src/server.h
===================================================================
--- tuxmath/trunk/src/server.h 2009-10-24 14:40:08 UTC (rev 1605)
+++ tuxmath/trunk/src/server.h 2009-10-26 16:55:35 UTC (rev 1606)
@@ -66,4 +66,7 @@
/* 2, 3, and 4 all return immediately, with the server running in a separate thread or process. But if you don't mind waiting... */
/* 5. Plain "blocking" function call, leaving scheduling issues up to you: */
int RunServer(int argc, char **argv);
+
+/* Find out if server is already running: */
+int ServerRunning(void);
#endif
More information about the Tux4kids-commits
mailing list