提升未调用的SSL async_shutdown完成处理程序

dim*_*mba 5 c++ boost boost-asio

我在OpenSSL 1.0.1e上使用boost 1.54.0.

当我不时关闭SSL连接对象时,我看到没有调用async_shutdown()的完成处理程序.

经过调试后我发现,当出现async_write()时会发生这种情况.

SSL async_shutdown()应该发送SSL警报(关闭),因此我们在这里有2次写入.我知道禁止多个async_write().

我该如何应对这种情况?我应该在调用SSL async_shutdown()之前等待async_write()完成吗?

编辑:根据这一点,我可能需要在底层TCP套接字上取消()取消所有未完成的异步操作.这是对的吗?

编辑如果我一直在使用async_ API,我可以打电话shutdown()或者我必须打电话async_shutdown()吗?

Bob*_*yan 2

这就是我处理关闭的方式。在此之前,我在关闭时遇到了问题。这段代码彻底关闭了一切:

void SSLSocket::Stop()
{
   // This method calls the shutdown method on the socket in order to stop reads or writes that might be going on.  If this is not done, then an exception will be thrown
   // when it comes time to delete this object.
   //
   boost::system::error_code EC;
   try
   {
      // This method can be called from the handler as well.  So once the ShuttingDown flag is set, don't go throught the same code again.
      //
      LockCode->Acquire(); // Single thread the code.
      if (ShuttingDown)
         return;
      ShuttingDown = true;
      pSocket->next_layer().cancel();
      pSocket->shutdown(EC);
      if (EC)
      {
         stringstream ss;
         ss << "SSLSocket::Stop: socket shutdown error - " << EC.message() << ".\n";
         // Log.LogString(ss.str(), LogError); // Usually get this - probably not an error.
      }
      else
      {
         pSocket->next_layer().close();
      }
      delete pSocket;
      pSocket = 0;
      ReqAlive = false;
      SetEvent(hEvent);
      IOService->stop();
      LobbySocketOpen = false;
      WorkerThreads.join_all();
      LockCode->Release();
      delete LockCode;
      LockCode = 0;
   }
   catch (std::exception& e)
   {
      stringstream ss;
      ss << "SSLSocket::Stop: threw an error - " << e.what() << ".\n";
      Log.LogString(ss.str(), LogError);
      Stop();
   }
}
Run Code Online (Sandbox Code Playgroud)