Parcourir la source

Merge branch '40-connection-timeouts' into 'develop'

Resolve "Boost connection timeout adjustment"

Closes #40

See merge request tobias.wach/ccats!55
Serdyukov, Denys il y a 4 ans
Parent
commit
3f324748b7
2 fichiers modifiés avec 13 ajouts et 2 suppressions
  1. 2 1
      cli/include/ioman.h
  2. 11 1
      cli/src/ioman.cpp

+ 2 - 1
cli/include/ioman.h

@@ -50,6 +50,8 @@ public:
 	std::vector<std::string> localinput;
 	std::condition_variable localcv;
 
+	boost::system::error_code errcode;
+
 protected:
 	/**
 	 * Prompt messages for readline prompt
@@ -72,7 +74,6 @@ protected:
 	virtual void handleInCmdResponse(CmdMan::CmdRet cmdret);
 	virtual void handleOutCmdResponse(CmdMan::CmdRet cmdret, vector<string> &toput);
 
-	boost::system::error_code errcode;
 	tcp::socket *tcpsock;
 	boost::asio::ssl::stream<tcp::socket &> *sslsock;
 	bool usessl;

+ 11 - 1
cli/src/ioman.cpp

@@ -146,6 +146,9 @@ vector<string> IoMan::tokenizeInput(string in) {
 	return args;
 }
 
+// callback for async connect, used to get timeout
+void connect_async_handler(const boost::system::error_code &error) { gIOMAN->errcode = error; }
+
 bool IoMan::connect() {
 	tcp::endpoint *ep = NULL;
 	address addr;
@@ -161,7 +164,14 @@ bool IoMan::connect() {
 		// establish connection
 		printMessage(string(__PRETTY_FUNCTION__) + string(" connecting to ") + ipstring, debug);
 		ep = new tcp::endpoint(addr, port);
-		tcpsock->connect(*ep, errcode);
+		// connect never returns would_block, initialize errcode so we can determine whats up
+		errcode = boost::asio::error::would_block;
+
+		tcpsock->async_connect(*ep, &connect_async_handler);
+
+		ios.run_for(std::chrono::seconds(5));
+
+		//~ tcpsock->connect(*ep, errcode);
 		if (errcode) {
 			root["error"] = errcode.message();
 			connected = false;