move check for full peer table

if we can't accept any more connections, don't poll the socket
This commit is contained in:
2026-06-01 15:51:38 +01:00
parent 3e8640e54f
commit f2b13bc34c
+26 -22
View File
@@ -256,33 +256,37 @@ int main(int argc, char **argv)
};
while(1) {
if(poll(pollfds, 2, 10000) == 0)
pollfds[0].revents = 0;
pollfds[1].revents = 0;
/* if find_peer says the peer table is full, don't poll the
* socket
*/
if(poll(pollfds, find_peer(0) ? 2 : 1, 10000) == 0)
continue;
if(pollfds[1].revents) {
if(find_peer(0)) {
int len = recvmsg(socket, &msg , 0);
if(len <= 0) continue;
int len = recvmsg(socket, &msg , 0);
if(len <= 0) continue;
int peer_fds[3];
if(fds_from_msg(&msg, peer_fds)) {
char *argline = malloc(len);
if(! argline) {
die("malloc failed");
}
memmove(argline, buf, len);
if(msg.msg_flags & (MSG_TRUNC | MSG_CTRUNC)) {
hangup_peer(socket, &peer_addr, msg.msg_namelen, 0xffff);
} else {
pid_t child_pid = fork_lua(L, argline, len, peer_fds);
register_peer(child_pid, &peer_addr, msg.msg_namelen);
}
/* close peer fds in parent */
close(peer_fds[0]);
close(peer_fds[1]);
close(peer_fds[2]);
int peer_fds[3];
if(fds_from_msg(&msg, peer_fds)) {
char *argline = malloc(len);
if(! argline) {
die("malloc failed");
}
memmove(argline, buf, len);
if(msg.msg_flags & (MSG_TRUNC | MSG_CTRUNC)) {
hangup_peer(socket, &peer_addr, msg.msg_namelen, 0xffff);
} else {
pid_t child_pid = fork_lua(L, argline, len, peer_fds);
register_peer(child_pid, &peer_addr, msg.msg_namelen);
}
/* close peer fds in parent */
close(peer_fds[0]);
close(peer_fds[1]);
close(peer_fds[2]);
}
}