spend less time petting dogs

This commit is contained in:
p2r3
2025-08-20 06:10:04 +03:00
parent 023b866529
commit a89043394c
2 changed files with 6 additions and 4 deletions

View File

@@ -392,7 +392,7 @@ int main () {
* client connection. * client connection.
*/ */
while (true) { while (true) {
wdt_reset(); if (client_count == 0) { wdt_reset(); }
// Attempt to accept a new connection // Attempt to accept a new connection
for (int i = 0; i < MAX_PLAYERS; i ++) { for (int i = 0; i < MAX_PLAYERS; i ++) {
@@ -413,7 +413,7 @@ int main () {
if (client_index == MAX_PLAYERS) client_index = 0; if (client_index == MAX_PLAYERS) client_index = 0;
if (clients[client_index] == -1) continue; if (clients[client_index] == -1) continue;
// Handle infrequent periodic events every 10 seconds // Handle infrequent periodic events every few seconds
clock_gettime(CLOCK_REALTIME, &time_now); clock_gettime(CLOCK_REALTIME, &time_now);
time_t seconds_since_update = time_now.tv_sec - keepalive_last.tv_sec; time_t seconds_since_update = time_now.tv_sec - keepalive_last.tv_sec;
if (seconds_since_update > 10) { if (seconds_since_update > 10) {
@@ -467,6 +467,8 @@ int main () {
disconnectClient(&clients[client_index], 4); disconnectClient(&clients[client_index], 4);
continue; continue;
} }
// Reset watchdog and yield between packets
wdt_reset();
} }

View File

@@ -63,12 +63,12 @@ ssize_t recv_all (int client_fd, void *buf, size_t n, uint8_t require_first) {
return total; // got exactly n bytes return total; // got exactly n bytes
} }
ssize_t send_all (int fd, const void *buf, size_t len) { ssize_t send_all (int client_fd, const void *buf, size_t len) {
const uint8_t *p = (const uint8_t *)buf; const uint8_t *p = (const uint8_t *)buf;
size_t sent = 0; size_t sent = 0;
while (sent < len) { while (sent < len) {
ssize_t n = send(fd, p + sent, len - sent, MSG_NOSIGNAL); ssize_t n = send(client_fd, p + sent, len - sent, MSG_NOSIGNAL);
if (n > 0) { if (n > 0) {
sent += (size_t)n; sent += (size_t)n;
continue; continue;