Skip to content

Commit

Permalink
socket: Rename is_unix to is_converted
Browse files Browse the repository at this point in the history
While "is_unix" certainly would describe the state after being converted
from an AF_INET/AF_INET6 socket to an AF_UNIX socket, it's not
necessarily true if we pick up an existing AF_UNIX socket. In this case
the "conversion" would be from AF_UNIX to AF_UNIX and the name "is_unix"
would be ambiguous and could apply to the state before the conversion
*and* afterwards.

I stumbled upon this when implementing a way to pick up an existing Unix
domain socket and eg. change its path.

Signed-off-by: aszlig <[email protected]>
  • Loading branch information
aszlig committed Aug 14, 2023
1 parent e11498e commit 221680a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void Socket::blackhole(void)
int Socket::setsockopt(int level, int optname, const void *optval,
socklen_t optlen)
{
if (this->is_unix && level != SOL_SOCKET) {
if (this->is_converted && level != SOL_SOCKET) {
LOG(DEBUG) << "Prevented calling setsockopt on fd " << this->fd
<< " with incompatible level " << level << '.';
return 0;
Expand All @@ -122,7 +122,7 @@ int Socket::setsockopt(int level, int optname, const void *optval,
* succeeded (and it's using SOL_SOCKET level), otherwise we risk a fatal
* error while replaying them on our end.
*/
if (!this->is_unix && level == SOL_SOCKET) {
if (!this->is_converted && level == SOL_SOCKET) {
if (optname == SO_REUSEADDR && *static_cast<const int*>(optval) > 0)
this->reuse_addr = true;

Expand All @@ -141,7 +141,7 @@ int Socket::ioctl(unsigned long request, const void *arg)
/* Only add the arguments to the queue if the ioctl() has succeeded,
* otherwise we risk a fatal error while replaying them on our end.
*/
if (!this->is_unix)
if (!this->is_converted)
this->sockopts.cache_ioctl(request, arg);

return ret;
Expand All @@ -154,7 +154,7 @@ int Socket::epoll_ctl(int epfd, int op, struct epoll_event *event)
if (ret != 0)
return ret;

if (!this->is_unix)
if (!this->is_converted)
this->sockopts.cache_epoll_ctl(epfd, op, event);

return ret;
Expand Down Expand Up @@ -217,7 +217,7 @@ bool Socket::make_unix(int oldfd)
int newfd;
int old_errno = errno;

if (this->is_unix)
if (this->is_converted)
return true;

if (oldfd != -1) {
Expand Down Expand Up @@ -256,7 +256,7 @@ bool Socket::make_unix(int oldfd)
<< newfd << '.';

errno = old_errno;
this->is_unix = true;
this->is_converted = true;
return true;
}

Expand Down Expand Up @@ -486,7 +486,7 @@ int Socket::accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
sock->ports.reserve(local_port.value());
sock->binding = local_addr;
sock->connection = peer;
sock->is_unix = true;
sock->is_converted = true;
peer.apply_addr(addr, addrlen);
Socket::registry[sockfd] = sock->getptr();
LOG(INFO) << "Accepted socket fd " << sockfd
Expand Down
2 changes: 1 addition & 1 deletion src/socket.hh
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ struct Socket : std::enable_shared_from_this<Socket>
static std::unordered_set<SocketPath> sockpath_registry;

/* Whether the socket has been converted to an AF_UNIX socket. */
bool is_unix = false;
bool is_converted = false;

/* Set if this socket is bound to an unlinked socket path. */
bool is_blackhole = false;
Expand Down

0 comments on commit 221680a

Please sign in to comment.