diff options
| author | Sam Varshavchik | 2020-04-07 00:05:02 -0400 | 
|---|---|---|
| committer | Sam Varshavchik | 2020-04-07 00:06:31 -0400 | 
| commit | 9cef0af75486f68720a813b03ec8e69848c6b04a (patch) | |
| tree | 3e622d22162ae4bb278c1efe20e920dfca9967ae /rfc1035/rfc1035udp.c | |
| parent | e7b9dfe7c3f940625941ca725d403677c744c671 (diff) | |
| download | courier-libs-9cef0af75486f68720a813b03ec8e69848c6b04a.tar.bz2 | |
Refactor rfc1035_query_udp (2/2).
Adds rfc1035_udp_query_multi(). rfc1035_query_udp is just a wrapper for it,
now.
Diffstat (limited to 'rfc1035/rfc1035udp.c')
| -rw-r--r-- | rfc1035/rfc1035udp.c | 67 | 
1 files changed, 40 insertions, 27 deletions
| diff --git a/rfc1035/rfc1035udp.c b/rfc1035/rfc1035udp.c index 91fbe3c..c128efd 100644 --- a/rfc1035/rfc1035udp.c +++ b/rfc1035/rfc1035udp.c @@ -195,60 +195,73 @@ unsigned     buflen=sizeof(rfc1035_buf);  	return (0);  } -static char *rfc1035_recv_udp(int fd, -	const struct sockaddr *addrshouldfrom, int addrshouldfrom_len, -			      int *buflen, const char *query, -			      unsigned query_len) +char *rfc1035_query_udp(struct rfc1035_res *res, +	int fd, const struct sockaddr *sin, int sin_len, +	const char *query, unsigned query_len, int *buflen, unsigned w)  {  	struct rfc1035_udp_query_responses *resps=  		rfc1035_udp_query_response_alloc(&query, &query_len, 1); +	char *bufptr=0;  	if (!resps)  		return 0; -	if (rfc1035_recv_one_udp_response(fd, -					  addrshouldfrom, -					  addrshouldfrom_len, -					  resps)) +	if (rfc1035_udp_query_multi(res, fd, sin, sin_len, resps, w))  	{ -		char *bufptr=resps->queries[0].response; - +		bufptr=resps->queries[0].response;  		*buflen=resps->queries[0].resplen; -  		resps->queries[0].response=0; -		rfc1035_udp_query_response_free(resps); -		return bufptr;  	}  	rfc1035_udp_query_response_free(resps); - -	return NULL; +	return bufptr;  } -char *rfc1035_query_udp(struct rfc1035_res *res, -	int fd, const struct sockaddr *sin, int sin_len, -	const char *query, unsigned query_len, int *buflen, unsigned w) +int rfc1035_udp_query_multi(struct rfc1035_res *res, +			    int fd, const struct sockaddr *sin, int sin_len, +			    struct rfc1035_udp_query_responses *qr, +			    unsigned w)  {  time_t current_time, final_time; -char	*rc; +int     i;  	time(¤t_time); -	if (rfc1035_send_udp(fd, sin, sin_len, query, query_len)) -		return (0); +	for (i=0; i<qr->n_queries; ++i) +	{ +		if (qr->queries[i].response) +			continue; /* Already sent it */ +		if (rfc1035_send_udp(fd, sin, sin_len, +				     qr->queries[i].query, +				     qr->queries[i].querylen)) +			return (0); +	}  	final_time=current_time+w; -	while (current_time < final_time) +	while (1)  	{ -		if (rfc1035_wait_reply(fd, final_time-current_time)) +		for (i=0; i<qr->n_queries; ++i) +			if (!qr->queries[i].response) +				break; + +		if (i == qr->n_queries) +			return 1; /* Everything received */ + +		if (current_time >= final_time)  			break; -		rc=rfc1035_recv_udp(fd, sin, sin_len, buflen, -				    query, query_len); -		if (rc)	return (rc); +		if (rfc1035_wait_reply(fd, final_time-current_time)) +			break; -		if (errno != EAGAIN)	break; +		if (!rfc1035_recv_one_udp_response(fd, +						   sin, +						   sin_len, +						   qr)) +		{ +			if (errno != EAGAIN) +				return 0; +		}  		time(¤t_time);  	} | 
