Skip to content

Commit

Permalink
Merge pull request #25 from gmbeard/fix/24-strerror-missing-ns-and-he…
Browse files Browse the repository at this point in the history
…ader

fix(#24) Missing namespace and header for `strerror`
  • Loading branch information
gmbeard authored Nov 27, 2023
2 parents ce7616d + f98a3ba commit 7fedac1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions .versioning/changes/F3oCxi3g1O.patch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixes an issue that was causing builds to fail on musl platforms (#24)
13 changes: 8 additions & 5 deletions src/io/unix_socket.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "io/unix_socket.hpp"
#include "utils/scope_guard.hpp"
#include <algorithm>
#include <cstring>
#include <errno.h>
#include <fcntl.h>
#include <stdexcept>
Expand All @@ -20,7 +21,7 @@ auto create_socket(std::string_view path, F&& on_create)
{
int fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd < 0)
throw std::runtime_error { "connect(): "s + strerror(errno) };
throw std::runtime_error { "connect(): "s + std::strerror(errno) };

auto close_guard = sc::ScopeGuard { [&] { close(fd); } };

Expand Down Expand Up @@ -68,15 +69,17 @@ auto UnixSocket::accept() -> UnixSocket
socklen_t len = sizeof(sockaddr_un);
auto fd = ::accept(fd_, reinterpret_cast<sockaddr*>(&remote_addr), &len);
if (fd < 0)
throw std::runtime_error { "UnixSocket::accept() "s + strerror(errno) };
throw std::runtime_error { "UnixSocket::accept() "s +
std::strerror(errno) };

return UnixSocket { fd };
}

auto UnixSocket::listen() -> void
{
if (auto const listen_result = ::listen(fd_, 1); listen_result < 0)
throw std::runtime_error { "UnixSocket::listen() "s + strerror(errno) };
throw std::runtime_error { "UnixSocket::listen() "s +
std::strerror(errno) };
}

auto UnixSocket::fd() const noexcept -> int { return fd_; }
Expand All @@ -97,7 +100,7 @@ auto bind(std::string_view path) -> UnixSocket
reinterpret_cast<sockaddr*>(&addr),
sizeof(addr.sun_family) + path.size());
result < 0)
throw std::logic_error { "bind(): "s + strerror(errno) };
throw std::logic_error { "bind(): "s + std::strerror(errno) };

return UnixSocket { fd };
});
Expand All @@ -110,7 +113,7 @@ auto connect(std::string_view path) -> UnixSocket
reinterpret_cast<sockaddr*>(&addr),
sizeof(addr.sun_family) + path.size());
result < 0)
throw std::logic_error { "connect(): "s + strerror(errno) };
throw std::logic_error { "connect(): "s + std::strerror(errno) };

return UnixSocket { fd };
});
Expand Down

0 comments on commit 7fedac1

Please sign in to comment.