[comp.emacs] select

jtsillas@sprite.ma30.bull.com (James Tsillas) (05/29/91)

I am having a few problem building emacs using Thomas Roell's X386 (X11R4)
libraries on our SCO systems. It seems the problem is based on the use of
HAVE_SELECT. When I build emacs with HAVE_SELECT it fails when trying to
read from a child process such as 'shell' or 'gnus-tcp'. When I build 
without HAVE_SELECT emacs cannot read from my keyboard. I am using 
SCO Dev.Kit. 3.2.1. 

Any help on this is greatly appreciated and thanks to Thomas for his great
libs.

-Jim.

--
 == James Tsillas                    Bull HN Information Systems Inc. ==
 == (508) 294-2937                   300 Concord Road   826A          ==
 == jtsillas@bubba.ma30.bull.com     Billerica, MA 01821              ==
 ==                                                                   ==
 == The opinions expressed above are solely my own and do not reflect ==
 == those of my employer.                                             ==
		    -== no solicitations please ==-

root@ttsi.lonestar.org (System) (06/01/91)

In article <JTSILLAS.91May29084756@sprite.ma30.bull.com> jtsillas@sprite.ma30.bull.com (James Tsillas) writes:
>
>I am having a few problem building emacs using Thomas Roell's X386 (X11R4)
>libraries on our SCO systems. It seems the problem is based on the use of
>HAVE_SELECT. When I build emacs with HAVE_SELECT it fails when trying to
>read from a child process such as 'shell' or 'gnus-tcp'. When I build 
>without HAVE_SELECT emacs cannot read from my keyboard. I am using 
>SCO Dev.Kit. 3.2.1. 
>

I ran into a similar if not identical problem with select and cobbled
together the following code from the X11 R4 distribution, which I
appended to sysdep.c, ifdef'ed for SCO Open Desktop.  Hope it helps.

--------------------------------- cut here -----------------------------------

#ifdef SCO_ODT
#include <sys/poll.h>

#define NOFILES_MAX 32
#define MAXSOCKS (NOFILES_MAX)
#define MSKCNT ((MAXSOCKS + 31) / 32)

#if (MSKCNT==1)
#define BITMASK(i) (1 << (i))
#define MASKIDX(i) 0
#endif
#if (MSKCNT>1)
#define BITMASK(i) (1 << ((i) & 31))
#define MASKIDX(i) ((i) >> 5)
#endif

#define MASKWORD(buf, i) buf[MASKIDX(i)]
#define BITSET(buf, i) MASKWORD(buf, i) |= BITMASK(i)
#define BITCLEAR(buf, i) MASKWORD(buf, i) &= ~BITMASK(i)
#define GETBIT(buf, i) (MASKWORD(buf, i) & BITMASK(i))


#define POLLERROR		(POLLHUP | POLLNVAL | POLLERR)
#define PFD(fds, i, x) \
{ \
	if (fds) \
		if (ev & (x)) \
			BITSET (fds, i); \
		else \
			BITCLEAR (fds, i); \
}
#define ERROR(x) \
{ \
	errno = x; \
	return -1; \
}
/*
	simulate BSD select system call with SYSV poll system call
	note that efds parameter is not fully supported (or understood)
*/

extern long ulimit();

int
select (nfds, rfds, wfds, efds, timeout)
int nfds;
unsigned long *rfds;
unsigned long *wfds;
unsigned long *efds;
struct timeval *timeout;
{
	int i, rc, ev, timevalue;
	struct pollfd pfds[NOFILES_MAX];
	static long _NOFILE = 0;

	if (_NOFILE == 0)
		_NOFILE = ulimit(4, (long)0);

 	if (nfds > _NOFILE)
		nfds = _NOFILE;   /* make poll happy */

	for (i = 0; i < nfds; i++)
	{
		ev = 0;

		if (rfds && GETBIT (rfds, i)) ev |= POLLIN;
		if (wfds && GETBIT (wfds, i)) ev |= POLLOUT;
		if (ev || (efds && GETBIT (efds, i)))
			pfds[i].fd = i;
		else
			pfds[i].fd = -1;
		pfds[i].events = ev;
	}
	if (timeout)
		timevalue = timeout->tv_sec * 1000 + timeout->tv_usec / 1000;
	else
		timevalue = -1;

	if ((rc = poll (pfds, (unsigned long)nfds, timevalue)) > 0)
	{
		if (!efds)
			for (i = 0; i < nfds; ++i)
			{
				ev = pfds[i].revents;
				if (ev & POLLERROR)
					ERROR (EBADF);
			}

		for (i = 0; i < nfds; ++i)
		{
			ev = pfds[i].revents;
			PFD (rfds, i, POLLIN);
			PFD (wfds, i, POLLOUT);
			PFD (efds, i, POLLERROR);
		}
	}
	return rc;
}

#endif /* SCO_ODT */

-- 
Mark S. Evans                 Tandem Telecommunications Systems Inc.
Phone: 214-516-6201           850 E. Central Parkway
Fax:   214-516-6801           Plano, TX 75074
Mail:  mse@ttsi.lonestar.org