I have a client-server application where the connection is performed via SSL.
and uses boost::asio
.
The relevant client code to establish a connection is
Client::Client(boost::asio::io_service& io_service,
boost::asio::ssl::context& context,
boost::asio::ip::tcp::resolver::iterator endpoint_iterator) : AbstractNetworkOps(io_service, context)
{
socket_.set_verify_mode(boost::asio::ssl::verify_peer);
socket_.set_verify_callback(boost::bind(&Client::verify_certificate, this, _1, _2));
this->endpoint_iterator = endpoint_iterator;
}
Client::~Client() {}
void Client::startConnection() {
Log("Start connecting...");
boost::system::error_code ec;
boost::asio::connect(socket_.lowest_layer(), this->endpoint_iterator, ec);
handle_connect(ec);
}
After a certain amount of message exchanges, the client should close the connection for which I call the following method
void AbstractNetworkOps::saveCloseSocket() {
boost::system::error_code ec;
socket_.lowest_layer().cancel();
socket_.shutdown(ec);
if (ec) {
stringstream ss;
Log("Socket shutdown error: %s", ec.message());
} else {
socket_.lowest_layer().close();
}
}
The problem here is, that the call to socket_.shutdown(ec)
blocks somehow and does not return!?
Is this not the correct way of doing it?
P.S. The application is quite large, that's why I cannot post the entire code here but please let me know if some important pieces are missing, so I can update it