--- parser3/src/main/pa_http.C 2026/10/10 21:51:21 1.138 +++ parser3/src/main/pa_http.C 2026/10/17 23:11:25 1.142 @@ -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.142 2026/10/17 23:11:25 moko Exp $" IDENT_PA_HTTP_H; // defines @@ -53,7 +57,7 @@ void pa_log(const char* fmt, ...); ssize_t pa_send(int sock, const char *buffer, size_t len){ size_t total_sent = 0; while (total_sent < len) { - ssize_t bytes_sent=send(sock, buffer + total_sent, len - total_sent, 0); + ssize_t bytes_sent=pa_sock_send(sock, buffer + total_sent, len - total_sent); if (bytes_sent < 0) { return bytes_sent; } else if (bytes_sent == 0) { @@ -151,7 +155,7 @@ public: bool read(SOCKET sock, size_t size){ if(length + size > buf_size) resize(buf_size * 2 + size); - ssize_t received_size=recv(sock, buf + length, size, 0); + ssize_t received_size=pa_sock_recv(sock, buf + length, size); if(received_size == 0) return false; if(received_size < 0) { @@ -1106,7 +1110,7 @@ ssize_t HTTPD_request::pa_recv(SOCKET so #endif { ALARM(pa_httpd_timeout); - ssize_t result=recv(sockfd, buffer, len, 0); + ssize_t result=pa_sock_recv(sockfd, buffer, len); ALARM(0); if(result < 0 && sock_timed_out(pa_socks_errno())) { PA_RECV_TIMEOUT @@ -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=pa_sock_recv(sock, dest, max_bytes); + 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,21 +1277,10 @@ 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) - return false; throw Exception("httpd.accept", 0, "error waiting for connection: %s (%d)", pa_socks_strerr(no), no); } if (ready == 0)