C++ 未调用boost SSL异步\u关闭完成处理程序

C++ 未调用boost SSL异步\u关闭完成处理程序,c++,boost,boost-asio,C++,Boost,Boost Asio,我正在使用Boost1.54.0和OpenSSL 1.0.1e 在不时关闭SSL连接对象时,我看到未调用的完成处理程序 调试后,我发现,当存在多余的async_write()时,就会发生这种情况 SSL async_shutdown()应该发送SSL警报(关闭),因此我们这里有两个写入。 我知道禁止使用多个async_write() 我该如何处理这种情况? 在调用SSL async_shutdown()之前,是否应该等待async_write()完成 编辑:根据所述,我可能需要在底层TCP套接字

我正在使用Boost1.54.0和OpenSSL 1.0.1e

在不时关闭SSL连接对象时,我看到未调用的完成处理程序

调试后,我发现,当存在多余的async_write()时,就会发生这种情况

SSL async_shutdown()应该发送SSL警报(关闭),因此我们这里有两个写入。 我知道禁止使用多个async_write()

我该如何处理这种情况? 在调用SSL async_shutdown()之前,是否应该等待async_write()完成

编辑:根据所述,我可能需要在底层TCP套接字上使用cancel()来取消所有未完成的异步操作。对吗


编辑如果我一直在使用异步API,我可以调用
shutdown()
还是必须调用
async\u 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();
   }
}
void SSLSocket::Stop()
{
//此方法调用套接字上的shutdown方法以停止可能正在进行的读取或写入。如果未执行此操作,则将引发异常
//当需要删除此对象时。
//
boost::system::error_code EC;
尝试
{
//这个方法也可以从处理程序中调用。因此,一旦设置了关闭标志,就不要再执行相同的代码。
//
LockCode->Acquire();//单线程执行代码。
如果(关闭)
返回;
关机=真;
pSocket->next_layer().取消();
pSocket->shutdown(EC);
国际单项体育联合会(欧共体)
{
细流ss;
ss释放();
删除锁码;
锁码=0;
}
捕获(标准::异常&e)
{
细流ss;

ss问题是什么?你的代码中到底是什么解决了它?是pSocket->next_layer().cancel()?这是很久以前的事了,但我相信当我调用cancel方法时,问题就消失了。我还遇到了多线程问题,这就是为什么我对代码进行单线程处理。