summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorMathias Schnarrenberger <mathias.schnarrenberger@web.de>2021-04-05 14:18:17 +0200
committerMathias Schnarrenberger <mathias.schnarrenberger@web.de>2021-04-05 14:18:17 +0200
commit20ce7578cc9b60d37fb1664fadfb561b547f8280 (patch)
treeea974c8c7882df513b78765f64d437faa1d015ad /src/net
parentef7ed37e3ebc6f038e13f0157e8c46d1c2df76a8 (diff)
Fixes https://github.com/reo7sp/tgbot-cpp/issues/13 for boost. Changed timeout to 20s compared to issue. Works at least for me.
Diffstat (limited to 'src/net')
-rw-r--r--src/net/BoostHttpOnlySslClient.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/net/BoostHttpOnlySslClient.cpp b/src/net/BoostHttpOnlySslClient.cpp
index 301d0c8..6e59649 100644
--- a/src/net/BoostHttpOnlySslClient.cpp
+++ b/src/net/BoostHttpOnlySslClient.cpp
@@ -48,6 +48,32 @@ string BoostHttpOnlySslClient::makeRequest(const Url& url, const vector<HttpReqA
string requestText = _httpParser.generateRequest(url, args, false);
write(socket, buffer(requestText.c_str(), requestText.length()));
+ fd_set fileDescriptorSet;
+ struct timeval timeStruct;
+
+ // set the timeout to 20 seconds
+ timeStruct.tv_sec = 20;
+ timeStruct.tv_usec = 0;
+ FD_ZERO(&fileDescriptorSet);
+
+ // We'll need to get the underlying native socket for this select call, in order
+ // to add a simple timeout on the read:
+
+ int nativeSocket = socket.lowest_layer().native_handle();
+
+ FD_SET(nativeSocket,&fileDescriptorSet);
+ select(nativeSocket+1,&fileDescriptorSet,NULL,NULL,&timeStruct);
+
+ if(!FD_ISSET(nativeSocket,&fileDescriptorSet)){ // timeout
+
+ std::string sMsg("TIMEOUT on read client data. Client IP: ");
+
+ sMsg.append(socket.next_layer().remote_endpoint().address().to_string());
+ _ioService.reset();
+
+ throw std::exception();
+ }
+
string response;
#ifdef TGBOT_CHANGE_READ_BUFFER_SIZE