5

OpenSSL 1.0.1e でブースト 1.54.0 を使用しています。

SSL 接続オブジェクトを時々閉じると、async_shutdown()の完了ハンドラが呼び出されないことがわかります。

デバッグした後、これは async_write() よりも優れている場合に発生することがわかりました。

SSL async_shutdown() は SSL Alert(Closing) を送信する必要があるため、ここでは 2 つの書き込みがあります。複数の async_write() が禁止されていることは知っています。

状況をどのように処理すればよいですか?SSL async_shutdown() を呼び出す前に、async_write() の完了を待つ必要がありますか?

編集:これによると未処理のすべての非同期操作をキャンセルするには、基になる TCP ソケットでおそらく cancel() が必要です。それが正しいか?

編集async_ API を常に使用している場合、電話できますshutdown()か、または電話する必要がありますasync_shutdown()か?

4

1 に答える 1

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();
   }
}
于 2013-08-22T16:09:59.530 に答える