From 02f90322e8fae14dedd7865394bbd3e499ef506d Mon Sep 17 00:00:00 2001 From: hniksic Date: Mon, 10 Nov 2003 05:20:46 -0800 Subject: [PATCH] [svn] Network updates. --- src/ChangeLog | 8 ++++++++ src/connect.c | 18 +++++++++++++----- src/host.c | 32 ++++++++++++++++++++------------ src/host.h | 3 ++- 4 files changed, 43 insertions(+), 18 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 8fe7b7b7..99d0478d 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2003-11-10 Hrvoje Niksic + + * connect.c (connect_to_host): Use that flag to decide whether to + re-resolve the host name. + + * host.c (struct address_list): Added a flag that maintains + whether the connection worked at some point. + 2003-11-10 Hrvoje Niksic * host.c (lookup_host): Special-case the numeric addresses only in diff --git a/src/connect.c b/src/connect.c index 3ed03c71..90729aec 100644 --- a/src/connect.c +++ b/src/connect.c @@ -356,12 +356,16 @@ connect_to_host (const char *host, int port) } address_list_release (al); - if (sock < 0 && address_list_cached_p (al)) + if (sock >= 0) + /* Mark a successful connection to one of the addresses. */ + address_list_set_connected (al); + + if (sock < 0 && address_list_connected_p (al)) { - /* We were unable to connect to any address in a list we've - obtained from cache. There is a possibility that the host is - under dynamic DNS and has changed its address. Resolve it - again. */ + /* We are unable to connect to any of HOST's addresses, although + we were previously able to connect to HOST. That might + indicate that HOST is under dynamic DNS and the addresses + we're connecting to have expired. Resolve it again. */ forget_host_lookup (host); goto again; } @@ -649,6 +653,10 @@ struct extended_info { void *ctx; }; +/* Register the handlers for operations on FD. This is meant + primarily for transport layers like SSL that piggyback on sockets, + but with their own readers, writers, etc. */ + void register_extended (int fd, xreader_t reader, xwriter_t writer, xpoller_t poller, xcloser_t closer, void *ctx) diff --git a/src/host.c b/src/host.c index 131e1414..eb0897cd 100644 --- a/src/host.c +++ b/src/host.c @@ -97,8 +97,9 @@ struct address_list { ip_address *addresses; /* pointer to the string of addresses */ int faulty; /* number of addresses known not to work. */ - int from_cache; /* whether this entry was pulled from - cache or freshly looked up. */ + int connected; /* whether we were able to connect to + one of the addresses in the list, + at least once. */ int refcount; /* reference count; when it drops to 0, the entry is freed. */ @@ -113,15 +114,6 @@ address_list_get_bounds (const struct address_list *al, int *start, int *end) *end = al->count; } -/* Return whether this address list entry has been obtained from the - cache. */ - -int -address_list_cached_p (const struct address_list *al) -{ - return al->from_cache; -} - /* Return a pointer to the address at position POS. */ const ip_address * @@ -191,6 +183,23 @@ address_list_set_faulty (struct address_list *al, int index) al->faulty = 0; } +/* Set the "connected" flag to true. This flag used by connect.c to + see if the host perhaps needs to be resolved again. */ + +void +address_list_set_connected (struct address_list *al) +{ + al->connected = 1; +} + +/* Return the value of the "connected" flag. */ + +int +address_list_connected_p (const struct address_list *al) +{ + return al->connected; +} + #ifdef ENABLE_IPV6 /** * address_list_from_addrinfo @@ -513,7 +522,6 @@ lookup_host (const char *host, int silent) { DEBUGP (("Found %s in host_name_addresses_map (%p)\n", host, al)); ++al->refcount; - al->from_cache = 1; return al; } } diff --git a/src/host.h b/src/host.h index 8666c08c..5029c9c2 100644 --- a/src/host.h +++ b/src/host.h @@ -98,11 +98,12 @@ void forget_host_lookup PARAMS ((const char *)); void address_list_get_bounds PARAMS ((const struct address_list *, int *, int *)); -int address_list_cached_p PARAMS ((const struct address_list *)); const ip_address *address_list_address_at PARAMS ((const struct address_list *, int)); int address_list_find PARAMS ((const struct address_list *, const ip_address *)); void address_list_set_faulty PARAMS ((struct address_list *, int)); +void address_list_set_connected PARAMS ((struct address_list *)); +int address_list_connected_p PARAMS ((const struct address_list *)); void address_list_release PARAMS ((struct address_list *)); const char *pretty_print_address PARAMS ((const ip_address *)); -- 2.39.2