Skip to content

Commit a3635ae

Browse files
committed
Make it possible to specify the timeout for WaitForIncoming
Instead of always using the hardcoded magic number 60.
1 parent ad7caea commit a3635ae

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

cf-serverd/cf-serverd-functions.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include <loading.h>
5050
#include <printsize.h>
5151

52+
#define WAIT_INCOMING_TIMEOUT 10
5253

5354
static const size_t QUEUESIZE = 50;
5455
int NO_FORK = false; /* GLOBAL_A */
@@ -717,7 +718,7 @@ int StartServer(EvalContext *ctx, Policy **policy, GenericAgentConfig *config)
717718
{
718719
CollectCallIfDue(ctx);
719720

720-
int selected = WaitForIncoming(sd);
721+
int selected = WaitForIncoming(sd, WAIT_INCOMING_TIMEOUT);
721722

722723
Log(LOG_LEVEL_DEBUG, "select(): %d", selected);
723724
if (selected == -1)

cf-testd/cf-testd.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#include <arpa/inet.h>
6060

6161
#define CFTESTD_QUEUE_SIZE 10
62+
#define WAIT_CHECK_TIMEOUT 10
6263

6364
// ============================= CFTestD_Config ==============================
6465
typedef struct
@@ -532,7 +533,7 @@ int CFTestD_StartServer(CFTestD_Config *config)
532533
int selected = 0;
533534
while (selected != -1)
534535
{
535-
selected = WaitForIncoming(sd);
536+
selected = WaitForIncoming(sd, WAIT_CHECK_TIMEOUT);
536537

537538
if (selected > 0)
538539
{

libcfnet/server_code.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@
1010
/* Wait up to a minute for an in-coming connection.
1111
*
1212
* @param sd The listening socket or -1.
13+
* @param tm_sec timeout in seconds
1314
* @retval > 0 In-coming connection.
1415
* @retval 0 No in-coming connection.
1516
* @retval -1 Error (other than interrupt).
1617
* @retval < -1 Interrupted while waiting.
1718
*/
18-
int WaitForIncoming(int sd)
19+
int WaitForIncoming(int sd, time_t tm_sec)
1920
{
2021
Log(LOG_LEVEL_DEBUG, "Waiting at incoming select...");
21-
struct timeval timeout = { .tv_sec = 60 };
22+
struct timeval timeout = { .tv_sec = tm_sec };
2223
int signal_pipe = GetSignalPipe();
2324
fd_set rset;
2425
FD_ZERO(&rset);

libcfnet/server_code.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
#include <platform.h>
55

66
int InitServer(size_t queue_size, char *bind_address);
7-
int WaitForIncoming(int sd);
7+
int WaitForIncoming(int sd, time_t tm_sec);
88

99
#endif

0 commit comments

Comments
 (0)