Skip to content

Commit d42d8d3

Browse files
committed
Add accept timeout as 3rd parameter of fdtransfer
1 parent 59b0ba4 commit d42d8d3

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/fdtransfer/fdtransferServer.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ bool FdTransferServer::sendFd(int fd, struct fd_response *resp, size_t resp_size
273273
return true;
274274
}
275275

276-
static int single_pid_server(int pid, const char *path) {
276+
static int single_pid_server(int pid, const char *path, unsigned int timeout) {
277277
// get its nspid prior to moving to its PID namespace.
278278
int nspid;
279279
uid_t _target_uid;
@@ -301,7 +301,7 @@ static int single_pid_server(int pid, const char *path) {
301301
}
302302
}
303303

304-
if (!FdTransferServer::bindServer(&sun, addrlen, 10)) {
304+
if (!FdTransferServer::bindServer(&sun, addrlen, timeout)) {
305305
return 1;
306306
}
307307

@@ -373,18 +373,20 @@ static int path_server(const char *path) {
373373

374374
int main(int argc, const char** argv) {
375375
int pid = 0;
376-
if (argc == 3) {
376+
unsigned int timeout = 0;
377+
if (argc == 4) {
377378
pid = atoi(argv[2]);
379+
timeout = atoi(argv[3]);
378380
} else if (argc != 2) {
379-
fprintf(stderr, "Usage: %s <path> [<pid>]\n", argv[0]);
381+
fprintf(stderr, "Usage: %s <path> [<pid> <timeout>]\n", argv[0]);
380382
return 1;
381383
}
382384

383385
// 2 modes:
384386
// pid is not given - bind on a path and accept requests forever, from any PID, until being killed.
385387
// pid is given - bind on an path for that PID, accept requests only from that PID until the single connection is closed.
386388
if (pid != 0) {
387-
return single_pid_server(pid, argv[1]);
389+
return single_pid_server(pid, argv[1], timeout);
388390
} else {
389391
return path_server(argv[1]);
390392
}

0 commit comments

Comments
 (0)