[mod.computers.vax] followup on my TWG sockets question

rick@NGP.UTEXAS.EDU (Rick Watson) (12/04/85)

Here is a followup on my question from a couple of weeks ago which was:

> Does anyone know if there is a way to see if there is data ready to read
> on a socket (using TWG's IP/TCP for VMS)?  Under UNIX, you could use
> select, but TWG did not seem to implement select.  I realize I could use
> an asynchronous QIO, but I want to find out if there is a synchronous
> way to do this.

The answer that worked was:

>I believe that the flags argument on the recv() calls will do what you want.
>The MSG_PEEK flag (0x01) or'd into the flags argument will return the
>number of bytes without actually moving them.  I ran into this with a program
>bug which caused an infinite loop trying to read.  If using QIOs, I believe
>P3 is the flags argument (doesn't appear to be documented in QIO spec).

...with one addition.  If there are no bytes to read, you will block
 until there are bytes available unless you also set non-blocking.
You do this as follows:

int noblock = 1;

stat = ioctl(sock, FIONBIO, &noblock);

numbytes = recv(sock, buf, sizeof(buf), MSG_PEEK);

Now, numbytes will contain the count of bytes available or -1 and errno
= EWOULDBLOCK if there are no bytes available.  Using MSG_PEEK causes no
data to be transferred.  If you want to go ahead and get the data, use 0
for the flags instead.  Set noblock to 0 and issue the ioctl again to go
back to blocking io. Also, MSG_PEEK should be 0x02 even though it is
documented to be 0x01 in the manual (it is correct in socket.h).

Another answer I got was:

>If you are just polling to see if there is any data on the socket the
>FIONREAD ioctl works just fine.

	stat = ioctl(sock, FIONREAD, &numbytes);

This works fine on a real UNIX 4.2 system and is preferrable to the
above method, but I haven't gotten it to work under TWG IP/TCP v2.2. (It
always returns errno = ENOTTY) I have talked to TWG on the phone (no
help) and spent a lot of time using XDELTA to step through INDRIVER and
have decided that this ioctl function is either not implemented, or uses
a bogus value for FIONREAD. FIONREAD under BSD UNIX and the header files
that came with IP/TCP generate 0x4004667F for the value of FIONREAD.

The last answer:

>I'm afraid the only way to do it is to set up several asynchronous qio's and
>wait for one of their event flags (or $hiber and do all processing in ast
>routines).

...was what I was trying to avoid as it complicates my generic TCP
interface that works with either TWG or Tektronix TCP/IP.

Thanks to those who responded and pftftft to TWG's customer support. (In
all fairness, they were polite on the phone and seemed to be trying to
answer my questions, but they never have figured out an answer for me.
Their best response was "maybe" it will work in the March (or maybe
September) release. One never gets to talk to an acutal programmer that
understands what you are trying to do, only non-programmer gateways).

Rick Watson
University of Texas Computation Center
 arpa:   rick@ngp.UTEXAS.EDU   rick@ngp.ARPA
 uucp:   ...seismo!ut-sally!ut-ngp!rick   rick@ut-ngp.UUCP
 bitnet: ccaw001@utadnx
 phone:  512/471-3241