mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
dirmngr: Allow a timeout for HTTP and other TCP connects.
* dirmngr/http.c: Include fcntl.h. (http_session_s): Add field 'connect_timeout'. (http_session_new): Clear that. (http_session_set_timeout): New function. (my_wsagetlasterror) [W32]: New. (connect_with_timeout): New function. (connect_server): Add arg 'timeout' and call connect_with_timeout. (send_request): Add arg 'timeout' and pass it to connect_server. (http_raw_connect): Add arg 'timeout'. (http_open): Pass TIMEOUT from the session to connect_server. -- Note that the non-blocking connect we implement is traditional a pretty non-portable thing due to slighly different semantics. The code uses the strategy W. Richard Stevens suggested in 1998. Hopefully current OS versions got it all right. The code has not been tested on Windows. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
17e5afd80f
commit
5b9025cfa1
3 changed files with 200 additions and 17 deletions
|
@ -203,6 +203,7 @@ main (int argc, char **argv)
|
|||
int no_crl = 0;
|
||||
const char *cafile = NULL;
|
||||
http_session_t session = NULL;
|
||||
unsigned int timeout = 0;
|
||||
|
||||
gpgrt_init ();
|
||||
log_set_prefix (PGM, GPGRT_LOG_WITH_PREFIX | GPGRT_LOG_WITH_PID);
|
||||
|
@ -224,6 +225,7 @@ main (int argc, char **argv)
|
|||
" --debug flyswatter\n"
|
||||
" --tls-debug N use TLS debug level N\n"
|
||||
" --cacert FNAME expect CA certificate in file FNAME\n"
|
||||
" --timeout MS timeout for connect in MS\n"
|
||||
" --no-verify do not verify the certificate\n"
|
||||
" --force-tls use HTTP_FLAG_FORCE_TLS\n"
|
||||
" --force-tor use HTTP_FLAG_FORCE_TOR\n"
|
||||
|
@ -261,6 +263,15 @@ main (int argc, char **argv)
|
|||
argc--; argv++;
|
||||
}
|
||||
}
|
||||
else if (!strcmp (*argv, "--timeout"))
|
||||
{
|
||||
argc--; argv++;
|
||||
if (argc)
|
||||
{
|
||||
timeout = strtoul (*argv, NULL, 10);
|
||||
argc--; argv++;
|
||||
}
|
||||
}
|
||||
else if (!strcmp (*argv, "--no-verify"))
|
||||
{
|
||||
no_verify = 1;
|
||||
|
@ -407,6 +418,9 @@ main (int argc, char **argv)
|
|||
http_release_parsed_uri (uri);
|
||||
uri = NULL;
|
||||
|
||||
if (session)
|
||||
http_session_set_timeout (session, timeout);
|
||||
|
||||
rc = http_open_document (&hd, *argv, NULL, my_http_flags,
|
||||
NULL, session, NULL, NULL);
|
||||
if (rc)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue