Don't try to set SO_REUSEADDR on sockets of AF_UNIX (#451)

Despite the fact that SO_REUSEADDR can be set on a Unix domain socket
via setsockopt() without reporting an error, SO_REUSEADDR was actually
created for ipv4/ipv6 and it's not supported for sockets of AF_UNIX.

Therefore, setting this option on a Unix domain socket does nothing but
costs one extra system call.

Signed-off-by: Andy Pan <i@andypan.me>
This commit is contained in:
Andy Pan 2024-05-08 01:25:26 +08:00 committed by GitHub
parent ba9dd7b23a
commit cde8ec1b41
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -616,7 +616,7 @@ int anetUnixServer(char *err, char *path, mode_t perm, int backlog)
}
int type = SOCK_STREAM;
int flags = ANET_SOCKET_CLOEXEC | ANET_SOCKET_NONBLOCK | ANET_SOCKET_REUSEADDR;
int flags = ANET_SOCKET_CLOEXEC | ANET_SOCKET_NONBLOCK;
if ((s = anetCreateSocket(err,AF_LOCAL,type,0,flags)) == ANET_ERR)
return ANET_ERR;