Loading src/event/epoll.cpp +2 −4 Changes for src/event/epoll.cpp: 2 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -105,11 +105,9 @@ namespace netplus { int next = EPOLLRDHUP | EPOLLIN | EPOLLONESHOT; // Check if we have pending writes or buffered data // Check if we have pending writes if (_con->SendData.pos < _con->SendData.size() || _con->csock->hasPendingWrite()) next |= EPOLLOUT; if (_con->csock->hasBufferedData()) next |= EPOLLOUT; try { _pptr->setpollEventsFd(_fd, next); Loading Loading @@ -234,7 +232,7 @@ namespace netplus { if (!ccon || !ccon->csock) return; register_connection: ccon->csock->setNonBlock(); // accept4(SOCK_NONBLOCK) already sets non-blocking in tcp::accept int fd = ccon->csock->fd(); // insert into connection map Loading src/posix/tcp.cpp +12 −12 Changes for src/posix/tcp.cpp: 12 added lines, 12 removed lines. Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <arpa/inet.h> #include <fcntl.h> #include <sys/un.h> #include <netinet/tcp.h> namespace netplus { Loading Loading @@ -141,19 +142,11 @@ tcp::tcp(const std::string& addr, int port, int maxconnections, int sockopts) } void tcp::bind() { std::cerr << "[TCP] bind() called on socket FD=" << _Socket << std::endl; std::cerr.flush(); if (::bind(_Socket, reinterpret_cast<sockaddr*>(&_Addr), _AddrLen) < 0) { std::cerr << "[TCP] bind() FAILED with errno=" << errno << ": " << strerror(errno) << std::endl; std::cerr.flush(); NetException e; e[NetException::Error] << "tcp::bind failed: " << strerror(errno); throw e; } std::cerr << "[TCP] bind() succeeded" << std::endl; std::cerr.flush(); } void tcp::listen() { Loading Loading @@ -185,7 +178,9 @@ void tcp::accept(std::unique_ptr<socket>& csock, bool nonblock) { sockaddr_storage peer{}; socklen_t peerLen = sizeof(peer); SOCKET cfd = ::accept(_Socket, reinterpret_cast<sockaddr*>(&peer), &peerLen); // Use accept4 with SOCK_NONBLOCK to avoid extra fcntl syscall int flags = nonblock ? SOCK_NONBLOCK : 0; SOCKET cfd = ::accept4(_Socket, reinterpret_cast<sockaddr*>(&peer), &peerLen, flags); if (cfd < 0) { NetException e; int et = (errno == EAGAIN || errno == EWOULDBLOCK) ? NetException::Note : NetException::Error; Loading @@ -197,13 +192,14 @@ void tcp::accept(std::unique_ptr<socket>& csock, bool nonblock) { csock->_Addr = peer; csock->_AddrLen = peerLen; if (nonblock) csock->setNonBlock(); // Disable Nagle's algorithm — reduces latency for small HTTP frames int one = 1; ::setsockopt(cfd, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one)); } size_t tcp::sendData(buffer& data, int flags) { const char* p = data.ptr ? data.data.ptr : data.data.buf; ssize_t s = ::send(_Socket, p, data.size, flags); ssize_t s = ::send(_Socket, p, data.size, flags | MSG_NOSIGNAL); if (s < 0) { if (errno == EAGAIN || errno == EWOULDBLOCK) { NetException e; Loading Loading @@ -305,6 +301,10 @@ void netplus::tcp::connect(const std::string& addr, int port, bool nonblock) // ✅ connected immediately setAddrFromAI(rp); // Disable Nagle's algorithm for low-latency HTTP int one = 1; ::setsockopt(_Socket, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one)); ::freeaddrinfo(result); return; } Loading src/quic.cpp +242 −131 File changed.Preview size limit exceeded, changes collapsed. Show changes src/socket.h +29 −1 Changes for src/socket.h: 29 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -806,7 +806,7 @@ namespace netplus { std::vector<uint8_t> _recv_buffer; std::deque<std::vector<uint8_t>> _send_queue; // AES instances for each encryption level // AES instances for each encryption level (GCM encrypt/decrypt) std::unique_ptr<aes> _aes_initial_send; std::unique_ptr<aes> _aes_initial_recv; std::unique_ptr<aes> _aes_hs_send; Loading @@ -814,6 +814,14 @@ namespace netplus { std::unique_ptr<aes> _aes_app_send; std::unique_ptr<aes> _aes_app_recv; // Cached AES instances for header protection (ECB, reused across packets) std::unique_ptr<aes> _aes_hp_initial_send; std::unique_ptr<aes> _aes_hp_initial_recv; std::unique_ptr<aes> _aes_hp_hs_send; std::unique_ptr<aes> _aes_hp_hs_recv; std::unique_ptr<aes> _aes_hp_app_send; std::unique_ptr<aes> _aes_hp_app_recv; // Certificate bundle for server mode std::map<std::string, ssl::CertificateBundle> _cert_map; ssl::CertificateBundle* _selected_cert = nullptr; Loading Loading @@ -846,6 +854,26 @@ namespace netplus { bool _handshake_timeout_triggered = false; static const int HANDSHAKE_TIMEOUT_MS = 5000; // 5 second timeout for handshake // PING keepalive: last activity timestamp & interval std::chrono::steady_clock::time_point _last_activity; static constexpr int KEEPALIVE_INTERVAL_MS = 15000; // Send PING every 15s of inactivity // Handshake retransmission: store last handshake flight for retransmit std::vector<std::vector<uint8_t>> _hs_flight_packets; // Stored for retransmit std::chrono::steady_clock::time_point _hs_last_send; int _hs_retransmit_count = 0; static constexpr int HS_RETRANSMIT_MAX = 5; static constexpr int HS_RETRANSMIT_INTERVAL_MS = 200; // Initial retransmit timer // Flow control batching: avoid sending duplicate MAX_DATA/MAX_STREAM_DATA bool _pending_max_data = false; uint64_t _pending_max_data_value = 0; std::map<uint64_t, uint64_t> _pending_max_stream_data; // ACK tracking: need to send ACK for initial/handshake levels bool _need_initial_ack = false; bool _need_handshake_ack = false; // Mutex for thread safety mutable std::mutex _quic_mutex; Loading test/quic_test.cpp +6 −0 Changes for test/quic_test.cpp: 6 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -776,10 +776,16 @@ static void runHttpsFallbackServer(std::map<std::string, netplus::ssl::Certifica }); // Configure framing callback: always HTTP/2 // stream_id == 0 → epoll post-handshake probe, return empty // (SETTINGS preface is sent by h2ProcessFrames) // stream_id > 0 → produce response for that HTTP/2 stream fallbackSock.setFramingCallback([](const std::string& alpn, uint32_t stream_id, const std::string& body, const std::string& content_type) -> std::string { if (stream_id == 0) { return ""; } return h2BuildResponse(stream_id, body, content_type); }); Loading Loading
src/event/epoll.cpp +2 −4 Changes for src/event/epoll.cpp: 2 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -105,11 +105,9 @@ namespace netplus { int next = EPOLLRDHUP | EPOLLIN | EPOLLONESHOT; // Check if we have pending writes or buffered data // Check if we have pending writes if (_con->SendData.pos < _con->SendData.size() || _con->csock->hasPendingWrite()) next |= EPOLLOUT; if (_con->csock->hasBufferedData()) next |= EPOLLOUT; try { _pptr->setpollEventsFd(_fd, next); Loading Loading @@ -234,7 +232,7 @@ namespace netplus { if (!ccon || !ccon->csock) return; register_connection: ccon->csock->setNonBlock(); // accept4(SOCK_NONBLOCK) already sets non-blocking in tcp::accept int fd = ccon->csock->fd(); // insert into connection map Loading
src/posix/tcp.cpp +12 −12 Changes for src/posix/tcp.cpp: 12 added lines, 12 removed lines. Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <arpa/inet.h> #include <fcntl.h> #include <sys/un.h> #include <netinet/tcp.h> namespace netplus { Loading Loading @@ -141,19 +142,11 @@ tcp::tcp(const std::string& addr, int port, int maxconnections, int sockopts) } void tcp::bind() { std::cerr << "[TCP] bind() called on socket FD=" << _Socket << std::endl; std::cerr.flush(); if (::bind(_Socket, reinterpret_cast<sockaddr*>(&_Addr), _AddrLen) < 0) { std::cerr << "[TCP] bind() FAILED with errno=" << errno << ": " << strerror(errno) << std::endl; std::cerr.flush(); NetException e; e[NetException::Error] << "tcp::bind failed: " << strerror(errno); throw e; } std::cerr << "[TCP] bind() succeeded" << std::endl; std::cerr.flush(); } void tcp::listen() { Loading Loading @@ -185,7 +178,9 @@ void tcp::accept(std::unique_ptr<socket>& csock, bool nonblock) { sockaddr_storage peer{}; socklen_t peerLen = sizeof(peer); SOCKET cfd = ::accept(_Socket, reinterpret_cast<sockaddr*>(&peer), &peerLen); // Use accept4 with SOCK_NONBLOCK to avoid extra fcntl syscall int flags = nonblock ? SOCK_NONBLOCK : 0; SOCKET cfd = ::accept4(_Socket, reinterpret_cast<sockaddr*>(&peer), &peerLen, flags); if (cfd < 0) { NetException e; int et = (errno == EAGAIN || errno == EWOULDBLOCK) ? NetException::Note : NetException::Error; Loading @@ -197,13 +192,14 @@ void tcp::accept(std::unique_ptr<socket>& csock, bool nonblock) { csock->_Addr = peer; csock->_AddrLen = peerLen; if (nonblock) csock->setNonBlock(); // Disable Nagle's algorithm — reduces latency for small HTTP frames int one = 1; ::setsockopt(cfd, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one)); } size_t tcp::sendData(buffer& data, int flags) { const char* p = data.ptr ? data.data.ptr : data.data.buf; ssize_t s = ::send(_Socket, p, data.size, flags); ssize_t s = ::send(_Socket, p, data.size, flags | MSG_NOSIGNAL); if (s < 0) { if (errno == EAGAIN || errno == EWOULDBLOCK) { NetException e; Loading Loading @@ -305,6 +301,10 @@ void netplus::tcp::connect(const std::string& addr, int port, bool nonblock) // ✅ connected immediately setAddrFromAI(rp); // Disable Nagle's algorithm for low-latency HTTP int one = 1; ::setsockopt(_Socket, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one)); ::freeaddrinfo(result); return; } Loading
src/socket.h +29 −1 Changes for src/socket.h: 29 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -806,7 +806,7 @@ namespace netplus { std::vector<uint8_t> _recv_buffer; std::deque<std::vector<uint8_t>> _send_queue; // AES instances for each encryption level // AES instances for each encryption level (GCM encrypt/decrypt) std::unique_ptr<aes> _aes_initial_send; std::unique_ptr<aes> _aes_initial_recv; std::unique_ptr<aes> _aes_hs_send; Loading @@ -814,6 +814,14 @@ namespace netplus { std::unique_ptr<aes> _aes_app_send; std::unique_ptr<aes> _aes_app_recv; // Cached AES instances for header protection (ECB, reused across packets) std::unique_ptr<aes> _aes_hp_initial_send; std::unique_ptr<aes> _aes_hp_initial_recv; std::unique_ptr<aes> _aes_hp_hs_send; std::unique_ptr<aes> _aes_hp_hs_recv; std::unique_ptr<aes> _aes_hp_app_send; std::unique_ptr<aes> _aes_hp_app_recv; // Certificate bundle for server mode std::map<std::string, ssl::CertificateBundle> _cert_map; ssl::CertificateBundle* _selected_cert = nullptr; Loading Loading @@ -846,6 +854,26 @@ namespace netplus { bool _handshake_timeout_triggered = false; static const int HANDSHAKE_TIMEOUT_MS = 5000; // 5 second timeout for handshake // PING keepalive: last activity timestamp & interval std::chrono::steady_clock::time_point _last_activity; static constexpr int KEEPALIVE_INTERVAL_MS = 15000; // Send PING every 15s of inactivity // Handshake retransmission: store last handshake flight for retransmit std::vector<std::vector<uint8_t>> _hs_flight_packets; // Stored for retransmit std::chrono::steady_clock::time_point _hs_last_send; int _hs_retransmit_count = 0; static constexpr int HS_RETRANSMIT_MAX = 5; static constexpr int HS_RETRANSMIT_INTERVAL_MS = 200; // Initial retransmit timer // Flow control batching: avoid sending duplicate MAX_DATA/MAX_STREAM_DATA bool _pending_max_data = false; uint64_t _pending_max_data_value = 0; std::map<uint64_t, uint64_t> _pending_max_stream_data; // ACK tracking: need to send ACK for initial/handshake levels bool _need_initial_ack = false; bool _need_handshake_ack = false; // Mutex for thread safety mutable std::mutex _quic_mutex; Loading
test/quic_test.cpp +6 −0 Changes for test/quic_test.cpp: 6 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -776,10 +776,16 @@ static void runHttpsFallbackServer(std::map<std::string, netplus::ssl::Certifica }); // Configure framing callback: always HTTP/2 // stream_id == 0 → epoll post-handshake probe, return empty // (SETTINGS preface is sent by h2ProcessFrames) // stream_id > 0 → produce response for that HTTP/2 stream fallbackSock.setFramingCallback([](const std::string& alpn, uint32_t stream_id, const std::string& body, const std::string& content_type) -> std::string { if (stream_id == 0) { return ""; } return h2BuildResponse(stream_id, body, content_type); }); Loading