aboutsummaryrefslogtreecommitdiff
path: root/src/Sockets.c
diff options
context:
space:
mode:
authorjshalf <jshalf@1faa4e14-9dd3-4be0-9f0e-ffe519881164>2001-05-18 02:50:51 +0000
committerjshalf <jshalf@1faa4e14-9dd3-4be0-9f0e-ffe519881164>2001-05-18 02:50:51 +0000
commit8b12a1b456d296db9c305a1f008dbf93f515301c (patch)
tree3cdb29f0a47b626f26d4b18055b676a5a0b32ee2 /src/Sockets.c
parentd843bdb3d90b9a4fc22ddff4c750376d27d0105e (diff)
Modifications so that all cluster nodes involved in a simulation will
use http server redirect to route web-browsers to the master httpd node. The modifications are able to sense the different between nodes on the same SMP with shared network interface and those on different boxes. Tested on SP2, IA64, and IA32 clusters so far. git-svn-id: http://svn.cactuscode.org/arrangements/CactusConnect/HTTPD/trunk@128 1faa4e14-9dd3-4be0-9f0e-ffe519881164
Diffstat (limited to 'src/Sockets.c')
-rw-r--r--src/Sockets.c147
1 files changed, 145 insertions, 2 deletions
diff --git a/src/Sockets.c b/src/Sockets.c
index 64fb5e0..93e8c8e 100644
--- a/src/Sockets.c
+++ b/src/Sockets.c
@@ -48,9 +48,16 @@
#include "httpd.h"
+#include "cctk.h"
+#include "cctk_DefineThorn.h"
+#include "cctk_Parameters.h"
+#ifdef CACTUSPUGH_PUGH
+#include "CactusPUGH/PUGH/src/include/pugh.h"
+#endif
+
static const char *rcsid = "$Header$";
-CCTK_FILEVERSION(CactusConnect_HTTPD_Sockets_c)
+CCTK_FILEVERSION(CactusConnect_HTTPD_Socket_c)
/********************************************************************
********************* Local Data Types ***********************
@@ -113,8 +120,9 @@ static fd_set active_fd_set;
static SOCKET sock;
static SOCKET minsock;
static SOCKET maxsock;
-
+static char httpredirect=0;
static httpSocket *socklist = NULL;
+static char httpmaster[1024];
static unsigned long int httpport = 0;
@@ -122,8 +130,89 @@ static unsigned long int httpport = 0;
********************* External Routines **********************
********************************************************************/
+#if 0 /* this would be more efficient, but PUGH doesn't define
+ a datatype for 8-byte integers. So instead,
+ setupRedirect will use the actual hostname. */
+CCTK_INT8 Util_GetHostAddr(char *hostname){
+ hostent *he;
+ char hostname[1025];
+ int addrlen;
+ CCTK_INT8 addr;
+
+ Util_GetHostName(hostname, 1024);
+ he=gethostbyname(hostname);
+ addrlen=he->h_length;
+ if(addrlen>sizeof(CCTK_INT8)) addrlen=CCTK_INT8;
+ addr=0;
+ memcpy(&addr,he->h_addr,addrlen);
+ return addr;
+}
+#endif
/*@@
+ @routine HTTP_SetupRedirect
+ @date Wed April 20 20:39:15 2001
+ @author John Shalf
+ @desc
+ Creates a socket to listen on purely for server redirect to the root node.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+int HTTP_SetupRedirect(cGH *cctkGH,int port, int queue_size,int hunt){
+ /* should not hunt */
+ int i;
+ char hostnm[1024];
+ char *alladdr;
+ int addrlen=1024;
+ int nprocs=CCTK_nProcs(NULL);
+ int proc=CCTK_MyProc(NULL);
+
+ puts("enter setup redirect------------");
+ memset(hostnm,0,addrlen);
+ Util_GetHostName(hostnm, addrlen);
+ alladdr=(char*)malloc(addrlen * nprocs);
+ memset(alladdr,0,addrlen*nprocs); /* zero it */
+#ifdef CCTK_MPI
+ { /* push stack */
+ pGH *pughGH = PUGH_pGH(cctkGH);
+ puts("all gather");
+ if(!pughGH) puts("********would fail");
+ MPI_Allgather(hostnm,addrlen,PUGH_MPI_CHAR,
+ alladdr,addrlen,PUGH_MPI_CHAR,
+ MPI_COMM_WORLD);
+ /* pughGH->PUGH_COMM_WORLD); fails if I use PUGH_COMM_WORLD */
+ puts("collected");
+ }
+#endif
+ /* set our master */
+ printf("alladdr is %s\n", alladdr);
+ strcpy(httpmaster,alladdr); /* the 0th element is the master hostname */
+ /* so compare my addr to the list sequentially */
+ for(i=0;i<nprocs;i++){
+ printf("Cycle through %u\n",i);
+ if(!strcmp(alladdr+i*addrlen,hostnm)){
+ /* we matched addresses */
+ if(i<proc || i==0) break; /* I'm not the lowest order */
+ /* otherwise, I am the lowest ranked processor with this
+ address that isn't the primary webserver. So
+ I should do a server redirect */
+ httpredirect=1; /* this has a redirect socket */
+ HTTP_SetupServer(port,queue_size,hunt);
+ HTTP_RegisterRedirect();
+ return 1;
+ }
+ }
+ printf("No Redirect**************\n");
+ httpredirect=0;
+ return 0; /* no registration performed */
+}
+
+/*@@
@routine HTTP_SetupServer
@date Wed Sep 13 20:39:15 2000
@author Tom Goodale
@@ -509,7 +598,61 @@ unsigned long int HTTP_Port(void)
return httpport;
}
+ /*@@
+ @routine HTTP_Master
+ @date Friday April 20 11:24:40 2001
+ @author John Shalf
+ @desc
+ Reports the hostname of the node the HTTP server is listening on.
+ The returns the hostname of the master as a string.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+@@*/
+char *HTTP_Master(void)
+{
+ return httpmaster;
+}
+
+ /*@@
+ @routine HTTP_IsServer
+ @date Friday April 20 11:24:40 2001
+ @author John Shalf
+ @desc
+ True if this node has a server socket open.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+@@*/
+char HTTP_IsServer(void){
+ if(CCTK_MyProc(NULL)==0 || httpredirect) return 1;
+ else return 0;
+}
+ /*@@
+ @routine HTTP_IsRedirect
+ @date Friday April 20 11:24:40 2001
+ @author John Shalf
+ @desc
+ True only if this node has a server open and that server
+ is exclusively used to redirect web traffic back to the root
+ node.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+@@*/
+char HTTP_IsRedirect(void){
+ return httpredirect;
+}
/********************************************************************
********************* Local Routines *************************
********************************************************************/