fix div by zero
[oweals/gnunet.git] / src / transport / plugin_transport_http_server.c
index 892d97050029bc022c4bfe2746289ec6e75b3e7a..abf60280ad240107153ccb5abba8d6a2c41bacf7 100644 (file)
@@ -2,20 +2,18 @@
      This file is part of GNUnet
      Copyright (C) 2002-2014, 2017 GNUnet e.V.
 
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 3, or (at your
-     option) any later version.
+     GNUnet is free software: you can redistribute it and/or modify it
+     under the terms of the GNU Affero General Public License as published
+     by the Free Software Foundation, either version 3 of the License,
+     or (at your option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
-
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-     Boston, MA 02110-1301, USA.
+     Affero General Public License for more details.
+    
+     You should have received a copy of the GNU Affero General Public License
+     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 /**
@@ -1651,7 +1649,7 @@ server_send_callback (void *cls,
  *
  * @param cls current session as closure
  * @param message the message to be forwarded to transport service
- * @return #GNUNET_OK
+ * @return #GNUNET_OK (all OK)
  */
 static int
 server_receive_mst_cb (void *cls,
@@ -1976,6 +1974,37 @@ server_disconnect_cb (void *cls,
 }
 
 
+/**
+ * Callback from MHD when a connection starts/stops
+ *
+ * @param cls closure with the `struct HTTP_Server_Plugin *`
+ * @param connection connection handle
+ * @param socket_context socket-specific pointer
+ * @param toe reason for connection notification
+ * @see #MHD_OPTION_NOTIFY_CONNECTION
+ */
+static void
+server_connection_cb (void *cls,
+                      struct MHD_Connection *connection,
+                      void **socket_context,
+                      enum MHD_ConnectionNotificationCode toe)
+{
+  struct HTTP_Server_Plugin *plugin = cls;
+  const union MHD_ConnectionInfo *info;
+
+  if (MHD_CONNECTION_NOTIFY_STARTED == toe)
+    return;
+
+  /* Reschedule to remove closed socket from our select set */
+  info = MHD_get_connection_info (connection,
+                                  MHD_CONNECTION_INFO_DAEMON);
+  GNUNET_assert (NULL != info);
+  server_reschedule (plugin,
+                     info->daemon,
+                     GNUNET_YES);
+}
+
+
 /**
  * Check if incoming connection is accepted.
  *
@@ -2257,6 +2286,8 @@ run_mhd_start_daemon (struct HTTP_Server_Plugin *plugin,
                                        GNUNET_MAX_MESSAGE_SIZE),
                              MHD_OPTION_NOTIFY_COMPLETED,
                              &server_disconnect_cb, plugin,
+                             MHD_OPTION_NOTIFY_CONNECTION,
+                             &server_connection_cb, plugin,
                              MHD_OPTION_EXTERNAL_LOGGER,
                              &server_log, NULL,
                              MHD_OPTION_END);