aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortradke <tradke@1faa4e14-9dd3-4be0-9f0e-ffe519881164>2002-04-22 14:01:02 +0000
committertradke <tradke@1faa4e14-9dd3-4be0-9f0e-ffe519881164>2002-04-22 14:01:02 +0000
commit97951e409ead94523f6d0b3017715131ea90c081 (patch)
tree3efd52cd3e82f2842abf94b11c7ef3328df42911
parent3dd07659c6e5612e6d6ef0bc22c51c09e23c0a93 (diff)
Catch 'Connection reset by peer' return code from socket calls.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusConnect/HTTPD/trunk@162 1faa4e14-9dd3-4be0-9f0e-ffe519881164
-rw-r--r--src/Sockets.c189
1 files changed, 96 insertions, 93 deletions
diff --git a/src/Sockets.c b/src/Sockets.c
index 4cf670c..caad22a 100644
--- a/src/Sockets.c
+++ b/src/Sockets.c
@@ -2,8 +2,8 @@
@file Sockets.c
@date Wed Sep 13 20:39:15 2000
@author Tom Goodale
- @desc
- Routines which deal with sockets.
+ @desc
+ Routines which deal with sockets.
These should probably move into thorn Socket at some point if
they aren't already there.
@enddesc
@@ -82,7 +82,7 @@ typedef enum {closed, open} httpSocketState;
typedef struct HTTPSocket
{
struct HTTPSocket *prev;
- struct HTTPSocket *next;
+ struct HTTPSocket *next;
unsigned long filedes;
httpSocketState state;
} httpSocket;
@@ -127,14 +127,14 @@ static unsigned long int httpport = 0;
@routine HTTP_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
+ @calls
+ @calledby
+ @history
+
+ @endhistory
@@*/
int HTTP_SetupServer(int port, int queue_size, int hunt)
@@ -154,7 +154,7 @@ int HTTP_SetupServer(int port, int queue_size, int hunt)
exit (EXIT_FAILURE);
}
-
+
Util_GetHostName(hostname, 1024);
httpport = hunt ? realport : port;
@@ -183,14 +183,14 @@ int HTTP_SetupServer(int port, int queue_size, int hunt)
@routine HTTP_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
+ @calls
+ @calledby
+ @history
+
+ @endhistory
@@*/
int HTTP_ShutdownServer(void)
@@ -213,16 +213,16 @@ int HTTP_ShutdownServer(void)
@routine HTTP_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
+ @calls
+ @calledby
+ @history
+
+ @endhistory
@@*/
int HTTP_Poll(cGH *cctkGH, long sec, long usec)
@@ -264,7 +264,7 @@ int HTTP_Poll(cGH *cctkGH, long sec, long usec)
perror ("select");
CCTK_Abort(cctkGH, EXIT_FAILURE);
}
-
+
/* Service all the sockets with input pending. */
if (FD_ISSET (sock, &read_fd_set))
{
@@ -291,7 +291,7 @@ int HTTP_Poll(cGH *cctkGH, long sec, long usec)
SocketCreate(new);
}
}
-
+
for(this = socklist; this; this = next)
{
next = this->next;
@@ -305,7 +305,7 @@ int HTTP_Poll(cGH *cctkGH, long sec, long usec)
}
}
-
+
return 0;
}
@@ -313,14 +313,14 @@ int HTTP_Poll(cGH *cctkGH, long sec, long usec)
@routine HTTP_Write
@date Fri Sep 15 18:47:41 2000
@author Tom Goodale
- @desc
+ @desc
Writes part or all of an HTTP reply.
- @enddesc
- @calls
- @calledby
- @history
-
- @endhistory
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
@@*/
int HTTP_Write(httpRequest *request, const char *buffer, size_t count)
@@ -343,20 +343,20 @@ int HTTP_Write(httpRequest *request, 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.
*/
@@ -378,7 +378,7 @@ int HTTP_Write(httpRequest *request, 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
@@ -388,21 +388,24 @@ int HTTP_Write(httpRequest *request, 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
+ 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
* receive a SIGPIPE unless MSG_NOSIGNAL is set.
*/
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;
@@ -459,20 +462,20 @@ int HTTP_Write(httpRequest *request, const char *buffer, size_t count)
@routine HTTP_Read
@date Mon Sep 18 10:14:03 2000
@author Tom Goodale
- @desc
+ @desc
Reads part or all of an HTTP request.
- @enddesc
- @calls
- @calledby
- @history
-
- @endhistory
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
@@*/
int HTTP_Read(httpRequest *request, char *buffer, size_t count)
{
int retval;
-
+
httpSocket *connection;
connection = (httpSocket *)request->connection;
@@ -498,14 +501,14 @@ int HTTP_Read(httpRequest *request, char *buffer, size_t count)
@routine HTTP_Port
@date Tue Oct 3 11:24:40 2000
@author Tom Goodale
- @desc
+ @desc
Reports the port the HTTP server is listening on.
- @enddesc
- @calls
- @calledby
- @history
-
- @endhistory
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
@@*/
unsigned long int HTTP_Port(void)
@@ -521,14 +524,14 @@ unsigned long int HTTP_Port(void)
@routine HTTP_MakeSocket
@date Wed Sep 13 20:39:15 2000
@author Tom Goodale
- @desc
+ @desc
Creates a socket.
- @enddesc
- @calls
- @calledby
- @history
-
- @endhistory
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
@@*/
SOCKET HTTP_MakeSocket (unsigned long port, int *hunt)
@@ -553,12 +556,12 @@ SOCKET HTTP_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);
@@ -568,7 +571,7 @@ SOCKET HTTP_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
@@ -599,14 +602,14 @@ SOCKET HTTP_MakeSocket (unsigned long port, int *hunt)
@routine SocketCreate
@date Thu Sep 21 15:03:32 2000
@author Tom Goodale
- @desc
+ @desc
Creates an httpSocket structure and links it to the list.
- @enddesc
- @calls
- @calledby
- @history
-
- @endhistory
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
@@*/
static httpSocket *SocketCreate(unsigned long int filedes)
@@ -621,7 +624,7 @@ static httpSocket *SocketCreate(unsigned long int filedes)
this->state = open;
this->prev = NULL;
this->next = socklist;
-
+
if(socklist)
{
socklist->prev = this;
@@ -639,14 +642,14 @@ static httpSocket *SocketCreate(unsigned long int filedes)
@routine SocketDestroy
@date Thu Sep 21 15:04:03 2000
@author Tom Goodale
- @desc
+ @desc
Destroys an httpSocket structure and removes it from the list.
- @enddesc
- @calls
- @calledby
- @history
-
- @endhistory
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
@@*/
static void SocketDestroy(httpSocket *this)
@@ -680,14 +683,14 @@ static void SocketDestroy(httpSocket *this)
@routine SocketClose
@date Thu Sep 21 15:04:27 2000
@author Tom Goodale
- @desc
+ @desc
Closes the socket associated with an httpSocket structure.
- @enddesc
- @calls
- @calledby
- @history
-
- @endhistory
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
@@*/
static void SocketClose(httpSocket *this)