diff options
Diffstat (limited to 'src/include/microhttpd2.h')
-rw-r--r-- | src/include/microhttpd2.h | 203 |
1 files changed, 203 insertions, 0 deletions
diff --git a/src/include/microhttpd2.h b/src/include/microhttpd2.h index bb65f534..2fae90b1 100644 --- a/src/include/microhttpd2.h +++ b/src/include/microhttpd2.h | |||
@@ -1197,6 +1197,209 @@ _MHD_EXTERN void | |||
1197 | MHD_daemon_destroy (struct MHD_Daemon *daemon); | 1197 | MHD_daemon_destroy (struct MHD_Daemon *daemon); |
1198 | 1198 | ||
1199 | 1199 | ||
1200 | /** | ||
1201 | * Add another client connection to the set of connections managed by | ||
1202 | * MHD. This API is usually not needed (since MHD will accept inbound | ||
1203 | * connections on the server socket). Use this API in special cases, | ||
1204 | * for example if your HTTP server is behind NAT and needs to connect | ||
1205 | * out to the HTTP client, or if you are building a proxy. | ||
1206 | * | ||
1207 | * If you use this API in conjunction with a internal select or a | ||
1208 | * thread pool, you must set the option #MHD_USE_ITC to ensure that | ||
1209 | * the freshly added connection is immediately processed by MHD. | ||
1210 | * | ||
1211 | * The given client socket will be managed (and closed!) by MHD after | ||
1212 | * this call and must no longer be used directly by the application | ||
1213 | * afterwards. | ||
1214 | * | ||
1215 | * @param daemon daemon that manages the connection | ||
1216 | * @param client_socket socket to manage (MHD will expect | ||
1217 | * to receive an HTTP request from this socket next). | ||
1218 | * @param addr IP address of the client | ||
1219 | * @param addrlen number of bytes in @a addr | ||
1220 | * @return #MHD_SC_OK on success | ||
1221 | * The socket will be closed in any case; `errno` is | ||
1222 | * set to indicate further details about the error. | ||
1223 | * @ingroup specialized | ||
1224 | */ | ||
1225 | _MHD_EXTERN enum MHD_StatusCode | ||
1226 | MHD_daemon_add_connection (struct MHD_Daemon *daemon, | ||
1227 | MHD_socket client_socket, | ||
1228 | const struct sockaddr *addr, | ||
1229 | socklen_t addrlen); | ||
1230 | |||
1231 | |||
1232 | /** | ||
1233 | * Obtain the `select()` sets for this daemon. Daemon's FDs will be | ||
1234 | * added to fd_sets. To get only daemon FDs in fd_sets, call FD_ZERO | ||
1235 | * for each fd_set before calling this function. FD_SETSIZE is assumed | ||
1236 | * to be platform's default. | ||
1237 | * | ||
1238 | * This function should only be called in when MHD is configured to | ||
1239 | * use external select with 'select()' or with 'epoll'. In the latter | ||
1240 | * case, it will only add the single 'epoll()' file descriptor used by | ||
1241 | * MHD to the sets. It's necessary to use #MHD_get_timeout() in | ||
1242 | * combination with this function. | ||
1243 | * | ||
1244 | * This function must be called only for daemon started without | ||
1245 | * #MHD_USE_INTERNAL_POLLING_THREAD flag. | ||
1246 | * | ||
1247 | * @param daemon daemon to get sets from | ||
1248 | * @param read_fd_set read set | ||
1249 | * @param write_fd_set write set | ||
1250 | * @param except_fd_set except set | ||
1251 | * @param max_fd increased to largest FD added (if larger | ||
1252 | * than existing value); can be NULL | ||
1253 | * @return #MHD_SC_OK on success, otherwise error code | ||
1254 | * @ingroup event | ||
1255 | */ | ||
1256 | _MHD_EXTERN enum MHD_StatusCode | ||
1257 | MHD_daemon_get_fdset (struct MHD_Daemon *daemon, | ||
1258 | fd_set *read_fd_set, | ||
1259 | fd_set *write_fd_set, | ||
1260 | fd_set *except_fd_set, | ||
1261 | MHD_socket *max_fd); | ||
1262 | |||
1263 | |||
1264 | /** | ||
1265 | * Obtain the `select()` sets for this daemon. Daemon's FDs will be | ||
1266 | * added to fd_sets. To get only daemon FDs in fd_sets, call FD_ZERO | ||
1267 | * for each fd_set before calling this function. | ||
1268 | * | ||
1269 | * Passing custom FD_SETSIZE as @a fd_setsize allow usage of | ||
1270 | * larger/smaller than platform's default fd_sets. | ||
1271 | * | ||
1272 | * This function should only be called in when MHD is configured to | ||
1273 | * use external select with 'select()' or with 'epoll'. In the latter | ||
1274 | * case, it will only add the single 'epoll' file descriptor used by | ||
1275 | * MHD to the sets. It's necessary to use #MHD_get_timeout() in | ||
1276 | * combination with this function. | ||
1277 | * | ||
1278 | * This function must be called only for daemon started | ||
1279 | * without #MHD_USE_INTERNAL_POLLING_THREAD flag. | ||
1280 | * | ||
1281 | * @param daemon daemon to get sets from | ||
1282 | * @param read_fd_set read set | ||
1283 | * @param write_fd_set write set | ||
1284 | * @param except_fd_set except set | ||
1285 | * @param max_fd increased to largest FD added (if larger | ||
1286 | * than existing value); can be NULL | ||
1287 | * @param fd_setsize value of FD_SETSIZE | ||
1288 | * @return #MHD_SC_OK on success, otherwise error code | ||
1289 | * @ingroup event | ||
1290 | */ | ||
1291 | _MHD_EXTERN enum MHD_StatusCode | ||
1292 | MHD_daemon_get_fdset2 (struct MHD_Daemon *daemon, | ||
1293 | fd_set *read_fd_set, | ||
1294 | fd_set *write_fd_set, | ||
1295 | fd_set *except_fd_set, | ||
1296 | MHD_socket *max_fd, | ||
1297 | unsigned int fd_setsize); | ||
1298 | |||
1299 | |||
1300 | /** | ||
1301 | * Obtain the `select()` sets for this daemon. Daemon's FDs will be | ||
1302 | * added to fd_sets. To get only daemon FDs in fd_sets, call FD_ZERO | ||
1303 | * for each fd_set before calling this function. Size of fd_set is | ||
1304 | * determined by current value of FD_SETSIZE. It's necessary to use | ||
1305 | * #MHD_get_timeout() in combination with this function. | ||
1306 | * | ||
1307 | * This function could be called only for daemon started | ||
1308 | * without #MHD_USE_INTERNAL_POLLING_THREAD flag. | ||
1309 | * | ||
1310 | * @param daemon daemon to get sets from | ||
1311 | * @param read_fd_set read set | ||
1312 | * @param write_fd_set write set | ||
1313 | * @param except_fd_set except set | ||
1314 | * @param max_fd increased to largest FD added (if larger | ||
1315 | * than existing value); can be NULL | ||
1316 | * @return #MHD_YES on success, #MHD_NO if this | ||
1317 | * daemon was not started with the right | ||
1318 | * options for this call or any FD didn't | ||
1319 | * fit fd_set. | ||
1320 | * @ingroup event | ||
1321 | */ | ||
1322 | #define MHD_daemon_get_fdset(daemon,read_fd_set,write_fd_set,except_fd_set,max_fd) \ | ||
1323 | MHD_get_fdset2((daemon),(read_fd_set),(write_fd_set),(except_fd_set),(max_fd),FD_SETSIZE) | ||
1324 | |||
1325 | |||
1326 | /** | ||
1327 | * Obtain timeout value for polling function for this daemon. | ||
1328 | * This function set value to amount of milliseconds for which polling | ||
1329 | * function (`select()` or `poll()`) should at most block, not the | ||
1330 | * timeout value set for connections. | ||
1331 | * It is important to always use this function, even if connection | ||
1332 | * timeout is not set, as in some cases MHD may already have more | ||
1333 | * data to process on next turn (data pending in TLS buffers, | ||
1334 | * connections are already ready with epoll etc.) and returned timeout | ||
1335 | * will be zero. | ||
1336 | * | ||
1337 | * @param daemon daemon to query for timeout | ||
1338 | * @param timeout set to the timeout (in milliseconds) | ||
1339 | * @return #MHD_SC_OK on success, #MHD_SC_NO_TIMEOUT if timeouts are | ||
1340 | * not used (or no connections exist that would | ||
1341 | * necessitate the use of a timeout right now), otherwise | ||
1342 | * an error code | ||
1343 | * @ingroup event | ||
1344 | */ | ||
1345 | _MHD_EXTERN enum MHD_StatusCode | ||
1346 | MHD_daemon_get_timeout (struct MHD_Daemon *daemon, | ||
1347 | MHD_UNSIGNED_LONG_LONG *timeout); | ||
1348 | |||
1349 | |||
1350 | /** | ||
1351 | * Run webserver operations (without blocking unless in client | ||
1352 | * callbacks). This method should be called by clients in combination | ||
1353 | * with #MHD_get_fdset if the client-controlled select method is used | ||
1354 | * and #MHD_get_timeout(). | ||
1355 | * | ||
1356 | * This function is a convenience method, which is useful if the | ||
1357 | * fd_sets from #MHD_get_fdset were not directly passed to `select()`; | ||
1358 | * with this function, MHD will internally do the appropriate `select()` | ||
1359 | * call itself again. While it is always safe to call #MHD_run (if | ||
1360 | * #MHD_USE_INTERNAL_POLLING_THREAD is not set), you should call | ||
1361 | * #MHD_run_from_select if performance is important (as it saves an | ||
1362 | * expensive call to `select()`). | ||
1363 | * | ||
1364 | * @param daemon daemon to run | ||
1365 | * @return #MHD_SC_OK on success | ||
1366 | * @ingroup event | ||
1367 | */ | ||
1368 | _MHD_EXTERN enum MHD_StatusCode | ||
1369 | MHD_daemon_run (struct MHD_Daemon *daemon); | ||
1370 | |||
1371 | |||
1372 | /** | ||
1373 | * Run webserver operations. This method should be called by clients | ||
1374 | * in combination with #MHD_get_fdset and #MHD_get_timeout() if the | ||
1375 | * client-controlled select method is used. | ||
1376 | * | ||
1377 | * You can use this function instead of #MHD_run if you called | ||
1378 | * `select()` on the result from #MHD_get_fdset. File descriptors in | ||
1379 | * the sets that are not controlled by MHD will be ignored. Calling | ||
1380 | * this function instead of #MHD_run is more efficient as MHD will not | ||
1381 | * have to call `select()` again to determine which operations are | ||
1382 | * ready. | ||
1383 | * | ||
1384 | * This function cannot be used with daemon started with | ||
1385 | * #MHD_USE_INTERNAL_POLLING_THREAD flag. | ||
1386 | * | ||
1387 | * @param daemon daemon to run select loop for | ||
1388 | * @param read_fd_set read set | ||
1389 | * @param write_fd_set write set | ||
1390 | * @param except_fd_set except set | ||
1391 | * @return #MHD_SC_OK on success | ||
1392 | * @ingroup event | ||
1393 | */ | ||
1394 | _MHD_EXTERN enum MHD_StatusCode | ||
1395 | MHD_daemon_run_from_select (struct MHD_Daemon *daemon, | ||
1396 | const fd_set *read_fd_set, | ||
1397 | const fd_set *write_fd_set, | ||
1398 | const fd_set *except_fd_set); | ||
1399 | |||
1400 | |||
1401 | |||
1402 | |||
1200 | /* ********************* daemon options ************** */ | 1403 | /* ********************* daemon options ************** */ |
1201 | 1404 | ||
1202 | 1405 | ||