--- parser3/src/include/pa_http.h 2023/09/26 20:49:07 1.34 +++ parser3/src/include/pa_http.h 2026/10/26 19:06:51 1.40 @@ -1,14 +1,14 @@ /** @file Parser: commonly used functions. - Copyright (c) 2001-2023 Art. Lebedev Studio (http://www.artlebedev.com) + Copyright (c) 2001-2026 Art. Lebedev Studio (https://www.artlebedev.com) Authors: Konstantin Morshnev , Alexandr Petrosian */ #ifndef PA_HTTP_H #define PA_HTTP_H -#define IDENT_PA_HTTP_H "$Id: pa_http.h,v 1.34 2023/09/26 20:49:07 moko Exp $" +#define IDENT_PA_HTTP_H "$Id: pa_http.h,v 1.40 2026/10/26 19:06:51 moko Exp $" #include "pa_vstring.h" #include "pa_vint.h" @@ -22,11 +22,6 @@ #ifdef _MSC_VER #include -#define socklen_t int -#else -#define closesocket close -#define INVALID_SOCKET -1 -typedef int SOCKET; #endif #ifndef DOXYGEN @@ -63,7 +58,7 @@ public: void clear(){ headers.clear(); - content_type=""; + content_type.clear(); content_length=0; } @@ -113,6 +108,13 @@ public: bool read_header(); size_t read_post(char *, size_t); size_t send_body(const void *, size_t); + + /// bytes received after the request headers, not processed yet + String::C unprocessed(); + /// receives up to size bytes, returns 0 if the connection is closed + size_t receive(char *, size_t); + void set_nodelay(); + void set_send_timeout(int timeout_secs); }; class HTTPD_Server : public PA_Allocated { @@ -124,6 +126,15 @@ public: } static mode; static const char *port; + static int max_connections; // not thread local: never changes; INT_MAX by default + static int connections; // accepted and not finished yet + + static bool too_many_connections(){ return connections>max_connections; } + + /// +1 on accept, -1 by whoever owns the connection at the end: + /// HTTPD_Connection destructor destructor, or the parent reaping the child in PARALLEL mode + static void track_connection(int delta); + static void set_mode(const String&); static SOCKET bind(const char *); };