diff options
-rw-r--r-- | param.ccl | 41 | ||||
-rw-r--r-- | src/Content.c | 2 | ||||
-rw-r--r-- | src/Server.c | 107 | ||||
-rw-r--r-- | src/Sockets.c | 16 | ||||
-rw-r--r-- | src/Startup.c | 55 | ||||
-rw-r--r-- | src/httpd.h | 13 |
6 files changed, 212 insertions, 22 deletions
@@ -3,30 +3,53 @@ private: +# Probably the most useful parameter + INT port "HTTP port number" { 1:65535 :: "Any valid port" } 5555 -INT queue_length "Listen queue length" +# This allows you to control the number of times all procs need to synchronise parameters +INT steering_frequency "How many iterations between steering events" STEERABLE = ALWAYS { - 1: :: "Any positive number" -} 4 + 0: :: "Any number, 0 means don't steer" +} 1 + +BOOLEAN provide_pages "Should the server provide any pages ?" +{ +} "yes" + +BOOLEAN standalone "Should the server poll continuously in startup" STEERABLE = ALWAYS +{ +} "no" + + +# Tuning parameters -INT timeout_seconds "Polling timeout seconds" +INT timeout_seconds "Polling timeout seconds" STEERABLE = ALWAYS { 0: :: "Any whole number" } 0 -INT timeout_useconds "Polling timeout micro-seconds" +INT timeout_useconds "Polling timeout micro-seconds" STEERABLE = ALWAYS { 0: :: "Any whole number" } 0 -BOOLEAN standalone "Should the server poll continuously in startup" +INT queue_length "Listen queue length" +{ + 1: :: "Any positive number" +} 4 + + +# You probably don't want to set these in a parameter file + +BOOLEAN pause "Pause ?" STEERABLE = ALWAYS { } "no" - -BOOLEAN provide_pages "Should the server provide any pages ?" + +BOOLEAN terminate "Kill the simulation ?" STEERABLE = ALWAYS { -} "yes" +} "no" + diff --git a/src/Content.c b/src/Content.c index cf770c7..c423d64 100644 --- a/src/Content.c +++ b/src/Content.c @@ -89,7 +89,9 @@ static int CompareStrings(const void *string1, const void *string2); @@*/ void HTTP_ContentWork(CCTK_ARGUMENTS) { +#if 0 HTTP_SteerDispatch(); +#endif } /*@@ diff --git a/src/Server.c b/src/Server.c index 9bf56f7..dc9aaca 100644 --- a/src/Server.c +++ b/src/Server.c @@ -212,6 +212,113 @@ int HTTP_Write(httpRequest *request, const char *buffer, size_t count) return retval; } + /*@@ + @routine HTTP_UpdateState + @date Sat Sep 16 21:12:23 2000 + @author Tom Goodale + @desc + Updates the state of the server from the latest parameter values. + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ +int HTTP_UpdateState(cGH *cctkGH, httpState *state) +{ + int type; + CCTK_INT *value; + + static int steering = 1; + static int last_steered = -1; + + value = (CCTK_INT *)CCTK_ParameterGet("pause",CCTK_THORNSTRING, &type); + + state->paused = *value; + + if(cctkGH && ! state->paused) + { + if(steering) + { + value = (CCTK_INT *)CCTK_ParameterGet("steering_frequency",CCTK_THORNSTRING, &type); + + if(*value > 0 && + *value+last_steered <= cctkGH->cctk_iteration) + { + /* Time to steer */ + state->steer = 1; + last_steered = cctkGH->cctk_iteration; + } + else + { + state->steer = 0; + } + + if(*value <= 0) + { + /* Once steering is switched off, can't restart it ! */ + steering = 0; + } + } + } + else + { + state->steer = 1; + } + + + + value = (CCTK_INT *)CCTK_ParameterGet("terminate",CCTK_THORNSTRING, &type); + + state->terminate = *value; + + value = (CCTK_INT *)CCTK_ParameterGet("standalone",CCTK_THORNSTRING, &type); + + state->standalone = *value; + + if(!state->paused) + { + + value = (CCTK_INT *)CCTK_ParameterGet("timeout_seconds",CCTK_THORNSTRING, &type); + + state->timeout_seconds = *value; + + value = (CCTK_INT *)CCTK_ParameterGet("timeout_useconds",CCTK_THORNSTRING, &type); + + state->timeout_useconds = *value; + } + else + { + state->timeout_seconds = -1; + state->timeout_useconds = -1; + } + + return 0; +} + + /*@@ + @routine HTTP_Terminate + @date Sat Sep 16 21:40:27 2000 + @author Tom Goodale + @desc + Terminate the simulation. + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ +int HTTP_Terminate(cGH *cctkGH) +{ + CCTK_Exit(cctkGH, 0); + + return 0; +} + /******************************************************************** ********************* Local Routines ************************* ********************************************************************/ diff --git a/src/Sockets.c b/src/Sockets.c index e7f5c93..8891729 100644 --- a/src/Sockets.c +++ b/src/Sockets.c @@ -165,11 +165,21 @@ int HTTP_Poll(cGH *cctkGH, long sec, long usec) struct sockaddr_in clientname; struct timeval timeout; + struct timeval *real_timeout; - timeout.tv_sec = sec; - timeout.tv_usec = usec; + if(sec >=0) + { + timeout.tv_sec = sec; + timeout.tv_usec = usec; + + real_timeout = &timeout; + } + else + { + real_timeout = NULL; + } - /* Block until input arrives on one or more active sockets. */ + /* Check if any input is available on one or more active sockets. */ read_fd_set = active_fd_set; if (select (FD_SETSIZE, &read_fd_set, NULL, NULL, &timeout) < 0) diff --git a/src/Startup.c b/src/Startup.c index a829862..8fe2264 100644 --- a/src/Startup.c +++ b/src/Startup.c @@ -17,6 +17,7 @@ #include "cctk_Parameters.h" #include "httpd.h" +#include "http_Steer.h" static char *rcsid = "$Header$"; @@ -40,6 +41,8 @@ int HTTP_Startup(void) { DECLARE_CCTK_PARAMETERS + httpState state; + if(CCTK_MyProc(NULL) == 0) { /* Does the server provide any pages by default ? */ @@ -51,17 +54,28 @@ int HTTP_Startup(void) HTTP_SetupServer(port, queue_length); } - if(standalone) + HTTP_UpdateState(NULL, &state); + + while(state.standalone) { - while(1) + if(CCTK_MyProc(NULL) == 0) { - if(CCTK_MyProc(NULL) == 0) - { - HTTP_Poll(NULL, 10000,0); - } + HTTP_Poll(NULL, -1,-1); } - } + if(state.steer == 1) + { + HTTP_SteerDispatch(); + + HTTP_UpdateState(NULL, &state); + } + + if(state.terminate) + { + HTTP_Terminate(NULL); + } + } + return 0; } @@ -84,10 +98,31 @@ void HTTP_Work(CCTK_ARGUMENTS) DECLARE_CCTK_ARGUMENTS DECLARE_CCTK_PARAMETERS - if(CCTK_MyProc(cctkGH) == 0) + httpState state; + + HTTP_UpdateState(cctkGH, &state); + + do { - HTTP_Poll(cctkGH, timeout_seconds, timeout_useconds); - } + if(CCTK_MyProc(cctkGH) == 0) + { + HTTP_Poll(cctkGH, state.timeout_seconds, state.timeout_useconds); + } + + if(state.steer == 1) + { + HTTP_SteerDispatch(); + + HTTP_UpdateState(cctkGH, &state); + } + + if(state.terminate) + { + HTTP_Terminate(cctkGH); + } + + } while(state.paused); + } /*@@ diff --git a/src/httpd.h b/src/httpd.h index 50d0eb2..e6c6e3f 100644 --- a/src/httpd.h +++ b/src/httpd.h @@ -13,6 +13,16 @@ #ifndef __HTTP_H__ #define __HTTP_H__ 1 +typedef struct +{ + int steer; + int paused; + int terminate; + int timeout_seconds; + int timeout_useconds; + int standalone; +} httpState; + #ifdef __cplusplus extern "C" { @@ -30,6 +40,9 @@ int HTTP_Poll(cGH *cctkGH, long sec, long usec); int HTTP_RequestGET(cGH *cctkGH, httpRequest *request); int HTTP_RequestUnsupported(cGH *cctkGH, httpRequest *request); +/* State stuff */ +int HTTP_UpdateState(cGH *cctkGH, httpState *state); + #ifdef __cplusplus } #endif |