Skip to content

Commit

Permalink
net io: make some code nicer to read
Browse files Browse the repository at this point in the history
  • Loading branch information
wiedehopf committed Oct 13, 2024
1 parent 87d62d3 commit 431f5d8
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions net_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -1466,14 +1466,13 @@ static int pongReceived(struct client *c, int64_t now) {
static int flushClient(struct client *c, int64_t now) {
if (!c->service) { fprintf(stderr, "report error: Ahlu8pie\n"); return -1; }
int toWrite = c->sendq_len;
char *psendq = c->sendq;

if (toWrite == 0) {
c->last_flush = now;
return 0;
}

int bytesWritten = send(c->fd, psendq, toWrite, 0);
int bytesWritten = send(c->fd, c->sendq, toWrite, 0);
int err = errno;

// If we get -1, it's only fatal if it's not EAGAIN/EWOULDBLOCK
Expand All @@ -1499,7 +1498,6 @@ static int flushClient(struct client *c, int64_t now) {
if (bytesWritten > 0) {
Modes.stats_current.network_bytes_out += bytesWritten;
// Advance buffer
psendq += bytesWritten;
toWrite -= bytesWritten;
c->sendq_len -= bytesWritten;

Expand All @@ -1510,13 +1508,13 @@ static int flushClient(struct client *c, int64_t now) {
memmove((void*)c->sendq, c->sendq + bytesWritten, toWrite);
}
}
if (c->last_flush != now && !(c->epollEvent.events & EPOLLOUT)) {
if (toWrite > 0 && !(c->epollEvent.events & EPOLLOUT)) {
// if we couldn't flush our buffer, make epoll tell us when we can write again
c->epollEvent.events |= EPOLLOUT;
if (epoll_ctl(Modes.net_epfd, EPOLL_CTL_MOD, c->fd, &c->epollEvent))
perror("epoll_ctl fail:");
}
if ((c->epollEvent.events & EPOLLOUT) && c->last_flush == now) {
if (toWrite == 0 && (c->epollEvent.events & EPOLLOUT)) {
// if set, remove EPOLLOUT from epoll if flush was successful
c->epollEvent.events ^= EPOLLOUT;
if (epoll_ctl(Modes.net_epfd, EPOLL_CTL_MOD, c->fd, &c->epollEvent))
Expand Down

0 comments on commit 431f5d8

Please sign in to comment.