2013-08-22 7 views
5

Ich verwende Boost 1.54.0 mit OpenSSL 1.0.1e.Boost SSL async_shutdown Abschluss Hadler nicht

Beim Schließen des SSL-Verbindungsobjekts von Zeit zu Zeit sehe ich, dass Abschlusshandler async_shutdown() nicht aufgerufen wird.

Nach dem Debugging habe ich herausgefunden, dass dies passiert, wenn async_write() auftaucht.

SSL async_shutdown() sollte SSL Alert (Closing) senden, daher haben wir hier 2 Schreibvorgänge. Ich weiß, dass mehrere async_write() sind verboten.

Wie soll ich mit der Situation umgehen? Sollte ich auf Async_write() Abschluss warten, bevor Sie SSL async_shutdown() aufrufen?

BEARBEITEN: Nach this brauche ich wahrscheinlich cancel() auf zugrunde liegenden TCP-Socket, um alle ausstehenden async-Operationen abzubrechen. Ist es richtig?

EDIT Wenn ich die ganze Zeit async_ API bin, kann ich anrufen shutdown() oder muss ich async_shutdown() nennen?

Antwort

2

So handhabe ich das Herunterfahren. Davor hatte ich Probleme beim Herunterfahren. Dieser Code schließt alles sauber herunter:

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

Was war das Problem und was genau in Ihrem Code geheilt? Ist es pSocket-> next_layer(). Abbrechen()? – dimba

+0

Das war vor einiger Zeit, aber ich glaube, dass das Problem wegging, als ich die Cancel-Methode anrief. Ich hatte auch ein Multithreading-Problem, weshalb ich den Code single threaded. –

+0

Noch nicht funktioniert. – dimba