Commit 29369e1c authored by Marek Vavruša's avatar Marek Vavruša Committed by Jan Včelák

tcp: fixed a bug when sweep could fail to close a descriptor

parent d370fa9d
......@@ -71,23 +71,19 @@ static enum fdset_sweep_state tcp_sweep(fdset_t *set, int i, void *data)
{
UNUSED(data);
assert(set && i < set->n && i >= 0);
int fd = set->pfd[i].fd;
/* Best-effort, name and shame. */
struct sockaddr_storage ss;
socklen_t len = sizeof(struct sockaddr_storage);
memset(&ss, 0, len);
if (getpeername(fd, (struct sockaddr*)&ss, &len) < 0) {
dbg_net("tcp: sweep getpeername() on invalid socket=%d\n", fd);
return FDSET_SWEEP;
if (getpeername(fd, (struct sockaddr*)&ss, &len) == 0) {
char addr_str[SOCKADDR_STRLEN] = {0};
sockaddr_tostr(addr_str, sizeof(addr_str), &ss);
log_notice("connection terminated due to inactivity, address '%s'", addr_str);
}
/* Translate */
char addr_str[SOCKADDR_STRLEN] = {0};
sockaddr_tostr(addr_str, sizeof(addr_str), &ss);
log_notice("connection terminated due to inactivity, address '%s'", addr_str);
close(fd);
return FDSET_SWEEP;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment