--- parser3/src/main/pa_http.C 2026/10/10 21:51:21 1.138 +++ parser3/src/main/pa_http.C 2026/10/16 13:55:16 1.140 @@ -13,7 +13,11 @@ #include "pa_vfile.h" #include "pa_random.h" -volatile const char * IDENT_PA_HTTP_C="$Id: pa_http.C,v 1.138 2026/10/10 21:51:21 moko Exp $" IDENT_PA_HTTP_H; +#ifndef WIN32 +#include // for TCP_NODELAY +#endif + +volatile const char * IDENT_PA_HTTP_C="$Id: pa_http.C,v 1.140 2026/10/16 13:55:16 moko Exp $" IDENT_PA_HTTP_H; // defines @@ -1242,6 +1246,30 @@ size_t HTTPD_Connection::send_body(const return result; } +String::C HTTPD_Connection::unprocessed() { + return String::C(request->buf + request->body_offset, request->length - request->body_offset); +} + +size_t HTTPD_Connection::receive(char *dest, size_t max_bytes) { + ssize_t received_size=recv(sock, dest, max_bytes, 0); + if(received_size < 0) { + int no=pa_socks_errno(); + if(pa_socks_is_reset(no)) + return 0; + throw Exception("httpd.read", 0, "error receiving data: %s (%d)", pa_socks_strerr(no), no); + } + return received_size; +} + +void HTTPD_Connection::set_nodelay() { + int nodelay=1; + setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (const char *)&nodelay, sizeof(nodelay)); +} + +void HTTPD_Connection::set_send_timeout(int timeout_secs) { + set_socket_timeout(sock, SO_SNDTIMEO, timeout_secs); +} + HTTPD_Connection::~HTTPD_Connection(){ if(sock != INVALID_SOCKET){ LOG(pa_log("httpd [%d] closed", sock)); @@ -1249,17 +1277,8 @@ HTTPD_Connection::~HTTPD_Connection(){ } } -static int sock_ready(SOCKET fd, int timeout_value){ - struct timeval timeout = {0, timeout_value * 1000}; - fd_set fds; - FD_ZERO(&fds); - FD_SET(fd, &fds); - int nfds = (int)fd + 1; /* typecast as nfds is ignored in MSVC anyway */ - return select(nfds, &fds, NULL, NULL, &timeout)>0; /* read */ -} - bool HTTPD_Connection::accept(SOCKET server_sock, int timeout_value) { - int ready = sock_ready(server_sock, timeout_value); + int ready = pa_sock_ready(server_sock, false, timeout_value); if (ready < 0) { int no=pa_socks_errno(); if(no == EINTR)