1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-05 08:11:47 +02:00

Add convenience function for connecting to a Unix domain socket

This commit is contained in:
Eelco Dolstra 2025-04-11 16:11:57 +02:00 committed by Jörg Thalheim
parent 5b4806ab3c
commit 0087188d47
3 changed files with 15 additions and 3 deletions

View file

@ -9,6 +9,8 @@
#endif
#include <unistd.h>
#include <filesystem>
namespace nix {
/**
@ -80,4 +82,9 @@ void bind(Socket fd, const std::string & path);
*/
void connect(Socket fd, const std::string & path);
/**
* Connect to a Unix domain socket.
*/
AutoCloseFD connect(const std::filesystem::path & path);
}

View file

@ -114,4 +114,11 @@ void connect(Socket fd, const std::string & path)
bindConnectProcHelper("connect", ::connect, fd, path);
}
AutoCloseFD connect(const std::filesystem::path & path)
{
auto fd = createUnixDomainSocket();
nix::connect(toSocket(fd.get()), path);
return fd;
}
}