libmicrohttpd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [libmicrohttpd] Problem destroying response objects


From: Christian Grothoff
Subject: Re: [libmicrohttpd] Problem destroying response objects
Date: Tue, 17 Mar 2009 12:48:19 -0600
User-agent: KMail/1.11.0 (Linux/2.6.27-11-generic; KDE/4.2.0; i686; ; )

I see your point, but the solution is a bit too Linux-specific -- especially 
since I would not like MHD behaving one way on Linux and differently on other 
platforms...  

So, is anyone on the list aware of how we could detect a (partial?) shutdown 
of a socket by the other side *without* doing actual read or write operations 
on the socket AND do so in a portable way? (A few #ifdef's might be ok for 
this in my book.)

Christian

On Monday 16 March 2009 12:35:10 pm Jon Nalley wrote:
> 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;
>
>  }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]