1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
/*
This file is part of libmicrohttpd
Copyright (C) 2017, 2020 Karlson2k (Evgeny Grin)
Copyright (C) 2019 ng0
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
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file mhd_send.h
* @brief Declarations of send() wrappers.
* @author ng0
* @author Karlson2k (Evgeny Grin)
*/
#ifndef MHD_SEND_H
#define MHD_SEND_H
#include "platform.h"
#include "internal.h"
#if defined(HAVE_STDBOOL_H)
#include <stdbool.h>
#endif /* HAVE_STDBOOL_H */
#include <errno.h>
#include "mhd_sockets.h"
#include "connection.h"
#ifdef HTTPS_SUPPORT
#include "connection_https.h"
#endif
#ifdef HAVE_FREEBSD_SENDFILE
/**
* Initialises static variables
*/
void
MHD_send_init_static_vars_ (void);
#endif /* HAVE_FREEBSD_SENDFILE */
/**
* Send buffer to the client, push data from network buffer if requested
* and full buffer is sent.
*
* @param connection the MHD_Connection structure
* @param buffer content of the buffer to send
* @param buffer_size the size of the @a buffer (in bytes)
* @param push_data set to true to force push the data to the network from
* system buffers (usually set for the last piece of data),
* set to false to prefer holding incomplete network packets
* (more data will be send for the same reply).
* @return sum of the number of bytes sent from both buffers or
* error code (negative)
*/
ssize_t
MHD_send_data_ (struct MHD_Connection *connection,
const char *buffer,
size_t buffer_size,
bool push_data);
/**
* Send reply header with optional reply body.
*
* @param connection the MHD_Connection structure
* @param header content of header to send
* @param header_size the size of the @a header (in bytes)
* @param never_push_hdr set to true to disable internal algorithm
* that can push automatically header data
* alone to the network
* @param body content of the body to send (optional, may be NULL)
* @param body_size the size of the @a body (in bytes)
* @param complete_response set to true if complete response
* is provided by @a header and @a body,
* set to false if additional body data
* will be sent later
* @return sum of the number of bytes sent from both buffers or
* error code (negative)
*/
ssize_t
MHD_send_hdr_and_body_ (struct MHD_Connection *connection,
const char *header,
size_t header_size,
bool never_push_hdr,
const char *body,
size_t body_size,
bool complete_response);
#if defined(_MHD_HAVE_SENDFILE)
/**
* Function for sending responses backed by file FD.
*
* @param connection the MHD connection structure
* @return actual number of bytes sent
*/
ssize_t
MHD_send_sendfile_ (struct MHD_Connection *connection);
#endif
/**
* Set required TCP_NODELAY state for connection socket
*
* The function automatically updates sk_nodelay state.
* @param connection the connection to manipulate
* @param nodelay_state the requested new state of socket
* @return true if succeed, false if failed
*/
bool
MHD_connection_set_nodelay_state_ (struct MHD_Connection *connection,
bool nodelay_state);
#endif /* MHD_SEND_H */
|