summaryrefslogtreecommitdiffstats
path: root/lib/libc/net
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>1997-06-28 04:19:52 +0000
committerpeter <peter@FreeBSD.org>1997-06-28 04:19:52 +0000
commit0e9bc076721cc9e5492fe8d0faa092eada38c0c3 (patch)
tree2b57a788388923247df85be433f3ce836c4b6d0d /lib/libc/net
parenta83cd6d7faae10bd3e364d9624acd3bf227ce3d9 (diff)
downloadFreeBSD-src-0e9bc076721cc9e5492fe8d0faa092eada38c0c3.zip
FreeBSD-src-0e9bc076721cc9e5492fe8d0faa092eada38c0c3.tar.gz
replace the OpenBSD fd_set sizing code with something more efficient.
Only call malloc() if the fd is too big for the compiled in fd_set size, and don't use calloc either. This should reduce the impact of conflicts with private malloc implementations etc. When using the fd_set on the stack, only zero what is needed rather than all 1024 bits like FD_ZERO did.
Diffstat (limited to 'lib/libc/net')
-rw-r--r--lib/libc/net/res_send.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/lib/libc/net/res_send.c b/lib/libc/net/res_send.c
index 798d0f6..9061ec6 100644
--- a/lib/libc/net/res_send.c
+++ b/lib/libc/net/res_send.c
@@ -56,7 +56,7 @@
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)res_send.c 8.1 (Berkeley) 6/4/93";
static char orig_rcsid[] = "From: Id: res_send.c,v 8.13 1997/06/01 20:34:37 vixie Exp";
-static char rcsid[] = "$Id: res_send.c,v 1.16 1997/06/27 08:22:03 peter Exp $";
+static char rcsid[] = "$Id: res_send.c,v 1.17 1997/06/27 13:00:51 peter Exp $";
#endif /* LIBC_SCCS and not lint */
/*
@@ -469,7 +469,8 @@ read_len:
* Use datagrams.
*/
struct timeval timeout;
- fd_set *dsmaskp;
+ fd_set dsmask, *dsmaskp;
+ int dsmasklen;
struct sockaddr_in from;
int fromlen;
@@ -575,16 +576,22 @@ read_len:
timeout.tv_sec = 1;
timeout.tv_usec = 0;
wait:
- dsmaskp = (fd_set *)calloc(howmany(s+1, NFDBITS),
- sizeof(fd_mask));
- if (dsmaskp == NULL) {
- res_close();
- goto next_ns;
- }
+ dsmasklen = howmany(s+1, NFDBITS) * sizeof(fd_mask);
+ if (dsmasklen > sizeof(fd_set)) {
+ dsmaskp = (fd_set *)malloc(dsmasklen);
+ if (dsmaskp == NULL) {
+ res_close();
+ goto next_ns;
+ }
+ } else
+ dsmaskp = &dsmask;
+ /* only zero what we need */
+ bzero((char *)dsmaskp, dsmasklen);
FD_SET(s, dsmaskp);
n = select(s+1, dsmaskp, (fd_set *)NULL,
(fd_set *)NULL, &timeout);
- free(dsmaskp);
+ if (dsmaskp != &dsmask)
+ free(dsmaskp);
if (n < 0) {
if (errno == EINTR)
goto wait;
OpenPOWER on IntegriCloud