/// @param ec Error code.
void connectHandler(const boost::system::error_code& ec) {
if (ec) {
- ADD_FAILURE() << "error occurred while connecting: "
- << ec.message();
- io_service_.stop();
+ // One would expect that async_connect wouldn't return EINPROGRESS
+ // error code, but simply wait for the connection to get
+ // established before the handler is invoked. It turns out, however,
+ // that on some OSes the connect handler may receive this error code
+ // which doesn't neccessarily indicate a problem. Making an attempt
+ // to write and read from this socket will typically succeed. So,
+ // we ignore this error.
+ if (ec.value() != boost::asio::error::in_progress) {
+ ADD_FAILURE() << "error occurred while connecting: "
+ << ec.message();
+ io_service_.stop();
+ }
}
}
#include <boost/shared_ptr.hpp>
#include <gtest/gtest.h>
-#include <string>
+#include <algorithm>
#include <arpa/inet.h>
+#include <cstddef>
+#include <cstdlib>
+#include <errno.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
-#include <algorithm>
-#include <cstdlib>
-#include <cstddef>
+#include <string>
#include <vector>
using namespace boost::asio;
EXPECT_EQ(0, server_cb.getCode());
EXPECT_EQ(TCPCallback::OPEN, client_cb.called());
- EXPECT_EQ(0, client_cb.getCode());
+
+ // On some operating system the async_connect may return EINPROGRESS.
+ // This doesn't neccessarily indicate an error. In most cases trying
+ // to asynchrouonsly write and read from the socket would work just
+ // fine.
+ if ((client_cb.getCode()) != 0 && (client_cb.getCode() != EINPROGRESS)) {
+ ADD_FAILURE() << "expected error code of 0 or " << EINPROGRESS
+ << " as a result of async_connect, got " << client_cb.getCode();
+ }
// Step 2. Get the client to write to the server asynchronously. The
// server will loop reading the data synchronously.
tcp::endpoint endpoint(address::from_string(SERVER_ADDRESS),
SERVER_PORT);
socket_.async_connect(endpoint,
- [this, request](const boost::system::error_code& ec) {
+ [this, request](const boost::system::error_code& ec) {
if (ec) {
- ADD_FAILURE() << "error occurred while connecting: "
- << ec.message();
- io_service_.stop();
+ // One would expect that async_connect wouldn't return
+ // EINPROGRESS error code, but simply wait for the connection
+ // to get established before the handler is invoked. It turns out,
+ // however, that on some OSes the connect handler may receive this
+ // error code which doesn't neccessarily indicate a problem.
+ // Making an attempt to write and read from this socket will
+ // typically succeed. So, we ignore this error.
+ if (ec.value() != boost::asio::error::in_progress) {
+ ADD_FAILURE() << "error occurred while connecting: "
+ << ec.message();
+ io_service_.stop();
+ return;
+ }
}
sendRequest(request);
});