aboutsummaryrefslogtreecommitdiff
path: root/src/Sockets.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/Sockets.c')
-rw-r--r--src/Sockets.c55
1 files changed, 37 insertions, 18 deletions
diff --git a/src/Sockets.c b/src/Sockets.c
index 60aee22..b080ed0 100644
--- a/src/Sockets.c
+++ b/src/Sockets.c
@@ -61,13 +61,13 @@ CCTK_FILEVERSION(CactusConnect_HTTPD_Sockets_c)
typedef enum {closed, open} httpSocketState;
-typedef struct HTTPSocket
+typedef struct HTTPSocketTag
{
- struct HTTPSocket *prev;
- struct HTTPSocket *next;
+ httpSocket *prev;
+ httpSocket *next;
unsigned long filedes;
httpSocketState state;
-} httpSocket;
+} httpSocket_PLACEHOLDER;
/********************************************************************
********************* Local Routine Prototypes *********************
@@ -101,6 +101,26 @@ static unsigned long int httpport = 0;
********************* External Routines **********************
********************************************************************/
+ /*@@
+ @routine HTTP_Send
+ @date 10.04.2004
+ @author Steve White
+ @desc
+ Writes all of an HTTP reply.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+int
+HTTP_Send( httpRequest * request, const char * message )
+{
+ return HTTP_Write(request, message, strlen(message));
+}
+
/*@@
@routine HTTP_SetupServer
@date Wed Sep 13 20:39:15 2000
@@ -203,13 +223,7 @@ int HTTP_ShutdownServer(void)
@@*/
int HTTP_Poll(cGH *cctkGH, long sec, long usec)
{
-#ifdef HAVE_SOCKLEN_T
- socklen_t size;
-#else
- int size;
-#endif
- SOCKET new;
- fd_set read_fd_set;
+ fd_set read_fd_set = active_fd_set;
struct sockaddr_in clientname;
struct timeval timeout;
httpSocket *this, *next;
@@ -219,7 +233,6 @@ int HTTP_Poll(cGH *cctkGH, long sec, long usec)
timeout.tv_usec = usec;
/* Check if any input is available on one or more active sockets. */
- read_fd_set = active_fd_set;
if (select (FD_SETSIZE, &read_fd_set, NULL, NULL, sec >= 0 ? &timeout : NULL)
== SOCKET_ERROR)
@@ -232,8 +245,12 @@ int HTTP_Poll(cGH *cctkGH, long sec, long usec)
if (FD_ISSET (sock, &read_fd_set))
{
/* Connection request on original socket. */
- size = sizeof (clientname);
- new = accept (sock, (struct sockaddr *) &clientname, &size);
+#ifdef HAVE_SOCKLEN_T
+ socklen_t size = sizeof (clientname);
+#else
+ int size = sizeof (clientname);
+#endif
+ SOCKET new = accept (sock, (struct sockaddr *) &clientname, &size);
if (new == INVALID_SOCKET)
{
perror ("accept");
@@ -253,15 +270,17 @@ int HTTP_Poll(cGH *cctkGH, long sec, long usec)
}
}
- for(this = socklist; this; this = next)
+ this = socklist;
+ while( this )
{
- next = this->next;
+ httpSocket *next = this->next;
/* Data arriving on an already-connected socket. */
if (FD_ISSET (this->filedes, &read_fd_set) &&
HTTP_ReadFromClient (cctkGH, this) < 0)
{
SocketDestroy(this);
}
+ this = next;
}
return (0);
@@ -287,7 +306,7 @@ int HTTP_Write(httpRequest *request, const char *buffer, size_t count)
int retval = -1;
size_t bytes_sent = 0;
size_t halfcount;
- httpSocket *connection = (httpSocket *)request->connection;
+ httpSocket *connection = HTTP_Connection( request);
int done = 0;
int tmp;
fd_set this_set;
@@ -427,7 +446,7 @@ int HTTP_Read(httpRequest *request, char *buffer, size_t count)
{
int retval = -1;
- httpSocket *connection = (httpSocket *)request->connection;
+ httpSocket *connection = HTTP_Connection( request );
if(connection->state == open)
{