I need a SysV select()
Clemens Schrimpe
csch at tmpmbx.UUCP
Sun May 22 06:10:31 AEST 1988
jpayne at cs.rochester.edu (Jonathan Payne) writes:
{}
{} Hi. The simple version of my question is, is there an equivalent
{} function in SysV for BSD's select()?
{}
{} If the answer is no, here's what I am trying to do. I want to get input
{} from either the keyboard or from some other file description. I don't
{} want to sit around polling the two, because that would be ridiculous. Is
{} there any reasonable way to do that on SysV? (Actually, the question
{} should be, is there anyway to do that on non-bsd systems?)
1) The answer is NO :-(
2) The answer is YES :-)
There is a way to work around that problem - but not unless
you are willing to hack your kernel.
One possible way is to build a device-driver, if you don't have
tha capability to hack the list of system calls.
OK: Here're my thoughts:
Reduced to the main problem, the thing you'd like to know is,
whether a read/write on a filedescriptor will block or not.
Having a way to determine this, you can write a simple loop in
the kernel checking this for each fd requested and if nothing
happened, goto sleep by either using delay() or timeout(), sleep(),
wakeup().
/* arg contains a bitmask as in BSD-select(2) */
for (;;)
{
mask = 0;
for (fd=0; fd < 8*sizeof(arg); ++fd)
{
if ( !(arg & (1<<fd)))
continue;
if (check(fd))
mask |= 1<<fd;
}
if (mask)
return(mask);
delay(Hz/10); /* 1/10 sec idle */
}
OK - now: how to determine, if there is data available on a fd;
Having the fd, you can step into the list in the user-structure
named u.u_ofile[], which is of type filep_t. In the file-structure
you'll find a pointer to the related inode-structure.
OK - if you have this, you can now determine the TYPE of the file:
- An ordinary file is always read/writeable - mark this fd!
- A named pipe is readable, if it's size stated in the inode-structure
is >0 and writeable if it's size is less then than the maximum size
of a named pipe (10240 on Xenix ???).
- A character-device is more difficult:
*** The facts stated from hereon in the posting refer to the behavior
*** of SCO Xenix 2.2 and are not neccessarily compatible with SYS V!
The device, to which the fd belongs to could be found out by
getting the major and minor device numbers out of the first to bytes
in the block-list of the above named inode-structure. Having the major
device number you can look up the array of tty-structures from the
cdevsw[] table.
Now you index that array with the minor device number and finally get
the tty-structure. (Uff :-)
Having this you can look, how many bytes are pending in the in/output
queues and decide, what to do.
NOTE: This is no fun - even if you have device drivers, indexing
their tty-structures not with the minor device number. And
that's mostly the case, where higher bits the minor-# state
the type of device being used.
If you only want to know about the availability of data on the
controlling tty, you should refer to the related tty-structre
via the pointer provided in the user-structure named u.u_ttyp!
Not an easy way - isn't it ???? ]:-}
AGAIN: These are only thoughts - I tried all this and it all works on SCO,
but I never (!!!) made a complete select() out of this. So all
the stuff was only used fragmentarily.
For those of you reading this article in comp.unix.wizards: please respond
to me via email, because comp.unix.wizards is often too full for me so I
skip many articles ...
Clemens Schrimpe, netmbx GbR (Berlin, West-Germany)
UUCP: csch at tmpmbx = Europe: ...!unido!tmpmbx!csch, USA: ...!pyramid!tmpmbx!csch
BITNET: csch at db0tui6 csch at tub.BITNET
PHONE: +49-30-332 40 15
FAX: +49-30-361 40 93
TELEX: (066)+186672 net d
BTX: 0303325016-0003
MODEM: +49-30-332 50 16 (V.22/V.22bis), +49-30-331 30 76/40 72 (V.21)
Username: gast
X.25: not stated herein (too many hackers around :-)
More information about the Comp.unix.wizards
mailing list