~ubuntu-branches/ubuntu/vivid/libmicrohttpd/vivid

« back to all changes in this revision

Viewing changes to src/daemon/connection.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-05-18 12:41:53 UTC
  • mfrom: (1.3.1 upstream) (7.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20090518124153-nfup3gwcwpt4soes
Tags: 0.4.2-1
MergingĀ upstreamĀ versionĀ 0.4.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include "response.h"
32
32
#include "reason_phrase.h"
33
33
 
 
34
#if HAVE_NETINET_TCP_H
 
35
/* for TCP_CORK */
 
36
#include <netinet/tcp.h>
 
37
#endif
 
38
 
34
39
/**
35
40
 * Message to transmit when http 1.1 request is received
36
41
 */
236
241
         have already sent the full message body */
237
242
      connection->response_write_position = response->total_size;
238
243
    }
239
 
  if ((response->total_size == -1) &&
 
244
  if ((response->total_size == MHD_SIZE_UNKNOWN) &&
240
245
      (0 == strcasecmp (connection->version, MHD_HTTP_VERSION_1_1)))
241
246
    connection->have_chunked_response = MHD_YES;
242
247
  else
282
287
MHD_connection_close (struct MHD_Connection *connection,
283
288
                      enum MHD_RequestTerminationCode termination_code)
284
289
{
285
 
 
286
290
  SHUTDOWN (connection->socket_fd, SHUT_RDWR);
287
291
  CLOSE (connection->socket_fd);
288
292
  connection->socket_fd = -1;
289
293
  connection->state = MHD_CONNECTION_CLOSED;
290
 
  if (connection->daemon->notify_completed != NULL)
 
294
  if ( (NULL != connection->daemon->notify_completed) &&
 
295
       (MHD_YES == connection->client_aware) )
291
296
    connection->daemon->notify_completed (connection->daemon->
292
 
                                          notify_completed_cls, connection,
293
 
                                          &connection->client_context,
294
 
                                          termination_code);
 
297
                                          notify_completed_cls, connection,
 
298
                                          &connection->client_context,
 
299
                                          termination_code);    
 
300
  connection->client_aware = MHD_NO;
295
301
}
296
302
 
297
303
/**
438
444
  char buf[128];
439
445
 
440
446
  connection->have_chunked_upload = MHD_NO;
441
 
  if (connection->response->total_size == -1)
 
447
  if (connection->response->total_size == MHD_SIZE_UNKNOWN)
442
448
    {
443
449
      have = MHD_get_response_header (connection->response,
444
450
                                      MHD_HTTP_HEADER_CONNECTION);
467
473
    {
468
474
      SPRINTF (buf,
469
475
               "%llu", 
470
 
               connection->response->total_size);
 
476
               (unsigned long long)connection->response->total_size);
471
477
      MHD_add_response_header (connection->response,
472
478
                               MHD_HTTP_HEADER_CONTENT_LENGTH, buf);
473
479
    }
1105
1111
    {
1106
1112
      instant_retry = MHD_NO;
1107
1113
      if ((connection->have_chunked_upload == MHD_YES) &&
1108
 
          (connection->remaining_upload_size == -1))
 
1114
          (connection->remaining_upload_size == MHD_SIZE_UNKNOWN))
1109
1115
        {
1110
1116
          if ((connection->current_chunk_offset ==
1111
1117
               connection->current_chunk_size)
1210
1216
          processed = available;
1211
1217
        }
1212
1218
      used = processed;
 
1219
      connection->client_aware = MHD_YES;
1213
1220
      if (MHD_NO ==
1214
1221
          connection->daemon->default_handler (connection->daemon->
1215
1222
                                               default_handler_cls,
1237
1244
      /* dh left "processed" bytes in buffer for next time... */
1238
1245
      buffer_head += used;
1239
1246
      available -= used;
1240
 
      if (connection->remaining_upload_size != -1)
 
