adding timeout when reading web data

master
Steffen Pohle 2 years ago
parent 9817a6b5a8
commit 0c3b402c17

@ -1,3 +1,6 @@
2023-11-17:
- TCP::WebGetFile timeout increased to 20000ms and added another function including an timeout parameter.
2022-02-02: 2022-02-02:
- TCP::WebGetFile downloaading from web is working fine now. - TCP::WebGetFile downloaading from web is working fine now.
- TCP constructor is dealing better on windows now. WinSock is Hell. - TCP constructor is dealing better on windows now. WinSock is Hell.

@ -1,5 +1,5 @@
.SILENT: help .SILENT: help
VERSION=0.1 VERSION=0.2
OBJLIB_NAME=UDPTCPNetwork OBJLIB_NAME=UDPTCPNetwork
-include Makefile.rules -include Makefile.rules

@ -143,6 +143,7 @@ public:
int WebGetURLElements (string url, string *host, string *port, string *file); 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 WebGetFile (string url, char *buffer, int maxsize, char *formdata, int timeout_ms);
}; };

@ -389,6 +389,10 @@ int TCP::WebHeaderGetParamValue(std::string line, std::string *parm, std::string
* success : size of buffer * success : size of buffer
*/ */
int TCP::WebGetFile (string url, char *buffer, int maxsize, char *formdata) { 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 outdata[NET_BUFFERSIZE];
char indata[NET_BUFFERSIZE]; char indata[NET_BUFFERSIZE];
string host, port, file; string host, port, file;
@ -427,7 +431,7 @@ int TCP::WebGetFile (string url, char *buffer, int maxsize, char *formdata) {
// read header // read header
// //
indata[0] = '\0'; indata[0] = '\0';
len = ReadTimeout (indata, NET_BUFFERSIZE-1, 2000); len = ReadTimeout (indata, NET_BUFFERSIZE-1, timeout_ms);
if (len <= 0) { if (len <= 0) {
fprintf (stderr, "%s:%d reading header Error:%s\n", __FILE__, __LINE__, strerror(errno)); fprintf (stderr, "%s:%d reading header Error:%s\n", __FILE__, __LINE__, strerror(errno));
return -1; return -1;

Loading…
Cancel
Save