未调用boost SSL async_shutdown完成处理程序



我使用的是带有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()完成吗?

EDIT:根据这一点,我可能需要底层TCP套接字上的cancel()来取消所有未完成的异步操作。这是正确的吗?

编辑如果我一直在使用async_ API,我可以调用shutdown()还是必须调用async_shutdown()

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

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();
   }
}

最新更新