Skip to content

Commit

Permalink
Add Linux and OpenBSD support
Browse files Browse the repository at this point in the history
  • Loading branch information
devnexen committed Apr 14, 2022
1 parent e5b7e84 commit ba1d2e7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion redis.conf
Expand Up @@ -177,7 +177,7 @@ tcp-keepalive 300

# Assign a cookie ID to the listener socket mostly for IP filtering purpose
# e.g. ipfw can redirect packets to a specified identifier, 0 is the default.
#socket-id 0
# socket-id 0

################################# TLS/SSL #####################################

Expand Down
18 changes: 9 additions & 9 deletions src/anet.c
Expand Up @@ -686,15 +686,15 @@ int anetPipe(int fds[2], int read_flags, int write_flags) {
int anetSockId(char *err, int fd, uint32_t id)
{
#ifdef HAVE_SOCKOPTID
if (setsockopt(fd, SOL_SOCKET, SO_USER_COOKIE, (void *)&id, sizeof(id)) == -1) {
anetSetError(err, "setsockopt: %s", strerror(errno));
return ANET_ERR;
}
return ANET_OK;
if (setsockopt(fd, SOL_SOCKET, SOCKOPTID, (void *)&id, sizeof(id)) == -1) {
anetSetError(err, "setsockopt: %s", strerror(errno));
return ANET_ERR;
}
return ANET_OK;
#else
UNUSED(fd);
if (id > 0)
anetSetError(err,"anetSockid unsupported on this platform");
return ANET_OK;
UNUSED(fd);
if (id > 0)
anetSetError(err,"anetSockid unsupported on this platform");
return ANET_OK;
#endif
}
14 changes: 14 additions & 0 deletions src/config.h
Expand Up @@ -80,6 +80,10 @@
/* MSG_NOSIGNAL. */
#ifdef __linux__
#define HAVE_MSG_NOSIGNAL 1
#if defined(SO_MARK)
#define HAVE_SOCKOPTID 1
#define SOCKOPTID SO_MARK
#endif
#endif

/* Test for polling API */
Expand Down Expand Up @@ -114,7 +118,17 @@
#endif

#if defined(__FreeBSD__)
#if defined(SO_USER_COOKIE)
#define HAVE_SOCKOPTID 1
#define SOCKOPTID SO_USER_COOKIE
#endif
#endif

#if defined(__OpenBSD__)
#if defined(SO_RTABLE)
#define HAVE_SOCKOPTID 1
#define SOCKOPTID SO_RTABLE
#endif
#endif

#if __GNUC__ >= 4
Expand Down

0 comments on commit ba1d2e7

Please sign in to comment.