Loading src/crypto/tls.cpp +18 −2 Changes for src/crypto/tls.cpp: 18 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -2893,10 +2893,26 @@ namespace netplus { throw e; } if (inner_type == 0x16) { rx_handshake_buf.insert(rx_handshake_buf.end(), plain.begin(), plain.end()); if (inner_type == 0x15) { // Alert record NetException e; if (plain.size() >= 2) { e[NetException::Error] << "tls13: received alert level=" << int(plain[0]) << " desc=" << int(plain[1]); } else { e[NetException::Error] << "tls13: received alert (malformed)"; } throw e; } if (inner_type != 0x16) { NetException e; e[NetException::Error] << "tls13: expected handshake inner type, got 0x" << std::hex << int(inner_type); throw e; } rx_handshake_buf.insert(rx_handshake_buf.end(), plain.begin(), plain.end()); return plain; } Loading src/event/epoll.cpp +43 −1 Changes for src/event/epoll.cpp: 43 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -76,7 +76,7 @@ namespace netplus { pollapi(eventapi* evcon, int timeout) : evconnection(evcon), _Timeout(timeout) {} virtual ~pollapi() = default; enum EventHandlerStatus { EVWAIT=0, EVIN=1, EVOUT=2, EVUP=3, EVERR=4, EVCON=5 }; enum EventHandlerStatus { EVWAIT=0, EVIN=1, EVOUT=2, EVUP=3, EVERR=4, EVCON=-1 }; virtual void initEventHandler()=0; virtual const char* getpolltype()=0; Loading Loading @@ -270,6 +270,15 @@ namespace netplus { evconnection->ConnectEvent(*ccon, tid, args); // If ConnectEvent queued data (e.g. HTTP/2 SETTINGS), // re-arm with EPOLLOUT so it gets flushed immediately. if (!ccon->SendData.empty() || ccon->csock->hasPendingWrite()) { epoll_event ev{}; ev.events = EPOLLIN | EPOLLOUT | EPOLLRDHUP | EPOLLONESHOT; ev.data.fd = fd; epoll_ctl(_pollFD, EPOLL_CTL_MOD, fd, &ev); } } catch (NetException& e) { if (e.getErrorType() == NetException::Note) return; Loading Loading @@ -349,6 +358,28 @@ namespace netplus { return; } // Post-handshake: if the socket has a framing // callback, invoke it with stream_id=0 to produce // initial connection data (e.g. HTTP/2 SETTINGS). // This breaks the deadlock where the browser waits // for SETTINGS and the server waits for the browser. if (auto *sslsock = dynamic_cast<ssl*>(c->csock.get())) { const auto &fcb = sslsock->getFramingCallback(); std::cerr << "[EPOLL] handshake done, alpn=\"" << sslsock->getSelectedAlpn() << "\" hasFCB=" << (bool)fcb << " sendData.empty=" << c->SendData.empty() << " fd=" << fd << std::endl; if (fcb && c->SendData.empty()) { std::string init = fcb(sslsock->getSelectedAlpn(), 0, "", ""); std::cerr << "[EPOLL] framing callback returned " << init.size() << " bytes" << std::endl; if (!init.empty()) { c->SendData.append(init.data(), init.size()); } } } // Step 3: Application data (handshake done) // Drain all available TLS records to avoid stalling // when multiple records arrive in a single TCP segment. Loading @@ -371,10 +402,14 @@ namespace netplus { if (!wouldBlock && rcv == 0) { // True EOF — peer closed the connection std::cerr << "[EPOLL] Step3: recvData returned 0 (EOF) fd=" << fd << std::endl; needClose = true; } else if (rcv > 0) { std::cerr << "[EPOLL] Step3: received " << rcv << " app bytes fd=" << fd << std::endl; c->RecvData.append(buf.data.buf, rcv); evconnection->RequestEvent(*c, tid, args); } else if (wouldBlock) { std::cerr << "[EPOLL] Step3: wouldBlock fd=" << fd << std::endl; } // Continue only if there are more buffered records Loading @@ -386,6 +421,10 @@ namespace netplus { // Always attempt to send if there is data queued // (browsers require the server's HTTP/2 SETTINGS before // sending their request, so we must not wait for EPOLLOUT) std::cerr << "[EPOLL] Step4 check: SendData=" << c->SendData.size() << " pendingWrite=" << c->csock->hasPendingWrite() << " needClose=" << needClose << " fd=" << fd << std::endl; if ((!c->SendData.empty() || c->csock->hasPendingWrite()) && !needClose) { if (c->csock->hasPendingWrite()) { try { Loading Loading @@ -430,6 +469,9 @@ namespace netplus { } } catch (NetException& e) { std::cerr << "[EPOLL] exception: " << e.what() << " type=" << e.getErrorType() << " fd=" << fd << std::endl; if (e.getErrorType() == NetException::Note) { int ev = EPOLLIN | EPOLLRDHUP | EPOLLONESHOT; if (c->csock->hasPendingWrite() || !c->SendData.empty()) Loading Loading
src/crypto/tls.cpp +18 −2 Changes for src/crypto/tls.cpp: 18 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -2893,10 +2893,26 @@ namespace netplus { throw e; } if (inner_type == 0x16) { rx_handshake_buf.insert(rx_handshake_buf.end(), plain.begin(), plain.end()); if (inner_type == 0x15) { // Alert record NetException e; if (plain.size() >= 2) { e[NetException::Error] << "tls13: received alert level=" << int(plain[0]) << " desc=" << int(plain[1]); } else { e[NetException::Error] << "tls13: received alert (malformed)"; } throw e; } if (inner_type != 0x16) { NetException e; e[NetException::Error] << "tls13: expected handshake inner type, got 0x" << std::hex << int(inner_type); throw e; } rx_handshake_buf.insert(rx_handshake_buf.end(), plain.begin(), plain.end()); return plain; } Loading
src/event/epoll.cpp +43 −1 Changes for src/event/epoll.cpp: 43 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -76,7 +76,7 @@ namespace netplus { pollapi(eventapi* evcon, int timeout) : evconnection(evcon), _Timeout(timeout) {} virtual ~pollapi() = default; enum EventHandlerStatus { EVWAIT=0, EVIN=1, EVOUT=2, EVUP=3, EVERR=4, EVCON=5 }; enum EventHandlerStatus { EVWAIT=0, EVIN=1, EVOUT=2, EVUP=3, EVERR=4, EVCON=-1 }; virtual void initEventHandler()=0; virtual const char* getpolltype()=0; Loading Loading @@ -270,6 +270,15 @@ namespace netplus { evconnection->ConnectEvent(*ccon, tid, args); // If ConnectEvent queued data (e.g. HTTP/2 SETTINGS), // re-arm with EPOLLOUT so it gets flushed immediately. if (!ccon->SendData.empty() || ccon->csock->hasPendingWrite()) { epoll_event ev{}; ev.events = EPOLLIN | EPOLLOUT | EPOLLRDHUP | EPOLLONESHOT; ev.data.fd = fd; epoll_ctl(_pollFD, EPOLL_CTL_MOD, fd, &ev); } } catch (NetException& e) { if (e.getErrorType() == NetException::Note) return; Loading Loading @@ -349,6 +358,28 @@ namespace netplus { return; } // Post-handshake: if the socket has a framing // callback, invoke it with stream_id=0 to produce // initial connection data (e.g. HTTP/2 SETTINGS). // This breaks the deadlock where the browser waits // for SETTINGS and the server waits for the browser. if (auto *sslsock = dynamic_cast<ssl*>(c->csock.get())) { const auto &fcb = sslsock->getFramingCallback(); std::cerr << "[EPOLL] handshake done, alpn=\"" << sslsock->getSelectedAlpn() << "\" hasFCB=" << (bool)fcb << " sendData.empty=" << c->SendData.empty() << " fd=" << fd << std::endl; if (fcb && c->SendData.empty()) { std::string init = fcb(sslsock->getSelectedAlpn(), 0, "", ""); std::cerr << "[EPOLL] framing callback returned " << init.size() << " bytes" << std::endl; if (!init.empty()) { c->SendData.append(init.data(), init.size()); } } } // Step 3: Application data (handshake done) // Drain all available TLS records to avoid stalling // when multiple records arrive in a single TCP segment. Loading @@ -371,10 +402,14 @@ namespace netplus { if (!wouldBlock && rcv == 0) { // True EOF — peer closed the connection std::cerr << "[EPOLL] Step3: recvData returned 0 (EOF) fd=" << fd << std::endl; needClose = true; } else if (rcv > 0) { std::cerr << "[EPOLL] Step3: received " << rcv << " app bytes fd=" << fd << std::endl; c->RecvData.append(buf.data.buf, rcv); evconnection->RequestEvent(*c, tid, args); } else if (wouldBlock) { std::cerr << "[EPOLL] Step3: wouldBlock fd=" << fd << std::endl; } // Continue only if there are more buffered records Loading @@ -386,6 +421,10 @@ namespace netplus { // Always attempt to send if there is data queued // (browsers require the server's HTTP/2 SETTINGS before // sending their request, so we must not wait for EPOLLOUT) std::cerr << "[EPOLL] Step4 check: SendData=" << c->SendData.size() << " pendingWrite=" << c->csock->hasPendingWrite() << " needClose=" << needClose << " fd=" << fd << std::endl; if ((!c->SendData.empty() || c->csock->hasPendingWrite()) && !needClose) { if (c->csock->hasPendingWrite()) { try { Loading Loading @@ -430,6 +469,9 @@ namespace netplus { } } catch (NetException& e) { std::cerr << "[EPOLL] exception: " << e.what() << " type=" << e.getErrorType() << " fd=" << fd << std::endl; if (e.getErrorType() == NetException::Note) { int ev = EPOLLIN | EPOLLRDHUP | EPOLLONESHOT; if (c->csock->hasPendingWrite() || !c->SendData.empty()) Loading