瀏覽代碼

handle 0 as specified in documentation

Christian Grothoff 17 年之前
父節點
當前提交
cff975d1ff
共有 5 個文件被更改,包括 23 次插入5 次删除
  1. 6 0
      ChangeLog
  2. 5 4
      doc/microhttpd.texi
  3. 9 0
      src/daemon/connection.c
  4. 3 0
      src/daemon/daemon.c
  5. 0 1
      src/daemon/reason_phrase.c

+ 6 - 0
ChangeLog

@@ -1,3 +1,9 @@
+Sun Aug 24 13:05:41 MDT 2008
+	 Now handling clients returning 0 from response callback
+	 as specified in the documentation (abort if internal
+	 select is used, retry immediately if a thread per 
+	 connection is used). -CG
+
 Sun Aug 24 12:44:43 MDT 2008
 	 Added missing reason phrase. -SG
 

+ 5 - 4
doc/microhttpd.texi

@@ -507,10 +507,11 @@ number of bytes that has been placed into @var{buf} should be returned.
 
 Note that returning zero will cause @mhd{} to try again, either
 ``immediately'' if in multi-threaded mode (in which case the callback
-may want to do blocking operations) or in the next round if MHD_run is
-used.  Returning zero for a daemon that runs in internal
-@cfunction{select} mode is an error (since it would result in busy
-waiting) and will cause the program to be aborted (@cfunction{abort}).
+may want to do blocking operations to avoid busy waiting) or in the
+next round if @code{MHD_run} is used.  Returning zero for a daemon
+that runs in internal @cfunction{select} mode is an error (since it
+would result in busy waiting) and cause the program to be aborted
+(@cfunction{abort}).
 
 @table @var
 @item cls

+ 9 - 0
src/daemon/connection.c

@@ -330,6 +330,9 @@ try_ready_normal_body (struct MHD_Connection *connection)
                        MHD_MIN (response->data_buffer_size,
                                 response->total_size -
                                 connection->response_write_position));
+  if ( (ret == 0) &&
+       (0 != (connection->daemon->options & MHD_USE_SELECT_INTERNALLY)) )
+    abort(); /* serious client API violation */
   if (ret == -1)
     {
       /* either error or http 1.0 transfer, close
@@ -1715,6 +1718,12 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
           if (connection->socket_fd != -1)
             connection_close_error (connection);
           return MHD_NO;
+        case MHD_TLS_CONNECTION_INIT:
+	case MHD_TLS_HELLO_REQUEST:
+	case MHD_TLS_HANDSHAKE_FAILED:
+	case MHD_TLS_HANDSHAKE_COMPLETE:
+	  EXTRA_CHECK(0);
+	  break;
         }
       break;
     }

+ 3 - 0
src/daemon/daemon.c

@@ -251,6 +251,9 @@ MHD_handle_connection (void *data)
         tv.tv_sec = timeout - (now - con->last_activity);
       else
         tv.tv_sec = 0;
+      if ( (con->state == MHD_CONNECTION_NORMAL_BODY_UNREADY) ||
+	   (con->state == MHD_CONNECTION_CHUNKED_BODY_UNREADY) )
+	timeout = 1; /* do not block */	
       num_ready = SELECT (max + 1,
                           &rs, &ws, &es, (timeout != 0) ? &tv : NULL);
       if (num_ready < 0)

+ 0 - 1
src/daemon/reason_phrase.c

@@ -2,7 +2,6 @@
      This file is part of libmicrohttpd
      (C) 2007 Lymba
 
-
      This library is free software; you can redistribute it and/or
      modify it under the terms of the GNU Lesser General Public
      License as published by the Free Software Foundation; either