[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [libmicrohttpd] Problem destroying response objects
From: |
Jon Nalley |
Subject: |
Re: [libmicrohttpd] Problem destroying response objects |
Date: |
Mon, 16 Mar 2009 13:35:10 -0500 |
On Fri, Mar 13, 2009 at 2:54 PM, Christian Grothoff <address@hidden> wrote:
> The suggested way to terminate these types of connections where clients fail
> to read from the socket is to use a timeout (use
> MHD_OPTION_CONNECTION_TIMEOUT); that will close idle connections and should
> then also destroy the response objects.
The problem with using MHD_OPTION_CONNECTION_TIMEOUT (for me) is that
the client could potentially drop and re-connect many times before the
timeout is reached. Since I am trying to implement "ajax long
polling" (see
http://en.wikipedia.org/wiki/Comet_(programming)#Ajax_with_long_polling)
I would prefer that clients not timeout if they are still connected
(or at least have a fairly long timeout).
I have solved my problem with the following patch. Admittedly, this
is fairly specific to my particular problem. The patch is also Linux
specific due to the _GNU_SOURCE and using POLLRDHUP (available in
linux since 2.6.17).
diff -r 9f2a4ba2c19e src/daemon/connection.c
--- a/src/daemon/connection.c Mon Mar 16 10:52:06 2009 -0500
+++ b/src/daemon/connection.c Mon Mar 16 11:38:10 2009 -0500
@@ -30,6 +30,9 @@
#include "memorypool.h"
#include "response.h"
#include "reason_phrase.h"
+
+#define _GNU_SOURCE
+#include <poll.h>
/**
* Message to transmit when http 1.1 request is received
@@ -1765,6 +1768,7 @@
unsigned int timeout;
const char *end;
char *line;
+ struct pollfd fds;
while (1)
{
@@ -2100,6 +2104,17 @@
connection_close_error (connection);
return MHD_NO;
}
+ if (connection->socket_fd != -1)
+ {
+ fds.fd = connection->socket_fd;
+ fds.events = POLLRDHUP;
+ poll (&fds, 1, 1);
+ if (fds.revents & POLLRDHUP)
+ {
+ connection_close_error (connection);
+ return MHD_NO;
+ }
+ }
return MHD_YES;
}