Skip to content

Commit d1b9324

Browse files
authored
Merge pull request #10765 from obsidiansystems/ssh-pipe-size-method
Add `SSHMaster::Connection::trySetBufferSize`
2 parents ca2e526 + 94a7c34 commit d1b9324

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

src/libstore/legacy-ssh-store.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ ref<LegacySSHStore::Connection> LegacySSHStore::openConnection()
7070
command.push_back(remoteStore.get());
7171
}
7272
conn->sshConn = master.startCommand(std::move(command), std::list{extraSshArgs});
73+
if (connPipeSize) {
74+
conn->sshConn->trySetBufferSize(*connPipeSize);
75+
}
7376
conn->to = FdSink(conn->sshConn->in.get());
7477
conn->from = FdSource(conn->sshConn->out.get());
7578

src/libstore/legacy-ssh-store.hh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ struct LegacySSHStoreConfig : virtual CommonSSHStoreConfig
3030
*/
3131
Strings extraSshArgs = {};
3232

33+
/**
34+
* Exposed for hydra
35+
*/
36+
std::optional<size_t> connPipeSize;
37+
3338
const std::string name() override { return "SSH Store"; }
3439

3540
static std::set<std::string> uriSchemes() { return {"ssh"}; }

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)