GNU libmicrohttpd  0.9.66
connection_close.c
Go to the documentation of this file.
1 /*
2  This file is part of libmicrohttpd
3  Copyright (C) 2007-2018 Daniel Pittman and Christian Grothoff
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
24 #include "internal.h"
25 #include "connection_close.h"
26 
27 
35 void
37 {
38  const struct MHD_Daemon *daemon = connection->daemon;
39 
40  connection->request.state = MHD_REQUEST_CLOSED;
42  if (! daemon->enable_turbo)
43  {
44 #ifdef HTTPS_SUPPORT
45  struct MHD_TLS_Plugin *tls;
46 
47  /* For TLS connection use shutdown of TLS layer
48  * and do not shutdown TCP socket. This give more
49  * chances to send TLS closure data to remote side.
50  * Closure of TLS layer will be interpreted by
51  * remote side as end of transmission. */
52  if (NULL != (tls = daemon->tls_api))
53  {
54  if (MHD_YES !=
55  tls->shutdown_connection (tls->cls,
56  connection->tls_cs))
57  {
58  (void) shutdown (connection->socket_fd,
59  SHUT_WR);
60  /* FIXME: log errors */
61  }
62  }
63  else /* Combined with next 'shutdown()'. */
64 #endif /* HTTPS_SUPPORT */
65  {
66  (void) shutdown (connection->socket_fd,
67  SHUT_WR); /* FIXME: log errors */
68  }
69  }
70 }
71 
72 
83 void
86 {
87  struct MHD_Daemon *daemon = connection->daemon;
88  struct MHD_Response *resp = connection->request.response;
89 
90  (void) rtc; // FIXME
91  MHD_connection_mark_closed_ (connection);
92  if (NULL != resp)
93  {
94  connection->request.response = NULL;
96  }
97  if (NULL != daemon->notify_connection_cb)
99  connection,
101 }
102 
103 /* end of connection_close.c */
struct MHD_Request request
Definition: internal.h:714
#define MHD_YES
Definition: microhttpd.h:140
MHD_RequestTerminationCode
Definition: microhttpd.h:1745
internal shared structures
struct MHD_Daemon * daemon
Definition: internal.h:672
MHD_NotifyConnectionCallback notify_connection_cb
Definition: internal.h:1044
enum MHD_REQUEST_STATE state
Definition: internal.h:546
functions to close connection
MHD_socket socket_fd
Definition: internal.h:749
bool enable_turbo
Definition: internal.h:1487
void MHD_connection_mark_closed_(struct MHD_Connection *connection)
void MHD_connection_close_(struct MHD_Connection *connection, enum MHD_RequestTerminationCode rtc)
enum MHD_RequestEventLoopInfo event_loop_info
Definition: internal.h:556
#define NULL
Definition: reason_phrase.c:30
enum MHD_Bool(* shutdown_connection)(void *cls, struct MHD_TLS_ConnectionState *cs)
struct MHD_Response * response
Definition: internal.h:380
void * notify_connection_cb_cls
Definition: internal.h:1049
void MHD_response_queue_for_destroy(struct MHD_Response *response)
Definition: response.c:88