Skip to content

Commit 415b22c

Browse files
author
Rob Sanders
committed
Merge remote-tracking branch 'upstream/stable' into libcli_1_10_5_staging
2 parents 36dfe81 + 65b98fc commit 415b22c

1 file changed

Lines changed: 25 additions & 6 deletions

File tree

libcli.c

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
#ifndef WIN32
2222
#include <regex.h>
2323
#endif
24+
#if defined(LIBCLI_USE_POLL) && !defined(WIN32)
25+
#include <poll.h>
26+
#define CLI_SOCKET_WAIT_PERROR "poll"
27+
#else
28+
#define CLI_SOCKET_WAIT_PERROR "select"
29+
#endif
2430
#include "libcli.h"
2531

2632
#ifdef __GNUC__
@@ -170,6 +176,7 @@ inline void cli_int_show_pipeline(struct cli_def *cli, struct cli_pipeline *pipe
170176
static void cli_int_free_pipeline(struct cli_pipeline *pipeline);
171177
static struct cli_command *cli_register_command_core(struct cli_def *cli, struct cli_command *parent, struct cli_command *c);
172178
static void cli_int_wrap_help_line(char *nameptr, char *helpptr, struct cli_comphelp *comphelp);
179+
static int cli_socket_wait(int sockfd, struct timeval *tm);
173180

174181
static char DELIM_OPT_START[] = "[";
175182
static char DELIM_OPT_END[] = "]";
@@ -1127,7 +1134,6 @@ int cli_loop(struct cli_def *cli, int sockfd) {
11271134

11281135
while (1) {
11291136
int sr;
1130-
fd_set r;
11311137

11321138
/*
11331139
* Ensure our transient mode is reset to the starting mode on *each* loop traversal transient mode is valid only
@@ -1168,12 +1174,9 @@ int cli_loop(struct cli_def *cli, int sockfd) {
11681174
cli->showprompt = 0;
11691175
}
11701176

1171-
FD_ZERO(&r);
1172-
FD_SET(sockfd, &r);
1173-
1174-
if ((sr = select(sockfd + 1, &r, NULL, NULL, &tm)) < 0) {
1177+
if ((sr = cli_socket_wait(sockfd, &tm)) < 0) {
11751178
if (errno == EINTR) continue;
1176-
perror("select");
1179+
perror(CLI_SOCKET_WAIT_PERROR);
11771180
l = -1;
11781181
break;
11791182
}
@@ -3585,3 +3588,19 @@ void cli_dump_optargs_and_args(struct cli_def *cli, const char *text, char *argv
35853588
cli_print(cli, "Extra args");
35863589
for (i = 0; i < argc; i++) cli_print(cli, "%2d %s", i, argv[i]);
35873590
}
3591+
3592+
static int cli_socket_wait(int sockfd, struct timeval *tm) {
3593+
#if defined(LIBCLI_USE_POLL) && !defined(WIN32)
3594+
struct pollfd pfd = {
3595+
.fd = sockfd,
3596+
.events = POLLIN,
3597+
};
3598+
3599+
return poll(&pfd, 1, (tm->tv_sec * 1000) + (tm->tv_usec / 1000));
3600+
#else
3601+
fd_set r;
3602+
FD_ZERO(&r);
3603+
FD_SET(sockfd, &r);
3604+
return select(sockfd + 1, &r, NULL, NULL, tm);
3605+
#endif
3606+
}

0 commit comments

Comments
 (0)