1247
      if (connection->remaining_upload_size != MHD_SIZE_UNKNOWN)
1241
1248
        connection->remaining_upload_size -= used;
1242
1249
    }
1243
1250
  while (instant_retry == MHD_YES);
1511
1518
        }
1512
1519
      else
1513
1520
        {
1514
 
          connection->remaining_upload_size = -1;       /* unknown size */
 
1521
          connection->remaining_upload_size = MHD_SIZE_UNKNOWN;
1515
1522
          if (0 ==
1516
1523
              strcasecmp (MHD_lookup_connection_value
1517
1524
                          (connection, MHD_HEADER_KIND,
1536
1543
  connection->last_activity = time (NULL);
1537
1544
  if (connection->state == MHD_CONNECTION_CLOSED)
1538
1545
    return MHD_NO;
 
1546
  /* make sure "read" has a reasonable number of bytes
 
1547
     in buffer to use per system call (if possible) */
 
1548
  if (connection->read_buffer_offset + MHD_BUF_INC_SIZE >
 
1549
      connection->read_buffer_size)
 
1550
    try_grow_read_buffer (connection);
1539
1551
  if (MHD_NO == do_read (connection))
1540
1552
    return MHD_YES;
1541
1553
  while (1)
1882
1894
                continue;
1883
1895
            }
1884
1896
          if ((connection->remaining_upload_size == 0) ||
1885
 
              ((connection->remaining_upload_size == -1) &&
 
1897
              ((connection->remaining_upload_size == MHD_SIZE_UNKNOWN) &&
1886
1898
               (connection->read_buffer_offset == 0) &&
1887
1899
               (MHD_YES == connection->read_closed)))
1888
1900
            {
1961
1973
            }
1962
1974
          connection->state = MHD_CONNECTION_HEADERS_SENDING;
1963
1975
 
1964
 
#if HAVE_TCP_CORK
 
1976
#if HAVE_DECL_TCP_CORK
1965
1977
          /* starting header send, set TCP cork */
1966
1978
          {
1967
1979
            const int val = 1;
2024
2036
          /* no default action */
2025
2037
          break;
2026
2038
        case MHD_CONNECTION_FOOTERS_SENT:
2027
 
#if HAVE_TCP_CORK
 
2039
#if HAVE_DECL_TCP_CORK
2028
2040
          /* done sending, uncork */
2029
2041
          {
2030
2042
            const int val = 0;
2034
2046
#endif
2035
2047
          MHD_destroy_response (connection->response);
2036
2048
          if (connection->daemon->notify_completed != NULL)
2037
 
            connection->daemon->notify_completed (connection->daemon->
2038
 
                                                  notify_completed_cls,
2039
 
                                                  connection,
2040
 
                                                  &connection->client_context,
2041
 
                                                  MHD_REQUEST_TERMINATED_COMPLETED_OK);
 
2049
            {
 
2050
              connection->daemon->notify_completed (connection->daemon->
 
2051
                                                    notify_completed_cls,
 
2052
                                                    connection,
 
2053
                                                    &connection->client_context,
 
2054
                                                    MHD_REQUEST_TERMINATED_COMPLETED_OK);
 
2055
            }
 
2056
          connection->client_aware = MHD_NO;
2042
2057
          end =
2043
2058
            MHD_lookup_connection_value (connection, MHD_HEADER_KIND,
2044
2059
                                         MHD_HTTP_HEADER_CONNECTION);
2097
2112
  if ((connection->socket_fd != -1) &&
2098
2113
      (timeout != 0) && (time (NULL) - timeout > connection->last_activity))
2099
2114
    {
2100
 
      connection_close_error (connection);
 
2115
      MHD_connection_close (connection, MHD_REQUEST_TERMINATED_TIMEOUT_REACHED);
2101
2116
      return MHD_NO;
2102
2117
    }
2103
2118
  return MHD_YES;