[Tux4kids-commits] r1535 - tuxmath/trunk/src

David Bruce dbruce-guest at alioth.debian.org
Sun Sep 13 00:03:01 UTC 2009


Author: dbruce-guest
Date: 2009-09-13 00:02:59 +0000 (Sun, 13 Sep 2009)
New Revision: 1535

Added:
   tuxmath/trunk/src/servermain.c
Modified:
   tuxmath/trunk/src/server.c
Log:
Added separate file with main() for server program so server can be run either as standalone program or as function called from within tuxmath



Modified: tuxmath/trunk/src/server.c
===================================================================
--- tuxmath/trunk/src/server.c	2009-09-12 23:28:30 UTC (rev 1534)
+++ tuxmath/trunk/src/server.c	2009-09-13 00:02:59 UTC (rev 1535)
@@ -16,7 +16,7 @@
 * derivative works into a GPLv2+ project like TuxMath - David Bruce 
 */
 
-#include "config.h"
+#include "globals.h"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -28,6 +28,7 @@
 #include "server.h" 
 #include "transtruct.h"
 #include "mathcards.h"
+#include "throttle.h"
 
 
 #define MAX_CLIENTS 16
@@ -39,12 +40,12 @@
 // setup and cleanup:
 int setup_server(void);
 void cleanup_server(void);
-static void handle_command_args(int argc, char* argv[]);
+void server_handle_command_args(int argc, char* argv[]);
 
 // top level functions in main loop:
 void check_UDP(void);
 void update_clients(void);
-static int check_messages(void);
+int server_check_messages(void);
 
 // client management utilities:
 int find_vacant_client(void);
@@ -104,14 +105,15 @@
 
 
 
-/* The contents of main() are wrapped into this function to allow the   */
-/* server to be run as a function in a process or thread within another */
-/* program - DSB                                                        */
+/* The previous contents of main() are wrapped into this function to   */
+/* allow the server to be run as a function in a process or thread     */
+/* within another program.  main() is now in a separate file,          */
+/* servermain.c, that consists solely of a call to RunServer().        */
 int RunServer(int argc, char **argv)
 { 
   printf("Started tuxmathserver, waiting for client to connect:\n>\n");
 
-  handle_command_args(argc, argv);
+  server_handle_command_args(argc, argv);
 
   /*     ---------------- Setup: ---------------------------   */
   if (!setup_server())
@@ -133,7 +135,7 @@
     /* Now we check to see if anyone is trying to connect. */
     update_clients();
     /* Check for any pending messages from clients already connected: */
-    check_messages();
+    server_check_messages();
 
     /* Limit frame rate to keep from eating all CPU: */
     /* NOTE almost certainly could make this longer wtihout noticably */
@@ -295,7 +297,7 @@
 
 
 /* Handle any arguments passed from command line */
-void handle_command_args(int argc, char* argv[])
+void server_handle_command_args(int argc, char* argv[])
 {
   int i;
 
@@ -459,7 +461,7 @@
   /* At this point num_clients can be updated: */
   num_clients = sockets_used;
 
-  /* Now we can communicate with the client using client[i].sock socket
+  /* Now we can communicate with the client using client[i].sock socket */
   /* serv_sock will remain opened waiting other connections */
     
 
@@ -493,7 +495,7 @@
 // or not a math game is in progress (although we expect different messages
 // during a game from those encountered outside of a game)
 
-int check_messages(void)
+int server_check_messages(void)
 {
   int actives = 0, i = 0;
   int ready_found = 0;

Added: tuxmath/trunk/src/servermain.c
===================================================================
--- tuxmath/trunk/src/servermain.c	                        (rev 0)
+++ tuxmath/trunk/src/servermain.c	2009-09-13 00:02:59 UTC (rev 1535)
@@ -0,0 +1,23 @@
+/*
+*  C Implementation: servermain.c
+*
+*       Description: main() function to allow standalone use of server program for 
+*       LAN-based play in Tux,of Math Command.
+*
+*
+* Author: David Bruce and the TuxMath team, (C) 2009
+* Developers list: <tuxmath-devel at lists.sourceforge.net>
+*
+* Copyright: See COPYING file that comes with this distribution.  (Briefly, GNU GPL).
+*
+*/
+
+#include "server.h"
+
+/* This function has to be in its own file that is not linked into tuxmath */
+/* itself because there can only be one main() in a program.  All of the   */
+/* server functionality is contained in server.h and server.c              */
+int main(int argc, char** argv)
+{
+  return RunServer(argc, argv);
+}




More information about the Tux4kids-commits mailing list