Loading src/event/iocp.cpp +71 −2 Original line number Diff line number Diff line Loading @@ -599,10 +599,79 @@ namespace netplus { else if (buf->operation == OP_WRITE) { // For SSL, the send encrypts all pending data at once // So we clear SendData entirely on completion if (owner->csock->getSocketType() == (int)sockettype::SSL) { bool isSSL = (owner->csock->getSocketType() == (int)sockettype::SSL); if (isSSL) { // SSL: all data was encrypted and sent owner->SendData.clear(); owner->SendOff = 0; // If handshake not done, continue handshake after send completes if (!owner->csock->getHandshakeDone()) { ssl* sslSock = static_cast<ssl*>(owner->csock.get()); std::cerr << "[IOCP] Write completed during handshake, continuing handshake..." << std::endl; // Delete the send buffer first delete buf; buf = nullptr; try { owner->csock->handshake_after_accept(); std::cerr << "[IOCP] handshake_after_accept returned, handshakeDone=" << owner->csock->getHandshakeDone() << std::endl; // If there's more data to send, flush it if (owner->csock->hasPendingWrite()) { std::cerr << "[IOCP] More data to send, flushing..." << std::endl; sslSock->flush_out(); buffer* sendBuf = sslSock->getIocpBuf(); if (sendBuf) { sendBuf->owner = owner; } } } catch (NetException& e) { if (e.getErrorType() == NetException::Note) { std::cerr << "[IOCP] Handshake needs more data, posting recv" << std::endl; // Need more data - but first check if we have data to send if (owner->csock->hasPendingWrite()) { try { sslSock->flush_out(); buffer* sendBuf = sslSock->getIocpBuf(); if (sendBuf) { sendBuf->owner = owner; } } catch (...) {} } // Post recv for more handshake data try { post_recv(st, *owner); } catch (...) {} continue; } // Real error std::cerr << "[IOCP] Handshake error after write: " << e.what() << std::endl; ev->DisconnectEvent(*owner, tid, 0); remove_con(st, cs); try { owner->csock->close(); } catch (...) {} continue; } // Handshake complete or needs more data if (!owner->csock->getHandshakeDone()) { // Post recv for more handshake data try { post_recv(st, *owner); } catch (...) {} } else { std::cerr << "[IOCP] Handshake complete after write!" << std::endl; // Post recv for application data try { post_recv(st, *owner); } catch (...) {} } owner->WritePending.store(false); continue; } } else { // Plain TCP: track bytes sent owner->SendOff += (size_t)bytes; Loading @@ -629,7 +698,7 @@ namespace netplus { } // send buffer was dynamically allocated delete buf; if (buf) delete buf; } } } Loading Loading
src/event/iocp.cpp +71 −2 Original line number Diff line number Diff line Loading @@ -599,10 +599,79 @@ namespace netplus { else if (buf->operation == OP_WRITE) { // For SSL, the send encrypts all pending data at once // So we clear SendData entirely on completion if (owner->csock->getSocketType() == (int)sockettype::SSL) { bool isSSL = (owner->csock->getSocketType() == (int)sockettype::SSL); if (isSSL) { // SSL: all data was encrypted and sent owner->SendData.clear(); owner->SendOff = 0; // If handshake not done, continue handshake after send completes if (!owner->csock->getHandshakeDone()) { ssl* sslSock = static_cast<ssl*>(owner->csock.get()); std::cerr << "[IOCP] Write completed during handshake, continuing handshake..." << std::endl; // Delete the send buffer first delete buf; buf = nullptr; try { owner->csock->handshake_after_accept(); std::cerr << "[IOCP] handshake_after_accept returned, handshakeDone=" << owner->csock->getHandshakeDone() << std::endl; // If there's more data to send, flush it if (owner->csock->hasPendingWrite()) { std::cerr << "[IOCP] More data to send, flushing..." << std::endl; sslSock->flush_out(); buffer* sendBuf = sslSock->getIocpBuf(); if (sendBuf) { sendBuf->owner = owner; } } } catch (NetException& e) { if (e.getErrorType() == NetException::Note) { std::cerr << "[IOCP] Handshake needs more data, posting recv" << std::endl; // Need more data - but first check if we have data to send if (owner->csock->hasPendingWrite()) { try { sslSock->flush_out(); buffer* sendBuf = sslSock->getIocpBuf(); if (sendBuf) { sendBuf->owner = owner; } } catch (...) {} } // Post recv for more handshake data try { post_recv(st, *owner); } catch (...) {} continue; } // Real error std::cerr << "[IOCP] Handshake error after write: " << e.what() << std::endl; ev->DisconnectEvent(*owner, tid, 0); remove_con(st, cs); try { owner->csock->close(); } catch (...) {} continue; } // Handshake complete or needs more data if (!owner->csock->getHandshakeDone()) { // Post recv for more handshake data try { post_recv(st, *owner); } catch (...) {} } else { std::cerr << "[IOCP] Handshake complete after write!" << std::endl; // Post recv for application data try { post_recv(st, *owner); } catch (...) {} } owner->WritePending.store(false); continue; } } else { // Plain TCP: track bytes sent owner->SendOff += (size_t)bytes; Loading @@ -629,7 +698,7 @@ namespace netplus { } // send buffer was dynamically allocated delete buf; if (buf) delete buf; } } } Loading