my $logfile; # log file
my $cmdfile; # command file
my $connect; # IP to connect to on CONNECT
+my $keepalive_secs; # number of seconds to keep idle connections
my $srcdir;
my $gopher = 0;
shift @ARGV;
}
}
+ elsif($ARGV[0] eq '--keepalive') {
+ if($ARGV[1]) {
+ $keepalive_secs = $ARGV[1];
+ shift @ARGV;
+ }
+ }
elsif($ARGV[0] eq '--id') {
if($ARGV[1] =~ /^(\d+)$/) {
$idnum = $1 if($1 > 0);
"--portfile \"$portfile\" ";
$flags .= "--gopher " if($gopher);
$flags .= "--connect $connect " if($connect);
+$flags .= "--keepalive $keepalive_secs " if($keepalive_secs);
if($ipvnum eq 'unix') {
$flags .= "--unix-socket '$unix_socket' ";
} else {
my $idnum = 1;
my $exe = "$perl $srcdir/http-server.pl";
my $verbose_flag = "--verbose ";
+ my $keepalive_secs = 30; # forwarded to sws, was 5 by default which
+ # led to pukes in CI jobs
if($alt eq "ipv6") {
# if IPv6, use a different setup
my $flags = "";
$flags .= "--gopher " if($proto eq "gopher");
$flags .= "--connect $HOSTIP " if($alt eq "proxy");
+ $flags .= "--keepalive $keepalive_secs ";
$flags .= $verbose_flag if($debugprotocol);
$flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
$flags .= "--logdir \"$LOGDIR\" ";
#endif
const char *serverlogfile = DEFAULT_LOGFILE;
-const char *logdir = "log";
-char loglockfile[256];
+static const char *logdir = "log";
+static char loglockfile[256];
#define SWSVERSION "curl test suite HTTP server/0.1"
static void http_connect(curl_socket_t *infdp,
curl_socket_t rootfd,
const char *ipaddr,
- unsigned short ipport)
+ unsigned short ipport,
+ int keepalive_secs)
{
curl_socket_t serverfd[2] = {CURL_SOCKET_BAD, CURL_SOCKET_BAD};
curl_socket_t clientfd[2] = {CURL_SOCKET_BAD, CURL_SOCKET_BAD};
} /* (rc > 0) */
else {
timeout_count++;
- if(timeout_count > 5) {
+ if(timeout_count > keepalive_secs) {
logmsg("CONNECT proxy timeout after %d idle seconds!", timeout_count);
break;
}
is no data waiting, or < 0 if it should be closed */
static int service_connection(curl_socket_t msgsock, struct httprequest *req,
curl_socket_t listensock,
- const char *connecthost)
+ const char *connecthost,
+ int keepalive_secs)
{
if(got_exit_signal)
return -1;
return 1;
}
else {
- http_connect(&msgsock, listensock, connecthost, req->connect_port);
+ http_connect(&msgsock, listensock, connecthost, req->connect_port,
+ keepalive_secs);
return -1;
}
}
const char *socket_type = "IPv4";
char port_str[11];
const char *location_str = port_str;
+ int keepalive_secs = 5;
/* a default CONNECT port is basically pointless but still ... */
size_t socket_idx;
arg++;
}
}
+ else if(!strcmp("--keepalive", argv[arg])) {
+ arg++;
+ if(argc>arg) {
+ char *endptr;
+ unsigned long ulnum = strtoul(argv[arg], &endptr, 10);
+ if((endptr != argv[arg] + strlen(argv[arg])) ||
+ (ulnum && ((ulnum < 0UL) || (ulnum > 65535UL)))) {
+ fprintf(stderr, "sws: invalid --keepalive argument (%s), must "
+ "be number of seconds\n", argv[arg]);
+ return 0;
+ }
+ keepalive_secs = curlx_ultous(ulnum);
+ arg++;
+ }
+ }
else if(!strcmp("--connect", argv[arg])) {
/* The connect host IP number that the proxy will connect to no matter
what the client asks for, but also use this as a hint that we run as
/* Service this connection until it has nothing available */
do {
rc = service_connection(all_sockets[socket_idx], req, sock,
- connecthost);
+ connecthost, keepalive_secs);
if(got_exit_signal)
goto sws_cleanup;