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

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