Blame SOURCES/libtirpc-1.1.4-dos-fix.patch

cb1c4e
diff --git a/src/rpc_com.h b/src/rpc_com.h
cb1c4e
index 10bec79..76badef 100644
cb1c4e
--- a/src/rpc_com.h
cb1c4e
+++ b/src/rpc_com.h
cb1c4e
@@ -61,8 +61,7 @@ void __xprt_unregister_unlocked(SVCXPRT *);
cb1c4e
 void __xprt_set_raddr(SVCXPRT *, const struct sockaddr_storage *);
cb1c4e
 
cb1c4e
 
cb1c4e
-SVCXPRT **__svc_xports;
cb1c4e
-int __svc_maxrec;
cb1c4e
+extern int __svc_maxrec;
cb1c4e
 
cb1c4e
 #ifdef __cplusplus
cb1c4e
 }
cb1c4e
diff --git a/src/svc.c b/src/svc.c
cb1c4e
index b59467b..3a8709f 100644
cb1c4e
--- a/src/svc.c
cb1c4e
+++ b/src/svc.c
cb1c4e
@@ -57,6 +57,9 @@
cb1c4e
 
cb1c4e
 #define max(a, b) (a > b ? a : b)
cb1c4e
 
cb1c4e
+SVCXPRT **__svc_xports;
cb1c4e
+int __svc_maxrec;
cb1c4e
+
cb1c4e
 /*
cb1c4e
  * The services list
cb1c4e
  * Each entry represents a set of procedures (an rpc program).
cb1c4e
@@ -191,6 +194,21 @@ __xprt_do_unregister (xprt, dolock)
cb1c4e
     rwlock_unlock (&svc_fd_lock);
cb1c4e
 }
cb1c4e
 
cb1c4e
+int
cb1c4e
+svc_open_fds()
cb1c4e
+{
cb1c4e
+	int ix;
cb1c4e
+	int nfds = 0;
cb1c4e
+
cb1c4e
+	rwlock_rdlock (&svc_fd_lock);
cb1c4e
+	for (ix = 0; ix < svc_max_pollfd; ++ix) {
cb1c4e
+		if (svc_pollfd[ix].fd != -1)
cb1c4e
+			nfds++;
cb1c4e
+	}
cb1c4e
+	rwlock_unlock (&svc_fd_lock);
cb1c4e
+	return (nfds);
cb1c4e
+}
cb1c4e
+
cb1c4e
 /*
cb1c4e
  * Add a service program to the callout list.
cb1c4e
  * The dispatch routine will be called when a rpc request for this
cb1c4e
diff --git a/src/svc_vc.c b/src/svc_vc.c
cb1c4e
index c23cd36..1729963 100644
cb1c4e
--- a/src/svc_vc.c
cb1c4e
+++ b/src/svc_vc.c
cb1c4e
@@ -64,6 +64,8 @@
cb1c4e
 
cb1c4e
 
cb1c4e
 extern rwlock_t svc_fd_lock;
cb1c4e
+extern SVCXPRT **__svc_xports;
cb1c4e
+extern int svc_open_fds();
cb1c4e
 
cb1c4e
 static SVCXPRT *makefd_xprt(int, u_int, u_int);
cb1c4e
 static bool_t rendezvous_request(SVCXPRT *, struct rpc_msg *);
cb1c4e
@@ -82,6 +84,7 @@ static void svc_vc_ops(SVCXPRT *);
cb1c4e
 static bool_t svc_vc_control(SVCXPRT *xprt, const u_int rq, void *in);
cb1c4e
 static bool_t svc_vc_rendezvous_control (SVCXPRT *xprt, const u_int rq,
cb1c4e
 				   	     void *in);
cb1c4e
+static int __svc_destroy_idle(int timeout);
cb1c4e
 
cb1c4e
 struct cf_rendezvous { /* kept in xprt->xp_p1 for rendezvouser */
cb1c4e
 	u_int sendsize;
cb1c4e
@@ -312,13 +315,14 @@ done:
cb1c4e
 	return (xprt);
cb1c4e
 }
cb1c4e
 
