Skip to content

Commit 6f2ec5f

Browse files
committed
Add convenience function for connecting to a Unix domain socket
1 parent bbfe39e commit 6f2ec5f

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/libstore/uds-remote-store.cc

+1-3
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,7 @@ ref<RemoteStore::Connection> UDSRemoteStore::openConnection()
8484
auto conn = make_ref<Connection>();
8585

8686
/* Connect to a daemon that does the privileged work for us. */
87-
conn->fd = createUnixDomainSocket();
88-
89-
nix::connect(toSocket(conn->fd.get()), path);
87+
conn->fd = nix::connect(path);
9088

9189
conn->from.fd = conn->fd.get();
9290
conn->to.fd = conn->fd.get();

src/libutil/include/nix/util/unix-domain-socket.hh

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#endif
1010
#include <unistd.h>
1111

12+
#include <filesystem>
13+
1214
namespace nix {
1315

1416
/**
@@ -80,4 +82,9 @@ void bind(Socket fd, const std::string & path);
8082
*/
8183
void connect(Socket fd, const std::string & path);
8284

85+
/**
86+
* Connect to a Unix domain socket.
87+
*/
88+
AutoCloseFD connect(const std::filesystem::path & path);
89+
8390
}

src/libutil/unix-domain-socket.cc

+7
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,11 @@ void connect(Socket fd, const std::string & path)
114114
bindConnectProcHelper("connect", ::connect, fd, path);
115115
}
116116

117+
AutoCloseFD connect(const std::filesystem::path & path)
118+
{
119+
auto fd = createUnixDomainSocket();
120+
nix::connect(toSocket(fd.get()), path);
121+
return fd;
122+
}
123+
117124
}

0 commit comments

Comments
 (0)