From ec0835e9087ed0a42fddf97a695f6862db01d648 Mon Sep 17 00:00:00 2001 From: tradke Date: Fri, 2 Mar 2001 15:25:11 +0000 Subject: Advertised the hostname/port number information in a temporary file for download. More or less just a hack for GGF for now. Removed dependency on PUGH, gcc warnings fixed, untabified, use Util_GetHostName(). git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGHIO/IsoSurfacer/trunk@38 bfcf8e34-485d-4d46-a995-1fd6fa6fb178 --- src/Sockets.c | 168 ++++++++++++++++++++++++++-------------------------------- 1 file changed, 75 insertions(+), 93 deletions(-) (limited to 'src') diff --git a/src/Sockets.c b/src/Sockets.c index 1e2f6d1..8c37b3e 100644 --- a/src/Sockets.c +++ b/src/Sockets.c @@ -11,7 +11,8 @@ @@*/ #include "cctk.h" -#include "CactusPUGH/PUGH/src/include/pugh.h" +#include "util_Network.h" +#include "CactusBase/IOUtil/src/ioutil_AdvertisedFiles.h" #include #include @@ -93,7 +94,7 @@ typedef struct ISOSocket static int byteswap(void *buf,CCTK_INT8 nelements,int elementsize); -IsoCommand *Iso_PollCommand(cGH *cGH,IsoCommand *cmd); +IsoCommand *Iso_PollCommand(cGH *GH,IsoCommand *cmd); int Iso_Write(isoSocket *connection, const char *buffer, size_t count); static SOCKET Iso_MakeSocket (unsigned long port, int *hunt); @@ -102,9 +103,15 @@ static isoSocket *SocketCreate(unsigned long int filedes, isoSocket **list); static void SocketDestroy(isoSocket *this, isoSocket **list); static void SocketClose(isoSocket *this); int Iso_SetupServer(cGH *GH,isosurfacerGH *myGH, - int dataport, int controlport, int queue_size, int hunt); + int dataport, int controlport, int queue_size, int hunt); +int Iso_ShutdownServer(void); +int Iso_Poll(cGH *GH, long sec, long usec); +int Iso_Read(isoSocket *connection, char *buffer, size_t count); +int IsoWriteDataToClients(const char *metadata, + CCTK_INT8 size, + IsoType type, + void *dataP); -static void GetHostName(char *name, int length); static int InitialiseTCP(void); /******************************************************************** @@ -132,8 +139,8 @@ static SOCKET maxsock; static isoSocket *controlsocklist = NULL; static isoSocket *datasocklist = NULL; -static chosen_controlport = 0; -static chosen_dataport = 0; +static int chosen_controlport = 0; +static int chosen_dataport = 0; /******************************************************************** @@ -157,15 +164,17 @@ static chosen_dataport = 0; @@*/ int Iso_SetupServer(cGH *GH,isosurfacerGH *myGH,int dataport, int controlport, int queue_size, int hunt) { - char hostname[1025]; int realdport; int realcport; + ioAdvertisedFileDesc advertised_file; + FILE *tempfile; + char hostname[1025]; + char tempfilename[L_tmpnam]; -#ifdef CCTK_MPI - pGH *pughGH; - pughGH = PUGH_pGH(GH); - if(pughGH->myproc!=0) return 0; /* not the root processor */ -#endif + + myGH = myGH; + + if(CCTK_MyProc(GH) != 0) return 0; /* not the root processor */ /* Some systems need special logic for starting up TCP. */ InitialiseTCP(); @@ -188,21 +197,50 @@ int Iso_SetupServer(cGH *GH,isosurfacerGH *myGH,int dataport, int controlport, i exit (EXIT_FAILURE); } - GetHostName(hostname, 1024); - - printf("Isosurfacer listening for control connections on %s port %d/\n", hostname, hunt ? realcport : controlport); - printf("Isosurfacer listening for data connections on %s port %d/\n", hostname, hunt ? realdport : dataport); chosen_controlport = hunt ? realcport:controlport; chosen_dataport = hunt ? realdport:dataport; minsock = datasock > controlsock ? controlsock : datasock; maxsock = datasock > controlsock ? datasock : controlsock; - /* Initialize the set of active sockets. */ FD_ZERO (&active_fd_set); FD_SET (controlsock, &active_fd_set); FD_SET (datasock, &active_fd_set); + Util_GetHostName(hostname, sizeof (hostname)); + CCTK_VInfo (CCTK_THORNSTRING, + "Isosurfacer listening for connections\n" + " host '%s' control port %d data port %d", + hostname, chosen_controlport, chosen_dataport); + + tempfile = NULL; + if (tmpnam (tempfilename)) + { + tempfile = fopen (tempfilename, "w"); + } + + if (tempfile) + { + fprintf (tempfile, "Hostname: %s\n", hostname); + fprintf (tempfile, "Control port: %d\n", chosen_controlport); + fprintf (tempfile, "Data port: %d\n", chosen_dataport); + fclose (tempfile); + + /* FIXME: this can go after the old filename scheme has gone */ + advertised_file.slice = ""; + advertised_file.thorn = CCTK_THORNSTRING; + advertised_file.varname = "All variables"; + advertised_file.description = "Streamed isosurface geometry data"; + advertised_file.mimetype = "data/streamed-isosurfaces"; + + IOUtil_AdvertiseFile (GH, tempfilename, &advertised_file); + } + else + { + CCTK_WARN (2, "Couldn't create unique temporary file ! " + "Isosurfacer data streaming was not advertised."); + } + return 0; } @@ -267,12 +305,8 @@ int Iso_Poll(cGH *GH, long sec, long usec) struct timeval timeout; struct timeval *real_timeout; - isoSocket *this; - isoSocket *next; -#ifdef CCTK_MPI - pGH *pughGH = PUGH_pGH(GH); - if(pughGH->myproc!=0) return 0; /* not the root processor */ -#endif + + if(CCTK_MyProc(GH) != 0) return 0; /* not the root processor */ if(sec >=0) { timeout.tv_sec = sec; @@ -310,7 +344,7 @@ int Iso_Poll(cGH *GH, long sec, long usec) } fprintf (stderr, "Isosurfacer: data connect to port %u from host %s, port %hd.\n", - chosen_dataport, + chosen_dataport, inet_ntoa (clientname.sin_addr), ntohs (clientname.sin_port)); @@ -332,7 +366,7 @@ int Iso_Poll(cGH *GH, long sec, long usec) } fprintf (stderr, "Isosurfacer: control connect to port %u from host %s, port %hd.\n", - chosen_controlport, + chosen_controlport, inet_ntoa (clientname.sin_addr), ntohs (clientname.sin_port)); @@ -342,23 +376,17 @@ int Iso_Poll(cGH *GH, long sec, long usec) return 0; } -IsoCommand *Iso_PollCommand(cGH *GH,IsoCommand *cmd){ -#ifdef HAVE_SOCKLEN_T - socklen_t size; -#else - int size; -#endif +IsoCommand *Iso_PollCommand(cGH *GH,IsoCommand *cmd) +{ fd_set read_fd_set; - struct sockaddr_in clientname; struct timeval timeout; struct timeval *real_timeout; isoSocket *this; - isoSocket *next; -#ifdef CCTK_MPI - pGH *pughGH = PUGH_pGH(GH); - if(pughGH->myproc!=0) return 0; /* not the root processor */ -#endif + + + if(CCTK_MyProc(GH) != 0) return 0; /* not the root processor */ + /* always a timeout of 0 */ timeout.tv_sec = 0; timeout.tv_usec = 0; @@ -380,12 +408,12 @@ IsoCommand *Iso_PollCommand(cGH *GH,IsoCommand *cmd){ /* puts("EndIsoRead"); */ /* Data arriving on an already-connected socket. */ if (r <= 0){ - puts("Destroy Socket"); - SocketDestroy(this, &controlsocklist); - puts("done destroy"); - if(controlsocklist==NULL) puts("*********It did the right thing"); - else puts("*******baaad socket... bad bad bad..."); - return NULL; + puts("Destroy Socket"); + SocketDestroy(this, &controlsocklist); + puts("done destroy"); + if(controlsocklist==NULL) puts("*********It did the right thing"); + else puts("*******baaad socket... bad bad bad..."); + return NULL; } else return cmd; /* return immediately with the new command (first available) */ } @@ -396,18 +424,15 @@ IsoCommand *Iso_PollCommand(cGH *GH,IsoCommand *cmd){ int IsoWriteDataToClients(const char *metadata, CCTK_INT8 size, IsoType type, - void *dataP) + void *dataP) { CCTK_INT4 *data=(CCTK_INT4*)dataP; int retval; - CCTK_INT4 i; CCTK_INT4 datatype=type; CCTK_INT8 datasize=size; isoSocket *this; isoSocket *next; - CCTK_INT4 tmppolys[3] = {0,0,0}; - CCTK_REAL4 tmpverts[3] = {0.0,0.0,0.0}; /* Convert the data to network byte order */ byteswap(data,size,4); @@ -449,6 +474,8 @@ int IsoWriteDataToClients(const char *metadata, data[i] = htons(data[i]); } #endif + + return (0); } @@ -662,7 +689,7 @@ static int byteswap(void *buf,CCTK_INT8 nelements,int elementsize) for(i=0;ih_name, length); -#endif - } -} - /****************************************************************************** ****************************************************************************** ******************************************************************************/ -- cgit v1.2.3