Loading src/event/epoll.cpp +16 −8 Changes for src/event/epoll.cpp: 16 added lines, 8 removed lines. Original line number Diff line number Diff line Loading @@ -264,19 +264,19 @@ namespace netplus { } epoll_event setevent{}; setevent.events = EPOLLIN | EPOLLRDHUP; // level-triggered setevent.events = EPOLLIN | EPOLLRDHUP | EPOLLONESHOT; setevent.data.fd = fd; epoll_ctl(_pollFD, EPOLL_CTL_ADD, fd, &setevent); evconnection->ConnectEvent(*ccon, tid, args); // With level-triggered, socket stays registered and will fire // on both IN and OUT as long as conditions persist. // Update events to include EPOLLOUT if data is pending. // With EPOLLONESHOT, socket must be re-armed after each event. // The batched send loop reduces re-arm syscalls by draining data // in a single epoll event rather than one chunk per event. if (ccon->SendData.pos < ccon->SendData.size() || ccon->csock->hasPendingWrite()) { epoll_event ev{}; ev.events = EPOLLIN | EPOLLOUT | EPOLLRDHUP; // level-triggered ev.events = EPOLLIN | EPOLLOUT | EPOLLRDHUP | EPOLLONESHOT; ev.data.fd = fd; epoll_ctl(_pollFD, EPOLL_CTL_MOD, fd, &ev); } Loading @@ -297,6 +297,7 @@ namespace netplus { return; } EpollArmGuard rearm(fd, c, this); bool needClose = false; // Pre-allocate buffer outside the inner loops to avoid // repeated heap allocation on every recv iteration. Loading Loading @@ -487,8 +488,13 @@ namespace netplus { } } // With level-triggered, socket stays ready for EPOLLOUT // No explicit re-arm needed // With EPOLLONESHOT, re-arm is needed; batching sends reduces syscalls significantly if (sendBlockedWouldBlock && c->SendData.pos < c->SendData.size()) { // More data queued but socket is full - need to wait for EPOLLOUT rearm.disarm(); setpollEventsFd(fd, EPOLLOUT | EPOLLRDHUP | EPOLLONESHOT); return; } if (c->SendData.pos >= c->SendData.size() && !c->csock->hasPendingWrite()) { c->SendData.clear(); Loading @@ -500,9 +506,10 @@ namespace netplus { } catch (NetException& e) { if (e.getErrorType() == NetException::Note) { int ev = EPOLLIN | EPOLLRDHUP; int ev = EPOLLIN | EPOLLRDHUP | EPOLLONESHOT; if (c->csock->hasPendingWrite() || c->SendData.pos < c->SendData.size()) ev |= EPOLLOUT; rearm.disarm(); setpollEventsFd(fd, ev); return; } Loading @@ -513,6 +520,7 @@ namespace netplus { } // unlock event_mutex if (needClose) { rearm.disarm(); CloseEventHandler(fd, tid, args); } } Loading Loading
src/event/epoll.cpp +16 −8 Changes for src/event/epoll.cpp: 16 added lines, 8 removed lines. Original line number Diff line number Diff line Loading @@ -264,19 +264,19 @@ namespace netplus { } epoll_event setevent{}; setevent.events = EPOLLIN | EPOLLRDHUP; // level-triggered setevent.events = EPOLLIN | EPOLLRDHUP | EPOLLONESHOT; setevent.data.fd = fd; epoll_ctl(_pollFD, EPOLL_CTL_ADD, fd, &setevent); evconnection->ConnectEvent(*ccon, tid, args); // With level-triggered, socket stays registered and will fire // on both IN and OUT as long as conditions persist. // Update events to include EPOLLOUT if data is pending. // With EPOLLONESHOT, socket must be re-armed after each event. // The batched send loop reduces re-arm syscalls by draining data // in a single epoll event rather than one chunk per event. if (ccon->SendData.pos < ccon->SendData.size() || ccon->csock->hasPendingWrite()) { epoll_event ev{}; ev.events = EPOLLIN | EPOLLOUT | EPOLLRDHUP; // level-triggered ev.events = EPOLLIN | EPOLLOUT | EPOLLRDHUP | EPOLLONESHOT; ev.data.fd = fd; epoll_ctl(_pollFD, EPOLL_CTL_MOD, fd, &ev); } Loading @@ -297,6 +297,7 @@ namespace netplus { return; } EpollArmGuard rearm(fd, c, this); bool needClose = false; // Pre-allocate buffer outside the inner loops to avoid // repeated heap allocation on every recv iteration. Loading Loading @@ -487,8 +488,13 @@ namespace netplus { } } // With level-triggered, socket stays ready for EPOLLOUT // No explicit re-arm needed // With EPOLLONESHOT, re-arm is needed; batching sends reduces syscalls significantly if (sendBlockedWouldBlock && c->SendData.pos < c->SendData.size()) { // More data queued but socket is full - need to wait for EPOLLOUT rearm.disarm(); setpollEventsFd(fd, EPOLLOUT | EPOLLRDHUP | EPOLLONESHOT); return; } if (c->SendData.pos >= c->SendData.size() && !c->csock->hasPendingWrite()) { c->SendData.clear(); Loading @@ -500,9 +506,10 @@ namespace netplus { } catch (NetException& e) { if (e.getErrorType() == NetException::Note) { int ev = EPOLLIN | EPOLLRDHUP; int ev = EPOLLIN | EPOLLRDHUP | EPOLLONESHOT; if (c->csock->hasPendingWrite() || c->SendData.pos < c->SendData.size()) ev |= EPOLLOUT; rearm.disarm(); setpollEventsFd(fd, ev); return; } Loading @@ -513,6 +520,7 @@ namespace netplus { } // unlock event_mutex if (needClose) { rearm.disarm(); CloseEventHandler(fd, tid, args); } } Loading