Skip to content

Commit 0d25cc6

Browse files
committed
Add SSHMaster::Connection::trySetBufferSize
It is unused in Nix currently, but will be used in Hydra. This reflects what Hydra does in NixOS/hydra#1387. We may probably to use it more widely for better SSH store performance, but this needs to be subject to more testing before we do that.
1 parent f0dbfad commit 0d25cc6

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/libstore/ssh.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,4 +240,19 @@ Path SSHMaster::startMaster()
240240

241241
#endif
242242

243+
void SSHMaster::Connection::trySetBufferSize(size_t size)
244+
{
245+
#ifdef F_SETPIPE_SZ
246+
/* This `fcntl` method of doing this takes a positive `int`. Check
247+
and convert accordingly.
248+
249+
The function overall still takes `size_t` because this is more
250+
portable for a platform-agnostic interface. */
251+
assert(size <= INT_MAX);
252+
int pipesize = size;
253+
fcntl(in.get(), F_SETPIPE_SZ, pipesize);
254+
fcntl(out.get(), F_SETPIPE_SZ, pipesize);
255+
#endif
256+
}
257+
243258
}

src/libstore/ssh.hh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ public:
5454
Pid sshPid;
5555
#endif
5656
AutoCloseFD out, in;
57+
58+
/**
59+
* Try to set the buffer size in both directions to the
60+
* designated amount, if possible. If not possible, does
61+
* nothing.
62+
*
63+
* Current implementation is to use `fcntl` with `F_SETPIPE_SZ`,
64+
* which is Linux-only. For this implementation, `size` must
65+
* convertable to an `int`. In other words, it must be within
66+
* `[0, INT_MAX]`.
67+
*/
68+
void trySetBufferSize(size_t size);
5769
};
5870

5971
/**

0 commit comments

Comments
 (0)