summaryrefslogtreecommitdiffstats
path: root/lib/libc/net/getservbyport.c
diff options
context:
space:
mode:
authorwpaul <wpaul@FreeBSD.org>1996-06-01 04:40:42 +0000
committerwpaul <wpaul@FreeBSD.org>1996-06-01 04:40:42 +0000
commitf96a6bec7fc3dcdc42d9d842779178e93798aac2 (patch)
tree88a15fae0931f2ee7da2910b94f61e8f0d043458 /lib/libc/net/getservbyport.c
parenta90d30f14691d10790925c99a7bcc9921319d21e (diff)
downloadFreeBSD-src-f96a6bec7fc3dcdc42d9d842779178e93798aac2.zip
FreeBSD-src-f96a6bec7fc3dcdc42d9d842779178e93798aac2.tar.gz
Improve NIS performace of getservbyname() and getservbyport(). Both these
functions are implimented as wrappers around getservent(), which means it's up to getservent() to do all the work. The NIS support in getservent() only allows it to scan through the services.byname map one entry at a time until it finds the requested service name/port. This can be painfully slow due to the overhead involved (lots and lots of successive RPCs). To fix this, we allow getservbyname() and getservbyport() to signal getservent() that if NIS is turned on (there's a '+' in /etc/services), the usual yp_first()/yp_next() linear search should be abandoned and yp_match() used instead. This causes getservent() to immediately locate the requested entry instead of wasting time groping through the whole map. The downside is that this trick is accomplished by exporting a couple of pointers from getservent.c which getservbyname.c and getservbyport.c can preset in order to tell getservent() what to do. If all three functions were in the same source module, then the extra cruft could be delcared static to avoid poluting the global symbol space. Maybe they should be combined anyway. For now I've settled on prepending lots of underscores.
Diffstat (limited to 'lib/libc/net/getservbyport.c')
-rw-r--r--lib/libc/net/getservbyport.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/libc/net/getservbyport.c b/lib/libc/net/getservbyport.c
index 0acb31b..a24f8df 100644
--- a/lib/libc/net/getservbyport.c
+++ b/lib/libc/net/getservbyport.c
@@ -47,6 +47,14 @@ getservbyport(port, proto)
{
register struct servent *p;
+#ifdef YP
+ extern int ___getservbyport_yp;
+ extern char *___getservbyproto_yp;
+
+ ___getservbyport_yp = port;
+ ___getservbyproto_yp = (char *)proto;
+#endif
+
setservent(_serv_stayopen);
while (p = getservent()) {
if (p->s_port != port)
@@ -56,5 +64,11 @@ getservbyport(port, proto)
}
if (!_serv_stayopen)
endservent();
+
+#ifdef YP
+ ___getservbyport_yp = 0;
+ ___getservbyproto_yp = NULL;
+#endif
+
return (p);
}
OpenPOWER on IntegriCloud