aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortradke <tradke@bfcf8e34-485d-4d46-a995-1fd6fa6fb178>2001-03-02 15:25:11 +0000
committertradke <tradke@bfcf8e34-485d-4d46-a995-1fd6fa6fb178>2001-03-02 15:25:11 +0000
commitec0835e9087ed0a42fddf97a695f6862db01d648 (patch)
treec362635f26294b0cf488885aec5619838c215086 /src
parent5a4d8c6cf12a1ee72d066b4e2dc5be3e1aa9adc8 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/Sockets.c168
1 files changed, 75 insertions, 93 deletions
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 <stdio.h>
#include <stdlib.h>
@@ -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;i<nelements;i++,buffer+=elementsize){
/* do the swap thing on each element */
for(s=0,d=elementsize-1;s<d;s++,d--){
- char c=buffer[s];
+ char c=buffer[s];
buffer[s]=buffer[d];
buffer[d]=c;
}
@@ -857,51 +884,6 @@ static void SocketClose(isoSocket *this)
}
}
- /*@@
- @routine GetHostName
- @date Fri Oct 20 12:12:34 2000
- @author Tom Goodale
- @desc
- Gets the fully qualified name of this host if possible.
- @enddesc
- @calls
- @calledby
- @history
-
- @endhistory
- @var name
- @vdesc character buffer to store name in
- @vtype char *
- @vio out
- @vcomment
-
- @endvar
- @var length
- @vdesc length of the character buffer
- @vtype int
- @vio in
- @vcomment
-
- @endvar
-
-@@*/
-static void GetHostName(char *name, int length)
-{
- gethostname(name, length);
-
- /* Does the name include the domain. */
- if(!strchr(name, '.'))
- {
-#ifdef HAVE_GETHOSTBYNAME
- struct hostent *thishostent;
-
- thishostent = gethostbyname(name);
-
- strncpy(name, thishostent->h_name, length);
-#endif
- }
-}
-
/******************************************************************************
******************************************************************************
******************************************************************************/