NIO CommKit Host Interface Installation and System Administration Manual
6-28
Porting CommKit Applications To Release 4.x
Examples
The function vcs_read uses the read system call (line 22) to read data from
an open file descriptor ds of a data switch connection. The return value is
checked on line 24 and, if it is greater than zero, the code breaks from the
loop and returns the number of bytes read. Line 27 checks for returns less
than zero.
Line 28 tests if errno is equal to EBADMSG. The EBADMSG indicates that
the message at the head of the queue is not a data message.
Line 29 uses the isdkeof function to check for a level-D EOF code. If an
EOF code has been received, the function returns a value of true, and the
code sets the value of nread to EOF and then breaks from the loop (lines 30-
31).
If no EOF code has been received, line 33 uses the isdkleveld function to
check for any other level-D code. The isdkleveld function returns either the
level-D code or a 0. If isdkleveld returns a level-D code, the loop continues
and executes another read system call.
NOTE: Since isdkleveld returns the level-D code, you could have used isdkleveld to check
for EOF, by testing the return value with URPdEOF from the dk_urp.h header file.
For all other errors, line 37 sets the return code to the negative of the errno,
and line 38 breaks the loop.
Line 40 checks for a zero return and calls isdkclosed. If the read returned 0
bytes and the circuit is not closed, then this is a real 0-length read and the
loop continues. If the circuit is closed, the loop is broken on line 44 and a
zero is returned.
poll Example
The code fragments in Figure 6-9 show how to poll a STREAMS file
descriptor.
Figure 6-9 poll Example
1 #include <signal.h>
2 #include <poll.h>
3 #include <sys/stropts.h>
4
5 static void catchpoll();
6
7/*