-/*
- * Return a random connection that hasn't been serviced yet and
- * is eligible for discard. There is a one in qlen chance that
- * we will return a null, saying that there are no dropable
- * requests. In this case, the protocol specific code should drop
- * the new request. This insures fairness.
- *
- * This may be used in conjunction with protocol specific queue
- * congestion routines.
- */
-struct socket *
-sodropablereq(head)
- register struct socket *head;
-{
- struct socket *so, *sonext = NULL;
- unsigned int i, j, qlen;
- static int rnd;
- static struct timeval old_runtime;
- static unsigned int cur_cnt, old_cnt;
- struct timeval tv;
-
- microtime(&tv);
- if ((i = (tv.tv_sec - old_runtime.tv_sec)) != 0) {
- old_runtime = tv;
- old_cnt = cur_cnt / i;
- cur_cnt = 0;
- }
-
- so = TAILQ_FIRST(&head->so_incomp);
- if (!so)
- return (NULL);
-
- qlen = head->so_incqlen;
- if (++cur_cnt > qlen || old_cnt > qlen) {
- rnd = (314159 * rnd + 66329) & 0xffff;
- j = ((qlen + 1) * rnd) >> 16;
-//###LD To clean up
- while (j-- && so) {
-// if (in_pcb_checkstate(so->so_pcb, WNT_ACQUIRE, 0) != WNT_STOPUSING) {
- socket_lock(so, 1);
- sonext = TAILQ_NEXT(so, so_list);
-// in_pcb_check_state(so->so_pcb, WNT_RELEASE, 0);
- socket_unlock(so, 1);
- so = sonext;
- }
- }
-
-// if (in_pcb_checkstate(so->so_pcb, WNT_ACQUIRE, 0) == WNT_STOPUSING)
-// return (NULL);
-// else
- return (so);
-}
-