aboutsummaryrefslogtreecommitdiff
path: root/src/Sockets.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/Sockets.c')
-rw-r--r--src/Sockets.c216
1 files changed, 69 insertions, 147 deletions
diff --git a/src/Sockets.c b/src/Sockets.c
index 7b3a7f1..3d51641 100644
--- a/src/Sockets.c
+++ b/src/Sockets.c
@@ -2,12 +2,12 @@
@file Sockets.c
@date Wed Sep 13 20:39:15 2000
@author Tom Goodale
- @desc
- Routines which deal with sockets.
- These should probably move into thorn Socket at some point if
- they aren't already there.
+ @desc
+ Routines which deal with sockets.
+ These should probably move into thorn Socket at some point if
+ they aren't already there.
@enddesc
- @version $Header$
+ @version $Id$
@@*/
#include "cctk.h"
@@ -84,7 +84,7 @@ typedef enum {closed, open} isoSocketState;
typedef struct ISOSocket
{
struct ISOSocket *prev;
- struct ISOSocket *next;
+ struct ISOSocket *next;
unsigned long filedes;
isoSocketState state;
} isoSocket;
@@ -108,8 +108,8 @@ int Iso_SetupServer(const cGH *GH,isosurfacerGH *myGH,
int Iso_ShutdownServer(void);
int Iso_Poll(const cGH *GH, long sec, long usec);
int Iso_Read(isoSocket *connection, char *buffer, size_t count);
-int IsoWriteDataToClients(const char *metadata,
- CCTK_INT8 size,
+int IsoWriteDataToClients(const char *metadata,
+ CCTK_INT8 size,
IsoType type,
void *dataP);
@@ -122,7 +122,7 @@ static int InitialiseTCP(void);
/********************************************************************
********************* Local Data *****************************
********************************************************************/
-/* OK, maybe this stuff should go into the isosurfacer GH?
+/* OK, maybe this stuff should go into the isosurfacer GH?
Just general fear of global variables... putting it into the
GH uses the same amount of space as the static vars, but gives
us a sort of a "namespace".
@@ -155,15 +155,9 @@ static char *advertised_filename = NULL;
@routine Iso_SetupServer
@date Wed Sep 13 20:39:15 2000
@author Tom Goodale
- @desc
+ @desc
Creates a socket to listen on.
- @enddesc
- @calls
- @calledby
- @history
-
- @endhistory
-
+ @enddesc
@@*/
int Iso_SetupServer(const cGH *GH,isosurfacerGH *myGH,int dataport, int controlport, int queue_size, int hunt)
{
@@ -253,15 +247,9 @@ int Iso_SetupServer(const cGH *GH,isosurfacerGH *myGH,int dataport, int controlp
@routine Iso_ShutdownServer
@date Wed Sep 13 20:39:15 2000
@author Tom Goodale
- @desc
+ @desc
Closes all sockets we are interested in.
- @enddesc
- @calls
- @calledby
- @history
-
- @endhistory
-
+ @enddesc
@@*/
int Iso_ShutdownServer(void)
{
@@ -290,17 +278,11 @@ int Iso_ShutdownServer(void)
@routine Iso_Poll
@date Wed Sep 13 20:39:15 2000
@author Tom Goodale
- @desc
+ @desc
Main workhorse routine.
Looks for activity on any of the sockets which are open
and dispatches work.
- @enddesc
- @calls
- @calledby
- @history
-
- @endhistory
-
+ @enddesc
@@*/
int Iso_Poll(const cGH *GH, long sec, long usec)
{
@@ -316,15 +298,6 @@ int Iso_Poll(const cGH *GH, long sec, long usec)
struct sockaddr_in clientname;
struct timeval timeout;
struct timeval *real_timeout;
- /*** FIXME: can CCTK_Abort() have a 'const cGH *' parameter ?? ***/
- union
- {
- const cGH *const_ptr;
- cGH *non_const_ptr;
- } GH_fake_const;
-
-
- GH_fake_const.const_ptr = GH;
if(CCTK_MyProc(GH) != 0) return 0; /* not the root processor */
@@ -346,9 +319,9 @@ int Iso_Poll(const cGH *GH, long sec, long usec)
if (ERROR_CHECK(select (FD_SETSIZE, &read_fd_set, NULL, NULL, real_timeout)))
{
perror ("select");
- CCTK_Abort(GH_fake_const.non_const_ptr, EXIT_FAILURE);
+ abort ();
}
-
+
/* Service all the sockets with input pending. */
if (FD_ISSET (datasock, &read_fd_set))
{
@@ -361,7 +334,7 @@ int Iso_Poll(const cGH *GH, long sec, long usec)
if (ERROR_CHECK(new))
{
perror ("accept");
- CCTK_Abort(GH_fake_const.non_const_ptr, EXIT_FAILURE);
+ abort ();
}
fprintf (stderr,
"Isosurfacer: data connect to port %u from host %s, port %hd.\n",
@@ -383,7 +356,7 @@ int Iso_Poll(const cGH *GH, long sec, long usec)
if (ERROR_CHECK(new))
{
perror ("accept");
- CCTK_Abort(GH_fake_const.non_const_ptr, EXIT_FAILURE);
+ abort ();
}
fprintf (stderr,
"Isosurfacer: control connect to port %u from host %s, port %hd.\n",
@@ -393,7 +366,7 @@ int Iso_Poll(const cGH *GH, long sec, long usec)
SocketCreate(new, &controlsocklist);
}
-
+
return 0;
}
@@ -404,15 +377,6 @@ IsoCommand *Iso_PollCommand(const cGH *GH,IsoCommand *cmd)
struct timeval *real_timeout;
isoSocket *this;
- /*** FIXME: can CCTK_Abort() have a 'const cGH *' parameter ?? ***/
- union
- {
- const cGH *const_ptr;
- cGH *non_const_ptr;
- } GH_fake_const;
-
-
- GH_fake_const.const_ptr = GH;
if(CCTK_MyProc(GH) != 0) return 0; /* not the root processor */
@@ -421,13 +385,13 @@ IsoCommand *Iso_PollCommand(const cGH *GH,IsoCommand *cmd)
timeout.tv_sec = 0;
timeout.tv_usec = 0;
real_timeout = &timeout;
-
+
/* Check if any input is available on one or more active sockets. */
read_fd_set = active_fd_set;
if (ERROR_CHECK(select (FD_SETSIZE, &read_fd_set, NULL, NULL, real_timeout))){
perror ("select");
- CCTK_Abort(GH_fake_const.non_const_ptr, EXIT_FAILURE);
+ abort ();
}
/* get next command on the control socket list */
for(this = controlsocklist; this; this = this->next){
@@ -455,8 +419,8 @@ IsoCommand *Iso_PollCommand(const cGH *GH,IsoCommand *cmd)
return NULL;
}
-int IsoWriteDataToClients(const char *metadata,
- CCTK_INT8 size,
+int IsoWriteDataToClients(const char *metadata,
+ CCTK_INT8 size,
IsoType type,
void *dataP)
{
@@ -472,26 +436,26 @@ int IsoWriteDataToClients(const char *metadata,
byteswap(data,size,4);
/* for(i = 0; i < size; i++)
{
- I wish htons/htonl actually worked as you'd expect them to
+ I wish htons/htonl actually worked as you'd expect them to
data[i] = htons(data[i]);
}*/
/* printf("Pre-Swap Datasize=%lld:%llx\n",datasize,datasize); */
byteswap(&datatype,1,4);
byteswap(&datasize,1,8);
/* printf("PostSwap Datasize=%lld:%llx\n",datasize,datasize); */
- /* unfortunately short is 16 bits and long is 32 bits on some systems
- datatype = htons(datatype);
+ /* unfortunately short is 16 bits and long is 32 bits on some systems
+ datatype = htons(datatype);
datasize = htonl(datasize); */
/* Send data down all connected sockets. */
for(this = datasocklist; this; this = next)
{
next = this->next;
-
- retval=Iso_Write(this, (void*)(&datasize), 8);
+
+ retval=Iso_Write(this, (void*)(&datasize), 8);
/* printf("RetVal on size write=%d\n",retval); */
- Iso_Write(this, (void*)(&datatype), 4);
- Iso_Write(this, metadata, 64);
+ Iso_Write(this, (void*)(&datatype), 4);
+ Iso_Write(this, metadata, 64);
retval = Iso_Write(this, (void *)data, size*4);
if(retval < 0)
@@ -517,15 +481,9 @@ int IsoWriteDataToClients(const char *metadata,
@routine Iso_Write
@date Fri Sep 15 18:47:41 2000
@author Tom Goodale
- @desc
+ @desc
Writes part or all of an Iso data connection.
- @enddesc
- @calls
- @calledby
- @history
-
- @endhistory
-
+ @enddesc
@@*/
int Iso_Write(isoSocket *connection, const char *buffer, size_t count)
{
@@ -544,20 +502,20 @@ int Iso_Write(isoSocket *connection, const char *buffer, size_t count)
while(!done)
{
/* Try and send the data. Make sure we don't get a SIGPIPE if the
- * other end is closed.
+ * other end is closed.
*/
- retval = send(connection->filedes,
- buffer+bytes_sent,
- count-bytes_sent,
+ retval = send(connection->filedes,
+ buffer+bytes_sent,
+ count-bytes_sent,
MSG_NOSIGNAL);
-
+
/* Check for errors */
if(ERROR_CHECK(retval))
{
switch(errno)
{
#ifdef EMSGSIZE
- case EMSGSIZE : /* The socket requires that message be sent atomically,
+ case EMSGSIZE : /* The socket requires that message be sent atomically,
* and the size of the message to be sent made this
* impossible.
*/
@@ -579,7 +537,7 @@ int Iso_Write(isoSocket *connection, const char *buffer, size_t count)
break;
#endif
-#ifdef ENOBUFS
+#ifdef ENOBUFS
case ENOBUFS :
/* The output queue for a network interface was full. This generally indicates that the interface has
* stopped sending, but may be caused by transient congestion. (This cannot occur in Linux, packets are
@@ -589,10 +547,10 @@ int Iso_Write(isoSocket *connection, const char *buffer, size_t count)
break;
#endif
case EBADF : /* An invalid descriptor was specified. */
-#ifdef ENOTSOCK
+#ifdef ENOTSOCK
case ENOTSOCK : /* The filedescriptor is not a socket. */
#endif
-#ifdef ECONNRESET
+#ifdef ECONNRESET
case ECONNRESET : /* Connection reset by peer */
#endif
case EPIPE : /* The local end has been shut down on a connection oriented socket. In this case the process will also
@@ -600,13 +558,13 @@ int Iso_Write(isoSocket *connection, const char *buffer, size_t count)
*/
SocketClose(connection);
break;
-
+
case EINTR : /* A signal occurred.*/
-
+
case ENOMEM : /* No memory available. */
case EINVAL : /* Invalid argument passed. */
-
+
case EFAULT : /* An invalid user space address was specified for a parameter. */
break;
@@ -663,20 +621,14 @@ int Iso_Write(isoSocket *connection, const char *buffer, size_t count)
@routine Iso_Read
@date Mon Sep 18 10:14:03 2000
@author Tom Goodale
- @desc
+ @desc
Reads part or all of an Iso request.
- @enddesc
- @calls
- @calledby
- @history
-
- @endhistory
-
+ @enddesc
@@*/
int Iso_Read(isoSocket *connection, char *buffer, size_t count)
{
int retval;
-
+
if(connection->state == open)
{
/* Currently don't do anything fancy. */
@@ -700,17 +652,11 @@ int Iso_Read(isoSocket *connection, char *buffer, size_t count)
/*@@
@routine byteswap
- @date
+ @date
@author John Shalf
- @desc
-
- @enddesc
- @calls
- @calledby
- @history
-
- @endhistory
+ @desc
+ @enddesc
@@*/
static int byteswap(void *buf,CCTK_INT8 nelements,int elementsize)
{
@@ -721,16 +667,16 @@ static int byteswap(void *buf,CCTK_INT8 nelements,int elementsize)
return 0;
#else
buffer=(char *)buf;
- if(elementsize<=1) return 0;
-
+ if(elementsize<=1) return 0;
+
for(i=0;i<nelements;i++,buffer+=elementsize){
- /* do the swap thing on each element */
+ /* do the swap thing on each element */
for(s=0,d=elementsize-1;s<d;s++,d--){
- char c=buffer[s];
- buffer[s]=buffer[d];
+ char c=buffer[s];
+ buffer[s]=buffer[d];
buffer[d]=c;
}
- }
+ }
return 1;
#endif
}
@@ -739,15 +685,9 @@ static int byteswap(void *buf,CCTK_INT8 nelements,int elementsize)
@routine Iso_MakeSocket
@date Wed Sep 13 20:39:15 2000
@author Tom Goodale
- @desc
+ @desc
Creates a socket.
- @enddesc
- @calls
- @calledby
- @history
-
- @endhistory
-
+ @enddesc
@@*/
int Iso_MakeSocket (unsigned long port, int *hunt)
{
@@ -771,12 +711,12 @@ int Iso_MakeSocket (unsigned long port, int *hunt)
opt = 1;
setsockopt(this_sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
#endif
-
+
done = 0;
realport = port;
while(!done)
- {
+ {
/* Give the socket a name. */
name.sin_family = AF_INET;
name.sin_port = htons (realport);
@@ -786,7 +726,7 @@ int Iso_MakeSocket (unsigned long port, int *hunt)
if(hunt)
{
/* Hunt for a new port */
- fprintf(stderr, "Port %u taken, trying %u\n", realport, realport+1);
+ fprintf(stderr, "Port %u taken, trying %u\n", realport, realport+1);
realport++;
}
else
@@ -817,15 +757,9 @@ int Iso_MakeSocket (unsigned long port, int *hunt)
@routine SocketCreate
@date Thu Sep 21 15:03:32 2000
@author Tom Goodale
- @desc
+ @desc
Creates an isoSocket structure and links it to the list.
- @enddesc
- @calls
- @calledby
- @history
-
- @endhistory
-
+ @enddesc
@@*/
static isoSocket *SocketCreate(unsigned long int filedes, isoSocket **list)
{
@@ -839,7 +773,7 @@ static isoSocket *SocketCreate(unsigned long int filedes, isoSocket **list)
this->state = open;
this->prev = NULL;
this->next = *list;
-
+
if(*list)
{
(*list)->prev = this;
@@ -857,15 +791,9 @@ static isoSocket *SocketCreate(unsigned long int filedes, isoSocket **list)
@routine SocketDestroy
@date Thu Sep 21 15:04:03 2000
@author Tom Goodale
- @desc
+ @desc
Destroys an isoSocket structure and removes it from the list.
- @enddesc
- @calls
- @calledby
- @history
-
- @endhistory
-
+ @enddesc
@@*/
static void SocketDestroy(isoSocket *this, isoSocket **list)
{
@@ -898,15 +826,9 @@ static void SocketDestroy(isoSocket *this, isoSocket **list)
@routine SocketClose
@date Thu Sep 21 15:04:27 2000
@author Tom Goodale
- @desc
+ @desc
Closes the socket associated with an isoSocket structure.
- @enddesc
- @calls
- @calledby
- @history
-
- @endhistory
-
+ @enddesc
@@*/
static void SocketClose(isoSocket *this)
{