2013-08-22 8 views
5

को बढ़ावा नहीं देता है, मैं ओपनएसएसएल 1.0.1e के साथ बूस्ट 1.54.0 का उपयोग कर रहा हूं।एसएसएल async_shutdown समापन हैडलर को

समय-समय पर एसएसएल कनेक्शन ऑब्जेक्ट को बंद करते समय मुझे लगता है कि async_shutdown() के समापन हैंडलर को नहीं कहा जाता है।

डीबगिंग के बाद मुझे पता चला कि यह तब होता है जब async_write() बाहर निकलता है।

एसएसएल async_shutdown() एसएसएल अलर्ट (समापन) भेजना चाहिए, इस प्रकार हमारे पास 2 लिखते हैं। मुझे पता है कि एकाधिक async_write() के वर्जित हैं।

मुझे स्थिति को कैसे संभालना चाहिए? क्या मुझे SSL async_shutdown() को कॉल करने से पहले async_write() पूर्णता की प्रतीक्षा करनी चाहिए?

संपादित: this के अनुसार मैं शायद() सभी बकाया async-कार्यवाही रद्द करना रद्द अंतर्निहित TCP सॉकेट पर की जरूरत है। क्या यह सही है?

संपादित मैं हर समय async_ एपीआई का उपयोग कर रहा है, मैं shutdown() कॉल कर सकते हैं या मैं async_shutdown() कॉल करना होगा?

उत्तर

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

समस्या क्या थी और वास्तव में आपके कोड में क्या ठीक हुआ? क्या यह pSocket-> next_layer() है। रद्द करें()? – dimba

+0

यह कुछ समय पहले था, लेकिन मुझे विश्वास है कि जब मैं रद्द विधि कहलाता हूं तो समस्या दूर हो गई। मेरे पास एक बहु-थ्रेडिंग समस्या भी थी, इसलिए मैंने कोड को थ्रेडेड किया। –

+0

अभी भी काम नहीं कर रहा है। – dimba

संबंधित मुद्दे