Skip to content

Commit 3c8b87f

Browse files
committed
Add blocking connect method
1 parent cc45572 commit 3c8b87f

File tree

4 files changed

+10
-0
lines changed

4 files changed

+10
-0
lines changed

include/f1x/aasdk/TCP/ITCPWrapper.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class ITCPWrapper
4141
virtual void asyncRead(boost::asio::ip::tcp::socket& socket, common::DataBuffer buffer, Handler handler) = 0;
4242
virtual void close(boost::asio::ip::tcp::socket& socket) = 0;
4343
virtual void asyncConnect(boost::asio::ip::tcp::socket& socket, const std::string& hostname, uint16_t port, ConnectHandler handler) = 0;
44+
virtual boost::system::error_code connect(boost::asio::ip::tcp::socket& socket, const std::string& hostname, uint16_t port) = 0;
4445
};
4546

4647
}

include/f1x/aasdk/TCP/TCPWrapper.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class TCPWrapper: public ITCPWrapper
3434
void asyncRead(boost::asio::ip::tcp::socket& socket, common::DataBuffer buffer, Handler handler) override;
3535
void close(boost::asio::ip::tcp::socket& socket) override;
3636
void asyncConnect(boost::asio::ip::tcp::socket& socket, const std::string& hostname, uint16_t port, ConnectHandler handler) override;
37+
boost::system::error_code connect(boost::asio::ip::tcp::socket& socket, const std::string& hostname, uint16_t port) override;
3738
};
3839

3940
}

include_ut/f1x/aasdk/TCP/UT/TCPWrapper.mock.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class TCPWrapperMock: public ITCPWrapper
3737
MOCK_METHOD3(asyncRead, void(boost::asio::ip::tcp::socket& socket, common::DataBuffer buffer, Handler handler));
3838
MOCK_METHOD1(close, void(boost::asio::ip::tcp::socket& socket));
3939
MOCK_METHOD4(asyncConnect, void(boost::asio::ip::tcp::socket& socket, const std::string& hostname, uint16_t port, ConnectHandler handler));
40+
MOCK_METHOD3(connect, boost::system::error_code(boost::asio::ip::tcp::socket& socket, const std::string& hostname, uint16_t port));
4041
};
4142

4243
}

src/TCP/TCPWrapper.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ void TCPWrapper::asyncConnect(boost::asio::ip::tcp::socket& socket, const std::s
4848
socket.async_connect(boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string(hostname), port), std::move(handler));
4949
}
5050

51+
boost::system::error_code TCPWrapper::connect(boost::asio::ip::tcp::socket& socket, const std::string& hostname, uint16_t port)
52+
{
53+
boost::system::error_code ec;
54+
socket.connect(boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string(hostname), port), ec);
55+
return ec;
56+
}
57+
5158
}
5259
}
5360
}

0 commit comments

Comments
 (0)