diff options
Diffstat (limited to 'src/Sockets.c')
-rw-r--r-- | src/Sockets.c | 56 |
1 files changed, 43 insertions, 13 deletions
diff --git a/src/Sockets.c b/src/Sockets.c index fea3c92..322b628 100644 --- a/src/Sockets.c +++ b/src/Sockets.c @@ -71,6 +71,7 @@ CCTK_FILEVERSION(DevThorns_isosurfacer_Socket_c) #define MSG_NOSIGNAL 0 #endif + typedef enum {closed, open} isoSocketState; typedef struct ISOSocket @@ -85,6 +86,7 @@ typedef struct ISOSocket ********************* Local Routine Prototypes ********************* ********************************************************************/ +IsoCommand *Iso_PollCommand(cGH *cctkGH,IsoCommand *cmd); int Iso_Write(isoSocket *connection, const char *buffer, size_t count); static SOCKET Iso_MakeSocket (unsigned long port, int *hunt); @@ -95,7 +97,7 @@ static void SocketClose(isoSocket *this); static int InitialiseTCP(void); -static int Iso_ReadFromClient(cGH *cctkGH, isoSocket *this); +static int Iso_ReadFromClient(cGH *cctkGH, isoSocket *this,IsoCommand *cmd); /******************************************************************** ********************* Other Routine Prototypes ********************* @@ -342,22 +344,46 @@ int Iso_Poll(cGH *cctkGH, long sec, long usec) SocketCreate(new, &controlsocklist); } + + return 0; +} + +IsoCommand *Iso_PollCommand(cGH *cctkGH,IsoCommand *cmd){ +#ifdef HAVE_SOCKLEN_T + socklen_t size; +#else + int size; +#endif + fd_set read_fd_set; + struct sockaddr_in clientname; + struct timeval timeout; + struct timeval *real_timeout; + + isoSocket *this; + isoSocket *next; + /* always a timeout of 0 */ + timeout.tv_sec = 0; + timeout.tv_usec = 0; + real_timeout = &timeout; - for(this = controlsocklist; this; this = next) - { - next = this->next; - if(FD_ISSET (this->filedes, &read_fd_set)) - { + /* 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(cctkGH, EXIT_FAILURE); + } + /* get next command on the control socket list */ + for(this = controlsocklist; this; this = this->next){ + if(FD_ISSET (this->filedes, &read_fd_set)){ /* Data arriving on an already-connected socket. */ - if (Iso_ReadFromClient (cctkGH, this) < 0) - { - SocketDestroy(this, &controlsocklist); + if (Iso_Read (this, cmd->buffer,64+64+64) <= 0){ + SocketDestroy(this, &controlsocklist); } + else return cmd; /* return immediately with the new command (first available) */ } } - - - return 0; + return NULL; } int IsoWriteDataToClients(const char *metadata, @@ -801,8 +827,12 @@ static void SocketClose(isoSocket *this) @endhistory @@*/ -static int Iso_ReadFromClient(cGH *cctkGH, isoSocket *this) +static int Iso_ReadFromClient(cGH *cctkGH, isoSocket *this,IsoCommand *command) { + /* Need to have 64+64+64 buffer here (datastruct) + put the buffer in a union. + */ + return -1; } |