cb1c4e
+
cb1c4e
 /*ARGSUSED*/
cb1c4e
 static bool_t
cb1c4e
 rendezvous_request(xprt, msg)
cb1c4e
 	SVCXPRT *xprt;
cb1c4e
 	struct rpc_msg *msg;
cb1c4e
 {
cb1c4e
-	int sock, flags;
cb1c4e
+	int sock, flags, nfds, cnt;
cb1c4e
 	struct cf_rendezvous *r;
cb1c4e
 	struct cf_conn *cd;
cb1c4e
 	struct sockaddr_storage addr;
cb1c4e
@@ -378,6 +382,16 @@ again:
cb1c4e
 
cb1c4e
 	gettimeofday(&cd->last_recv_time, NULL);
cb1c4e
 
cb1c4e
+	nfds = svc_open_fds();
cb1c4e
+	if (nfds >= (_rpc_dtablesize() / 5) * 4) {
cb1c4e
+		/* destroy idle connections */
cb1c4e
+		cnt = __svc_destroy_idle(15);
cb1c4e
+		if (cnt == 0) {
cb1c4e
+			/* destroy least active */
cb1c4e
+			__svc_destroy_idle(0);
cb1c4e
+		}
cb1c4e
+	}
cb1c4e
+
cb1c4e
 	return (FALSE); /* there is never an rpc msg to be processed */
cb1c4e
 }
cb1c4e
 
cb1c4e
@@ -819,3 +833,49 @@ __svc_clean_idle(fd_set *fds, int timeout, bool_t cleanblock)
cb1c4e
 {
cb1c4e
 	return FALSE;
cb1c4e
 }
cb1c4e
+
cb1c4e
+static int
cb1c4e
+__svc_destroy_idle(int timeout)
cb1c4e
+{
cb1c4e
+	int i, ncleaned = 0;
cb1c4e
+	SVCXPRT *xprt, *least_active;
cb1c4e
+	struct timeval tv, tdiff, tmax;
cb1c4e
+	struct cf_conn *cd;
cb1c4e
+
cb1c4e
+	gettimeofday(&tv, NULL);
cb1c4e
+	tmax.tv_sec = tmax.tv_usec = 0;
cb1c4e
+	least_active = NULL;
cb1c4e
+	rwlock_wrlock(&svc_fd_lock);
cb1c4e
+
cb1c4e
+	for (i = 0; i <= svc_max_pollfd; i++) {
cb1c4e
+		if (svc_pollfd[i].fd == -1)
cb1c4e
+			continue;
cb1c4e
+		xprt = __svc_xports[i];
cb1c4e
+		if (xprt == NULL || xprt->xp_ops == NULL ||
cb1c4e
+			xprt->xp_ops->xp_recv != svc_vc_recv)
cb1c4e
+			continue;
cb1c4e
+		cd = (struct cf_conn *)xprt->xp_p1;
cb1c4e
+		if (!cd->nonblock)
cb1c4e
+			continue;
cb1c4e
+		if (timeout == 0) {
cb1c4e
+			timersub(&tv, &cd->last_recv_time, &tdiff);
cb1c4e
+			if (timercmp(&tdiff, &tmax, >)) {
cb1c4e
+				tmax = tdiff;
cb1c4e
+				least_active = xprt;
cb1c4e
+			}
cb1c4e
+			continue;
cb1c4e
+		}
cb1c4e
+		if (tv.tv_sec - cd->last_recv_time.tv_sec > timeout) {
cb1c4e
+			__xprt_unregister_unlocked(xprt);
cb1c4e
+			__svc_vc_dodestroy(xprt);
cb1c4e
+			ncleaned++;
cb1c4e
+		}
cb1c4e
+	}
cb1c4e
+	if (timeout == 0 && least_active != NULL) {
cb1c4e
+		__xprt_unregister_unlocked(least_active);
cb1c4e
+		__svc_vc_dodestroy(least_active);
cb1c4e
+		ncleaned++;
cb1c4e
+	}
cb1c4e
+	rwlock_unlock(&svc_fd_lock);
cb1c4e
+	return (ncleaned);
cb1c4e
+}