From 0c3b402c17507499072421b6d57dc6ef84c37e3a Mon Sep 17 00:00:00 2001 From: Steffen Pohle Date: Fri, 17 Nov 2023 20:56:38 +0100 Subject: [PATCH] adding timeout when reading web data --- Changelog | 3 +++ Makefile | 2 +- UDPTCPNetwork.h | 1 + tcp.cc | 6 +++++- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Changelog b/Changelog index 0ab4f32..3ef160b 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,6 @@ +2023-11-17: +- TCP::WebGetFile timeout increased to 20000ms and added another function including an timeout parameter. + 2022-02-02: - TCP::WebGetFile downloaading from web is working fine now. - TCP constructor is dealing better on windows now. WinSock is Hell. diff --git a/Makefile b/Makefile index fbd2058..8df5783 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ .SILENT: help -VERSION=0.1 +VERSION=0.2 OBJLIB_NAME=UDPTCPNetwork -include Makefile.rules diff --git a/UDPTCPNetwork.h b/UDPTCPNetwork.h index 1198bb2..a5adfa0 100644 --- a/UDPTCPNetwork.h +++ b/UDPTCPNetwork.h @@ -143,6 +143,7 @@ public: int WebGetURLElements (string url, string *host, string *port, string *file); int WebGetFile (string url, char *buffer, int maxsize, char *formdata); + int WebGetFile (string url, char *buffer, int maxsize, char *formdata, int timeout_ms); }; diff --git a/tcp.cc b/tcp.cc index 1989f77..9ad1a2a 100644 --- a/tcp.cc +++ b/tcp.cc @@ -389,6 +389,10 @@ int TCP::WebHeaderGetParamValue(std::string line, std::string *parm, std::string * success : size of buffer */ int TCP::WebGetFile (string url, char *buffer, int maxsize, char *formdata) { + return WebGetFile(url, buffer, maxsize, formdata, 20000); +} + +int TCP::WebGetFile (string url, char *buffer, int maxsize, char *formdata, int timeout_ms) { char outdata[NET_BUFFERSIZE]; char indata[NET_BUFFERSIZE]; string host, port, file; @@ -427,7 +431,7 @@ int TCP::WebGetFile (string url, char *buffer, int maxsize, char *formdata) { // read header // indata[0] = '\0'; - len = ReadTimeout (indata, NET_BUFFERSIZE-1, 2000); + len = ReadTimeout (indata, NET_BUFFERSIZE-1, timeout_ms); if (len <= 0) { fprintf (stderr, "%s:%d reading header Error:%s\n", __FILE__, __LINE__, strerror(errno)); return -1;