gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [libmicrohttpd] branch master updated (f3dd2a63 -> 0bc2fe6f


From: gnunet
Subject: [GNUnet-SVN] [libmicrohttpd] branch master updated (f3dd2a63 -> 0bc2fe6f)
Date: Tue, 21 Mar 2017 21:49:56 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a change to branch master
in repository libmicrohttpd.

    from f3dd2a63 Added autoconf module for detection of select() trigger on 
shutdown of listening socket.
     new d14c6aa0 style fixes to i18n example
     new 222acd1c clarify when it is ok to call MHD_get_fdset in documentation, 
document MHD_get_fdset2()
     new 93fad63d make error message more friendly
     new 6b03d68f document MHD_CONNECTION_INFO_CONNECTION_TIMEOUT in manual
     new 7aa69301 add -lrt for glibc < 2.17 compatibility
     new 0bc2fe6f add -lrt for glib

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 ChangeLog                   |  8 +++++
 configure.ac                |  2 ++
 doc/libmicrohttpd.texi      | 21 ++++++++++++
 src/examples/msgs_i18n.c    | 78 +++++++++++++++++++++++++--------------------
 src/include/microhttpd.h    | 41 +++++++++++++++---------
 src/microhttpd/connection.c | 13 +++++---
 src/microhttpd/daemon.c     | 24 +++++++++++---
 src/microhttpd/internal.h   |  6 ++++
 8 files changed, 134 insertions(+), 59 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 6881370f..c8fcffb9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Tue Mar 21 13:51:04 CET 2017
+       Use "-lrt" to link libmicrohttpd if we are using
+       clock_gettime() as needed by glibc < 2.17. -CG
+
+Tue Mar 21 13:42:07 CET 2017
+       Allow chaining of suspend-resume calls withuot
+       the application processing data from the network. -CG
+
 Mon Mar 20 0:51:24 MSK 2017
        Added autoconf module for detection whatever shutdown of listening 
socket
        trigger select. This is only reliable method to use such feature as some
diff --git a/configure.ac b/configure.ac
index 5442ed85..7a44c0d5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -939,6 +939,8 @@ AC_LINK_IFELSE(
   ],
   [
     AC_DEFINE([HAVE_CLOCK_GET_TIME], [1], [Define to 1 if you have 
`clock_get_time', `host_get_clock_service' and `mach_port_deallocate' 
functions.])
+# For glibc < 2.17, we need -lrt:    
+    MHD_LIBDEPS="-lrt $MHD_LIBDEPS"
     AC_MSG_RESULT([[yes]])
   ],
   [AC_MSG_RESULT([[no]])
diff --git a/doc/libmicrohttpd.texi b/doc/libmicrohttpd.texi
index dba1d08f..1d6438d9 100644
--- a/doc/libmicrohttpd.texi
+++ b/doc/libmicrohttpd.texi
@@ -1594,6 +1594,15 @@ is added to @var{read_fd_set}. The list of currently 
existent
 connections is scanned and their file descriptors added to the correct
 set.
 
+When calling this function, FD_SETSIZE is assumed to be platform's
+default.  If you changed FD_SETSIZE for your application,
+you should use @code{MHD_get_fdset2()} instead.
+
+This function should only be called in when MHD is configured to use
+external select with @code{select()} or with @code{epoll()}.  In
+the latter case, it will only add the single @code{epoll()} file
+descriptor used by MHD to the sets.
+
 After the call completed successfully: the variable referenced by
 @var{max_fd} references the file descriptor with highest integer
 identifier. The variable must be set to zero before invoking this
@@ -1605,6 +1614,10 @@ the right options for this call.
 @end deftypefun
 
 
address@hidden int MHD_get_fdset2 (struct MHD_Daemon *daemon, fd_set * 
read_fd_set, fd_set * write_fd_set, fd_set * except_fd_set, int *max_fd, 
unsigned int fd_setsize)
+Like @code{MHD_get_fdset()}, except that you can manually specify the value of 
FD_SETSIZE used by your application.
+
+
 @deftypefun int MHD_get_timeout (struct MHD_Daemon *daemon, unsigned long long 
*timeout)
 @cindex timeout
 Obtain timeout value for select for this daemon (only needed if
@@ -2801,6 +2814,14 @@ socket was first accepted.  Note that this is NOT the 
same as the
 
 Takes no extra arguments.
 
address@hidden MHD_CONNECTION_INFO_TIMEOUT
+Returns pointer to an @code{unsigned int} that is the current timeout
+used for the connection (in seconds, 0 for no timeout).  Note that
+while suspended connections will not timeout, the timeout value
+returned for suspended connections will be the timeout that the
+connection will use after it is resumed, and thus might not be zero.
+
+Takes no extra arguments.
 @end table
 @end deftp
 
diff --git a/src/examples/msgs_i18n.c b/src/examples/msgs_i18n.c
index 220729af..2d8eb566 100755
--- a/src/examples/msgs_i18n.c
+++ b/src/examples/msgs_i18n.c
@@ -19,7 +19,8 @@
 /**
  * @file msgs_i18n.c
  * @brief example for how to use translate libmicrohttpd messages
- * @author Christian Grothoff, Silvio Clecio (silvioprog)
+ * @author Christian Grothoff
+ * @author Silvio Clecio (silvioprog)
  */
 
 /*
@@ -35,51 +36,60 @@
  * export LANGUAGE=pt_BR
  * ./msgs_i18n
  * # it may print: Opção inválida 4196490! (Você terminou a lista com 
MHD_OPTION_END?)
- *
- * # tip: if you get any problem in your i18n application, you can debug it 
using `strace` tool, e.g:
- * $ strace -e trace=open ./msgs_i18n
- * 
  */
-
 #include <stdio.h>
 #include <locale.h>
 #include <libintl.h>
 #include <microhttpd.h>
 
-#ifndef _
-#define _(fm) dgettext("libmicrohttpd", fm)
-#endif
 
 static int
-ahc_echo(void *cls,
-         struct MHD_Connection *cnc,
-         const char *url,
-         const char *mt,
-         const char *ver,
-         const char *upd,
-         size_t *upsz,
-         void **ptr) {
-    return MHD_NO;
+ahc_echo (void *cls,
+         struct MHD_Connection *cnc,
+         const char *url,
+         const char *mt,
+         const char *ver,
+         const char *upd,
+         size_t *upsz,
+         void **ptr)
+{  
+  return MHD_NO;
 }
 
+
 static void
-error_handler(void *cls,
-              const char *fm,
-              va_list ap) {
-    vprintf(_(fm), ap);
+error_handler (void *cls,
+              const char *fm,
+              va_list ap)
+{
+  /* Here we do the translation using GNU gettext.
+     As the error message is from libmicrohttpd, we specify
+     "libmicrohttpd" as the translation domain here. */
+  vprintf (dgettext ("libmicrohttpd",
+                    fm),
+         ap);
 }
 
+
 int
-main() {
-    setlocale(LC_ALL, "");
-    /* notice I'm using PO files in the directory 
"libmicrohttpd/src/examples/locale", please change it matching
-     * where the MHD PO files are installed */
-    bindtextdomain("libmicrohttpd", "locale");
-    MHD_start_daemon(MHD_USE_SELECT_INTERNALLY | MHD_FEATURE_MESSAGES | 
MHD_USE_ERROR_LOG,
-                     8080,
-                     NULL, NULL,
-                     &ahc_echo, NULL,
-                     MHD_OPTION_EXTERNAL_LOGGER, &error_handler, NULL
-                     /* MHD_OPTION_END - to raise the error "Invalid option 
..." we are going to translate */);
-    return 1; /* purposely */
+main (int argc,
+      char **argv)
+{
+  setlocale(LC_ALL, "");
+
+  /* The example uses PO files in the directory 
+     "libmicrohttpd/src/examples/locale".  This
+     needs to be adapted to match
+     where the MHD PO files are installed. */
+  bindtextdomain ("libmicrohttpd",
+                 "locale");
+  MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_FEATURE_MESSAGES | 
MHD_USE_ERROR_LOG,
+                   8080,
+                   NULL, NULL,
+                   &ahc_echo, NULL,
+                   MHD_OPTION_EXTERNAL_LOGGER, &error_handler, NULL,
+                   99999 /* invalid option, to raise the error 
+                            "Invalid option ..." which we are going 
+                            to translate */);
+  return 1; /* This program won't "succeed"... */
 }
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
index a09cddf3..40545452 100644
--- a/src/include/microhttpd.h
+++ b/src/include/microhttpd.h
@@ -2178,8 +2178,13 @@ MHD_add_connection (struct MHD_Daemon *daemon,
  * before calling this function. FD_SETSIZE is assumed
  * to be platform's default.
  *
- * This function could be called only for daemon started
- * without MHD_USE_INTERNAL_POLLING_THREAD flag.
+ * This function should only be called in when MHD is configured to
+ * use external select with @code{select()} or with @code{epoll()}.
+ * In the latter case, it will only add the single @code{epoll()} file
+ * descriptor used by MHD to the sets.
+ *
+ * This function must be called only for daemon started
+ * without #MHD_USE_INTERNAL_POLLING_THREAD flag.
  *
  * @param daemon daemon to get sets from
  * @param read_fd_set read set
@@ -2205,12 +2210,18 @@ MHD_get_fdset (struct MHD_Daemon *daemon,
  * Obtain the `select()` sets for this daemon.
  * Daemon's FDs will be added to fd_sets. To get only
  * daemon FDs in fd_sets, call FD_ZERO for each fd_set
- * before calling this function. Passing custom FD_SETSIZE
- * as @a fd_setsize allow usage of larger/smaller than
- * platform's default fd_sets.
+ * before calling this function.
  *
- * This function could be called only for daemon started
- * without MHD_USE_INTERNAL_POLLING_THREAD flag.
+ * Passing custom FD_SETSIZE as @a fd_setsize allow usage of
+ * larger/smaller than platform's default fd_sets.
+ *
+ * This function should only be called in when MHD is configured to
+ * use external select with @code{select()} or with @code{epoll()}.
+ * In the latter case, it will only add the single @code{epoll()} file
+ * descriptor used by MHD to the sets.
+ *
+ * This function must be called only for daemon started
+ * without #MHD_USE_INTERNAL_POLLING_THREAD flag.
  *
  * @param daemon daemon to get sets from
  * @param read_fd_set read set
@@ -2227,11 +2238,11 @@ MHD_get_fdset (struct MHD_Daemon *daemon,
  */
 _MHD_EXTERN int
 MHD_get_fdset2 (struct MHD_Daemon *daemon,
-               fd_set *read_fd_set,
-               fd_set *write_fd_set,
-               fd_set *except_fd_set,
-               MHD_socket *max_fd,
-               unsigned int fd_setsize);
+               fd_set *read_fd_set,
+               fd_set *write_fd_set,
+               fd_set *except_fd_set,
+               MHD_socket *max_fd,
+               unsigned int fd_setsize);
 
 
 /**
@@ -2242,7 +2253,7 @@ MHD_get_fdset2 (struct MHD_Daemon *daemon,
  * determined by current value of FD_SETSIZE.
  *
  * This function could be called only for daemon started
- * without MHD_USE_INTERNAL_POLLING_THREAD flag.
+ * without #MHD_USE_INTERNAL_POLLING_THREAD flag.
  *
  * @param daemon daemon to get sets from
  * @param read_fd_set read set
@@ -2288,7 +2299,7 @@ MHD_get_timeout (struct MHD_Daemon *daemon,
  * fd_sets from #MHD_get_fdset were not directly passed to `select()`;
  * with this function, MHD will internally do the appropriate `select()`
  * call itself again.  While it is always safe to call #MHD_run (if
- * ::MHD_USE_INTERNAL_POLLING_THREAD is not set), you should call
+ * #MHD_USE_INTERNAL_POLLING_THREAD is not set), you should call
  * #MHD_run_from_select if performance is important (as it saves an
  * expensive call to `select()`).
  *
@@ -2315,7 +2326,7 @@ MHD_run (struct MHD_Daemon *daemon);
  * ready.
  *
  * This function cannot be used with daemon started with
- * MHD_USE_INTERNAL_POLLING_THREAD flag.
+ * #MHD_USE_INTERNAL_POLLING_THREAD flag.
  *
  * @param daemon daemon to run select loop for
  * @param read_fd_set read set
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 36c05716..695a605c 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -92,7 +92,7 @@
  * minimal.
  */
 #ifdef HAVE_MESSAGES
-#define INTERNAL_ERROR "<html><head><title>Internal server 
error</title></head><body>Some programmer needs to study the manual more 
carefully.</body></html>"
+#define INTERNAL_ERROR "<html><head><title>Internal server 
error</title></head><body>Please ask the developer of this Web server to 
carefully read the GNU libmicrohttpd documentation about connection management 
and blocking.</body></html>"
 #else
 #define INTERNAL_ERROR ""
 #endif
@@ -1415,10 +1415,11 @@ MHD_connection_update_event_loop_info (struct 
MHD_Connection *connection)
         case MHD_CONNECTION_CONTINUE_SENT:
           if (connection->read_buffer_offset == connection->read_buffer_size)
             {
-              if ((MHD_YES != try_grow_read_buffer (connection)) &&
-                  (0 != (connection->daemon->options &
-                         MHD_USE_INTERNAL_POLLING_THREAD)) &&
-                  (! connection->suspended))
+              if ( (MHD_YES != try_grow_read_buffer (connection)) &&
+                  (0 != (connection->daemon->options &
+                         MHD_USE_INTERNAL_POLLING_THREAD)) &&
+                  (! connection->suspended) &&
+                  (! connection->just_resumed) )
                 {
                   /* failed to grow the read buffer, and the
                      client which is supposed to handle the
@@ -1822,6 +1823,7 @@ call_connection_handler (struct MHD_Connection 
*connection)
     return;                     /* already queued a response */
   processed = 0;
   connection->client_aware = true;
+  connection->just_resumed = false;    
   if (MHD_NO ==
       connection->daemon->default_handler (connection->daemon-> 
default_handler_cls,
                                           connection,
@@ -1984,6 +1986,7 @@ process_request_body (struct MHD_Connection *connection)
         }
       used = processed;
       connection->client_aware = true;
+      connection->just_resumed = false;
       if (MHD_NO ==
           connection->daemon->default_handler 
(connection->daemon->default_handler_cls,
                                                connection,
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 991577b1..e94ad64c 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -1046,8 +1046,8 @@ internal_get_fdset2 (struct MHD_Daemon *daemon,
  * as @a fd_setsize allow usage of larger/smaller than
  * platform's default fd_sets.
  *
- * This function could be called only for daemon started
- * without MHD_USE_INTERNAL_POLLING_THREAD flag.
+ * This function must be called only for daemon started
+ * without #MHD_USE_INTERNAL_POLLING_THREAD flag.
  *
  * @param daemon daemon to get sets from
  * @param read_fd_set read set
@@ -1106,9 +1106,12 @@ MHD_get_fdset2 (struct MHD_Daemon *daemon,
     }
 #endif
 
-  return internal_get_fdset2 (daemon, read_fd_set,
-                              write_fd_set, except_fd_set,
-                              max_fd, fd_setsize);
+  return internal_get_fdset2 (daemon,
+                             read_fd_set,
+                              write_fd_set,
+                             except_fd_set,
+                              max_fd,
+                             fd_setsize);
 }
 
 
@@ -2796,7 +2799,18 @@ MHD_resume_connection (struct MHD_Connection *connection)
     MHD_PANIC (_("Cannot resume connections without enabling 
MHD_ALLOW_SUSPEND_RESUME!\n"));
   MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
   connection->resuming = true;
+  connection->just_resumed = true;
   daemon->resuming = true;
+  if (connection->connection_timeout == daemon->connection_timeout)
+  {
+    /* move to the end... */
+    XDLL_remove (daemon->normal_timeout_head,
+                daemon->normal_timeout_tail,
+                connection);
+    XDLL_insert (daemon->normal_timeout_head,
+                daemon->normal_timeout_tail,
+                connection);
+  }
   MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
   if ( (MHD_ITC_IS_VALID_(daemon->itc)) &&
        (! MHD_itc_activate_ (daemon->itc, "r")) )
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
index 5350c013..3abd9731 100644
--- a/src/microhttpd/internal.h
+++ b/src/microhttpd/internal.h
@@ -947,6 +947,12 @@ struct MHD_Connection
    * Is the connection wanting to resume?
    */
   bool resuming;
+  
+  /**
+   * Did the connection just resume? (Means we are generous
+   * in dealing with a full read buffer...).
+   */
+  bool just_resumed;
 };
 
 

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

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