Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!gatech!udel!burdvax!bbking!bcarb From: bcarb@KSP.Unisys.COM (Brian Carb) Newsgroups: comp.windows.x Subject: Re: unix System V Summary: Use FIONREAD to Check for Socket Data Keywords: TCP/IP, socket, non-blocking Message-ID: <700@bbking.KSP.Unisys.COM> Date: 8 Jun 89 15:16:44 GMT References: <8906021126.AA04281@wheat-chex.ai.mit.edu> Distribution: usa Organization: Unisys/Knowledge Systems Projects, Frazer, PA Lines: 33 >> We are working with Compac 386 using X-window version 11 >> release III and unix system V of Interactive. When we >> use AtAddInput over a pipe there is an error "select failed" with >> ... >You lose. System V doesn't have a general way of implementing a >select() function that works on all possible kinds of file descriptors >(there is no "real" non-blocking I/O, i.e., something that would let >you distinguish EOF from no-data-available, and there is no general >way of finding out how much data is available on a file descriptor). >.. >A hack to get around this problem is to do a read() on the file >descriptor you are interested in and use an alarm() call to time out We use the following code on a Unisys 6000/50 (Convergent) running System V to check if data is available on a socket: /* Function to check if data exists on a TCP/IP socket */ #include #include int socketlisten(fd) int fd; { int chars_available; if(ioctl(fd,FIONREAD,(char *)&chars_available) < 0) return(-1); else return(chars_available); } bcarb@ksp.unisys.com (Brian A. Carb)