
#include "V_S_UC.h"
/*
#include "pktime.h"
*
* Learning why select() is failing can be an insane task ...
*/
	global int dbn_select = 0;	/* Select counter */

d_select(n,r,w,x,t)
	int  n;
	U32 *r, *w, *x;
	TIMV*t;
{	int  v;
	int  ss, ms, us;
	fd_set *rp,*wp,*xp;
	long t0, t1;
	int   e=0;
	Fenter("Select");
	V6S "(n=%d,r=%08lX,w=%08lX,x=%08lX,t=%08lX)",n,r,w,x,t D;
	ss = t ? t->tv_sec : 0;
	us = t ? t->tv_usec : 0;
	ms = t ? us / 1000 : 0;
	if (r)
		V6S "rmask=%08X",*r D;
	if (w)
		V6S "wmask=%08X",*w D;
	if (x)
		V6S "emask=%08X",*x D;
	if (t)
		V6S "tmout=%d.%06d",ss,us D;
	if (Vflg['S']>3) UnixTime(&t0);



	rp = (fd_set*)r;
	wp = (fd_set*)w;
	xp = (fd_set*)x;
	errno = 0;

	v = select(n,rp,wp,xp,t);
	e = errno;



	++dbn_select;

	if (Vflg['S']>3) UnixTime(&t1);
	V6S "select(%d,%06lX,%06lX,%06lX,%06lX)=%d [Err %d=%s=%s]"
		,n,r,w,x,t,v,Errinfo D;
	if (t && (Vflg['S'] > 5) && ((t1 - t0) < ss))
		V6S "select(%d,...,%d.%03d)=%d after %d sec [Err %d=%s]",
			n,ss,ms,v,t1-t0,Errinfo D;
	if (r && *r)
		V6S "Return rmask=%08X",*r D;
	if (w && *w)
		V6S "Return wmask=%08X",*w D;
	if (x && *x)
		V6S "Return emask=%08X",*x D;
	V6S "Return %d after %d seconds.",v,t1-t0 D;
	errno = e;
	Fexit;
	return v;
}
