Stop polling as soon as we have the packet we were waiting for.

* include/grub/net.h (grub_net_poll_cards): New argument stop_condition.
	All users updated.
	* grub-core/net/arp.c (have_pending): New var.
	(pending_req): Likewise.
	(grub_net_arp_send_request): Fill pending_req and use have_pending as
	stop indicator.
	(grub_net_arp_receive): Set have_pending.
	* grub-core/net/dns.c (recv_data): New field stop.
	(recv_hook): Set stop.
	(grub_net_dns_lookup): Init stop and use as stop condition.
	* grub-core/net/http.c (http_establish): Use headers_recv as stop
	condition.
	* grub-core/net/net.c (grub_net_poll_cards): New argument
	stop_condition. Stop when it goes true.
	* grub-core/net/tcp.c (grub_net_tcp_open): Use `established' as stop
	indicator.
	* grub-core/net/tftp.c (tftp_open): Use `have_oack' as stop indicator.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2012-06-09 11:06:55 +02:00
parent 3e74723951
commit 96f7e60eae
10 changed files with 48 additions and 18 deletions

View file

@ -108,6 +108,7 @@ struct recv_data
int dns_err;
char *name;
const char *oname;
int stop;
};
static inline int
@ -339,6 +340,7 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)),
grub_memcpy (&(*data->addresses)[*data->naddresses].ipv4,
ptr, 4);
(*data->naddresses)++;
data->stop = 1;
break;
case DNS_CLASS_AAAA:
if (length != 16)
@ -348,6 +350,7 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)),
grub_memcpy (&(*data->addresses)[*data->naddresses].ipv6,
ptr, 16);
(*data->naddresses)++;
data->stop = 1;
break;
case DNS_CLASS_CNAME:
if (!(redirect_cnt & (redirect_cnt - 1)))
@ -425,7 +428,7 @@ grub_net_dns_lookup (const char *name,
static grub_uint16_t id = 1;
grub_err_t err = GRUB_ERR_NONE;
struct recv_data data = {naddresses, addresses, cache,
grub_cpu_to_be16 (id++), 0, 0, name};
grub_cpu_to_be16 (id++), 0, 0, name, 0};
grub_uint8_t *nbd;
int have_server = 0;
@ -573,7 +576,7 @@ grub_net_dns_lookup (const char *name,
if (*data.naddresses)
goto out;
}
grub_net_poll_cards (200);
grub_net_poll_cards (200, &data.stop);
}
out:
grub_free (data.name);