Skip to content

Commit a8e0d9f

Browse files
Drain EPOLLET socket reads and preserve errno 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 c4d3404 commit a8e0d9f

1 file changed

Lines changed: 19 additions & 9 deletions

File tree

src/Client.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,26 @@ Client::~Client()
2222

2323
ssize_t Client::receiveData()
2424
{
25-
ssize_t RcvBytes;
26-
do {
27-
RcvBytes = read(_ClientFD, _ReceiveBuffer, SOCKET_RECEIVE_BUFFER_SIZE);
28-
} while (RcvBytes == -1 && errno == EINTR);
25+
for (;;) {
26+
const ssize_t RcvBytes = read(_ClientFD, _ReceiveBuffer, SOCKET_RECEIVE_BUFFER_SIZE);
27+
const int ReadErrno = errno;
2928

30-
DBG(220, "RcvBytes:" << RcvBytes << " ClientFD:" << _ClientFD);
29+
DBG(220, "RcvBytes:" << RcvBytes << " ClientFD:" << _ClientFD);
3130

32-
if (RcvBytes > 0) {
33-
appendBuffer(_ReceiveBuffer, RcvBytes);
34-
}
31+
if (RcvBytes > 0) {
32+
appendBuffer(_ReceiveBuffer, RcvBytes);
33+
continue;
34+
}
35+
36+
if (RcvBytes == 0) {
37+
return 0;
38+
}
3539

36-
return RcvBytes;
40+
if (ReadErrno == EINTR) {
41+
continue;
42+
}
43+
44+
errno = ReadErrno;
45+
return -1;
46+
}
3747
}

0 commit comments

Comments
 (0)