From 40ab6e43e79372ad4deafc3fad0778d898dcd696 Mon Sep 17 00:00:00 2001 From: whayter Date: Mon, 1 Nov 2021 17:27:25 +0100 Subject: [PATCH] pollout test --- src/web/Server.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/web/Server.cpp b/src/web/Server.cpp index c1f7b55c..b7c6112f 100644 --- a/src/web/Server.cpp +++ b/src/web/Server.cpp @@ -81,9 +81,10 @@ void Server::routine() _getRequests(i); _buildRequests(i); _buildResponses(i); - _sendResponses(i); } } + else if (_fds[i].revents & POLLOUT) + _sendResponses(i); else stop(-1); } @@ -145,6 +146,8 @@ void Server::_getRequests(int deviceIndex) for (int i = 0; i < nbytes; i++) _devices[deviceIndex].getInputBuffer().push_back(buffer[i]); } + else + _disconnectDevice(deviceIndex); } void Server::_buildRequests(int deviceIndex) @@ -170,13 +173,14 @@ void Server::_buildResponses(int deviceIndex) http::Response response; std::pair pair = requests.front(); if (http::isError(requests.front().second)) - //response = http::errorResponse(pair.first.getUri(), pair.second); response = http::errorResponse(getContext(pair.first.getUri()), response, pair.second); else response = http::buildResponse(pair.first); requests.pop(); _devices[deviceIndex].getResponsesQueue().push(response); } + if (!_devices[deviceIndex].getResponsesQueue().empty()) + _fds[deviceIndex].events = POLLIN | POLLOUT; } void Server::_sendResponses(int deviceIndex) @@ -207,6 +211,8 @@ void Server::_sendResponses(int deviceIndex) outputBuffer.erase(outputBuffer.begin(), outputBuffer.begin() + nbytes); _log(deviceIndex, "Response sent."); } + if (outputBuffer.empty()) + _fds[deviceIndex].events = POLLIN; if (endConnection) _disconnectDevice(deviceIndex); }