Skip to content

Commit bc5105b

Browse files
committed
fix: do not overwrite res variable
- One of the most costly bugs I've had in terms of time
1 parent 1b74800 commit bc5105b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

source/prime-time/main.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ int main()
8989
}
9090

9191
char *data, *sddata;
92-
int n, fd, res, size, sdsize;
92+
int n, fd, res, size, sdsize, rs;
9393
struct epoll_ctl_info epci = {epollfd, 0, 0};
9494
struct queue* rcqu = NULL, *sdqu = NULL;
9595
queue_init(&rcqu, QUEUE_CAPACITY);
@@ -146,9 +146,8 @@ int main()
146146
continue;
147147
}
148148
sdsize = queue_pop_no_copy(sdqu, &sddata);
149-
log_trace("main epoll loop: queue(%d): '%s'", sdsize, sddata);
150-
res = sendall(fd, sddata, &sdsize);
151-
if (res != 0) {
149+
rs = sendall(fd, sddata, &sdsize);
150+
if (rs != 0) {
152151
log_error("main epoll loop:: failed during sendall function");
153152
if (fd_poll_del_and_close(&epci) == -1) {
154153
perror("epoll_ctl: recv 0");
@@ -163,6 +162,7 @@ int main()
163162
continue;
164163

165164
// Handle closing request received
165+
log_info("main epoll loop:: closing connection");
166166
if (fd_poll_del_and_close(&epci) == -1) {
167167
perror("epoll_ctl: recv 0");
168168
exit(EXIT_FAILURE);

0 commit comments

Comments
 (0)