Skip to content

Commit 73cc980

Browse files
Refine errno handling and ET read completion semantics
Agent-Logs-Url: https://github.com/WEBcodeX1/http-1.2/sessions/52de29c4-0332-4c1e-9fd4-e87a34608c1f Co-authored-by: clauspruefer <17313789+clauspruefer@users.noreply.github.com>
1 parent a8e0d9f commit 73cc980

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

src/Client.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Client::~Client()
2222

2323
ssize_t Client::receiveData()
2424
{
25+
ssize_t TotalRcvBytes = 0;
26+
2527
for (;;) {
2628
const ssize_t RcvBytes = read(_ClientFD, _ReceiveBuffer, SOCKET_RECEIVE_BUFFER_SIZE);
2729
const int ReadErrno = errno;
@@ -30,6 +32,7 @@ ssize_t Client::receiveData()
3032

3133
if (RcvBytes > 0) {
3234
appendBuffer(_ReceiveBuffer, RcvBytes);
35+
TotalRcvBytes += RcvBytes;
3336
continue;
3437
}
3538

@@ -41,6 +44,13 @@ ssize_t Client::receiveData()
4144
continue;
4245
}
4346

47+
if (
48+
(ReadErrno == EAGAIN || ReadErrno == EWOULDBLOCK) &&
49+
TotalRcvBytes > 0
50+
) {
51+
return TotalRcvBytes;
52+
}
53+
4454
errno = ReadErrno;
4555
return -1;
4656
}

src/ClientHandler.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,19 @@ void ClientHandler::readClientData(const uint16_t FDCount)
8484

8585
if (Clients.contains(ReadFD)) {
8686
const auto RecvStatus = Clients[ReadFD]->receiveData();
87-
const int RecvErrno = errno;
8887
if (RecvStatus == 0) {
8988
Clients.erase(ReadFD);
9089
close(ReadFD);
91-
} else if (
92-
RecvStatus < 0 &&
93-
RecvErrno != EAGAIN &&
94-
RecvErrno != EWOULDBLOCK &&
95-
RecvErrno != EINTR
96-
) {
97-
Clients.erase(ReadFD);
98-
close(ReadFD);
90+
} else if (RecvStatus < 0) {
91+
const int RecvErrno = errno;
92+
if (
93+
RecvErrno != EAGAIN &&
94+
RecvErrno != EWOULDBLOCK &&
95+
RecvErrno != EINTR
96+
) {
97+
Clients.erase(ReadFD);
98+
close(ReadFD);
99+
}
99100
}
100101
}
101102
}

0 commit comments

Comments
 (0)