Probably going to merge accept and network threads

This commit is contained in:
2025-08-20 16:24:09 -04:00
parent 24a1157f0d
commit 7e28e6503d
6 changed files with 166 additions and 72 deletions

View File

@@ -47,19 +47,25 @@ void Connection::appendMessage(std::string_view s, bool copyToArena) {
}
}
std::string_view Connection::readBytes(char *buf, size_t buffer_size) {
int r = read(fd_, buf, buffer_size);
if (r == -1) {
if (errno == EINTR || errno == EAGAIN) {
return {}; // Empty string_view indicates no data or would block
int Connection::readBytes(char *buf, size_t buffer_size) {
int r;
for (;;) {
r = read(fd_, buf, buffer_size);
if (r == -1) {
if (errno == EINTR) {
continue;
}
if (errno == EAGAIN) {
return 0;
}
perror("read");
return -1;
}
perror("read");
return {}; // Error - let server handle connection cleanup
if (r == 0) {
return -1;
}
return r;
}
if (r == 0) {
return {}; // EOF - let server handle connection cleanup
}
return {buf, size_t(r)};
}
bool Connection::writeBytes() {