1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-30 22:43:12 +03:00
2004-10-23  Ulrich Drepper  <drepper@redhat.com>

	* resolv/res_send.c (send_dg): Combine write and read to socket
	into one loop.
This commit is contained in:
Ulrich Drepper
2004-10-23 08:22:29 +00:00
parent 390c662066
commit 17a1031933
2 changed files with 134 additions and 139 deletions

View File

@ -1,3 +1,8 @@
2004-10-23 Ulrich Drepper <drepper@redhat.com>
* resolv/res_send.c (send_dg): Combine write and read to socket
into one loop.
2001-10-31 Alexandre Oliva <aoliva@redhat.com> 2001-10-31 Alexandre Oliva <aoliva@redhat.com>
* elf/elf.h: Add R_MN10300_* relocation numbers. * elf/elf.h: Add R_MN10300_* relocation numbers.

View File

@ -73,6 +73,7 @@ static const char rcsid[] = "$BINDId: res_send.c,v 8.38 2000/03/30 20:16:51 vixi
* Send query to name server and wait for reply. * Send query to name server and wait for reply.
*/ */
#include <assert.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/param.h> #include <sys/param.h>
#include <sys/time.h> #include <sys/time.h>
@ -808,7 +809,7 @@ send_dg(res_state statp,
int ptimeout; int ptimeout;
struct sockaddr_in6 from; struct sockaddr_in6 from;
static int socket_pf = 0; static int socket_pf = 0;
int fromlen, resplen, seconds, n, s; int fromlen, resplen, seconds, n;
if (EXT(statp).nssocks[ns] == -1) { if (EXT(statp).nssocks[ns] == -1) {
/* only try IPv6 if IPv6 NS and if not failed before */ /* only try IPv6 if IPv6 NS and if not failed before */
@ -854,7 +855,7 @@ send_dg(res_state statp,
Dprint(statp->options & RES_DEBUG, Dprint(statp->options & RES_DEBUG,
(stdout, ";; new DG socket\n")) (stdout, ";; new DG socket\n"))
} }
s = EXT(statp).nssocks[ns];
/* /*
* Compute time for the total operation. * Compute time for the total operation.
*/ */
@ -867,12 +868,24 @@ send_dg(res_state statp,
evConsTime(&timeout, seconds, 0); evConsTime(&timeout, seconds, 0);
evAddTime(&finish, &now, &timeout); evAddTime(&finish, &now, &timeout);
int need_recompute = 0; int need_recompute = 0;
resend: int nwritten = 0;
pfd[0].fd = EXT(statp).nssocks[ns];
pfd[0].events = POLLOUT;
wait:
if (need_recompute) {
evNowTime(&now);
if (evCmpTime(finish, now) <= 0) {
Perror(statp, stderr, "select", errno);
res_nclose(statp);
return (0);
}
evSubTime(&timeout, &finish, &now);
}
/* Convert struct timespec in milliseconds. */ /* Convert struct timespec in milliseconds. */
ptimeout = timeout.tv_sec * 1000 + timeout.tv_nsec / 1000000; ptimeout = timeout.tv_sec * 1000 + timeout.tv_nsec / 1000000;
pfd[0].fd = s; n = 0;
pfd[0].events = POLLOUT; if (nwritten == 0)
n = __poll (pfd, 1, 0); n = __poll (pfd, 1, 0);
if (__builtin_expect (n == 0, 0)) { if (__builtin_expect (n == 0, 0)) {
n = __poll (pfd, 1, ptimeout); n = __poll (pfd, 1, ptimeout);
@ -890,7 +903,7 @@ send_dg(res_state statp,
evNowTime(&now); evNowTime(&now);
if (evCmpTime(finish, now) > 0) { if (evCmpTime(finish, now) > 0) {
evSubTime(&timeout, &finish, &now); evSubTime(&timeout, &finish, &now);
goto resend; goto wait;
} }
} }
Perror(statp, stderr, "select", errno); Perror(statp, stderr, "select", errno);
@ -898,48 +911,24 @@ send_dg(res_state statp,
return (0); return (0);
} }
__set_errno (0); __set_errno (0);
if (send(s, (char*)buf, buflen, 0) != buflen) { if (pfd[0].revents & POLLOUT) {
if (send(pfd[0].fd, (char*)buf, buflen, 0) != buflen) {
if (errno == EINTR || errno == EAGAIN) if (errno == EINTR || errno == EAGAIN)
goto recompute_resend; goto recompute_resend;
Perror(statp, stderr, "send", errno); Perror(statp, stderr, "send", errno);
res_nclose(statp); res_nclose(statp);
return (0); return (0);
} }
wait:
if (need_recompute) {
evNowTime(&now);
if (evCmpTime(finish, now) <= 0) {
err_return:
Perror(statp, stderr, "select", errno);
res_nclose(statp);
return (0);
}
evSubTime(&timeout, &finish, &now);
}
/* Convert struct timespec in milliseconds. */
ptimeout = timeout.tv_sec * 1000 + timeout.tv_nsec / 1000000;
pfd[0].events = POLLIN; pfd[0].events = POLLIN;
n = __poll (pfd, 1, ptimeout); ++nwritten;
if (n == 0) {
Dprint(statp->options & RES_DEBUG, (stdout,
";; timeout receiving\n"));
*gotsomewhere = 1;
return (0);
}
if (n < 0) {
if (errno == EINTR) {
need_recompute = 1;
goto wait; goto wait;
} } else {
goto err_return; assert(pfd[0].revents & POLLIN);
}
__set_errno (0);
fromlen = sizeof(struct sockaddr_in6); fromlen = sizeof(struct sockaddr_in6);
if (anssiz < MAXPACKET if (anssiz < MAXPACKET
&& anscp && anscp
&& (ioctl (s, FIONREAD, &resplen) < 0 && (ioctl (pfd[0].fd, FIONREAD, &resplen) < 0
|| anssiz < resplen)) { || anssiz < resplen)) {
ans = malloc (MAXPACKET); ans = malloc (MAXPACKET);
if (ans == NULL) if (ans == NULL)
@ -952,7 +941,7 @@ send_dg(res_state statp,
anhp = (HEADER *) ans; anhp = (HEADER *) ans;
} }
} }
resplen = recvfrom(s, (char*)ans, anssiz,0, resplen = recvfrom(pfd[0].fd, (char*)ans, anssiz,0,
(struct sockaddr *)&from, &fromlen); (struct sockaddr *)&from, &fromlen);
if (resplen <= 0) { if (resplen <= 0) {
if (errno == EINTR || errno == EAGAIN) { if (errno == EINTR || errno == EAGAIN) {
@ -1042,6 +1031,7 @@ send_dg(res_state statp,
*/ */
return (resplen); return (resplen);
} }
}
#ifdef DEBUG #ifdef DEBUG
static void static void