NIO CommKit Host Interface Installation and System Administration Manual

6-27
Porting CommKit Applications To Release 4.x
Examples
Figure 6-8 isdkclosed, isdkeof, isdkleveld Example
1/*
2 ** Read from VCS connection.
3 ** Return value
4 ** nread > 0, number of bytes read.
5 ** nread == 0, circuit has been closed.
6 ** nread == EOF, level-D EOF received.
7 ** nread < 0 (other than EOF), nread is ~errno.
8 ** Note: Real zero length reads and level-D codes
9 ** other than EOF are not returned by this function.
10 */
11 #include <stdio.h>
12 #include <errno.h>
13
14 vcs_read(ds)
15 {
16 static char rbuf(BUFSIZ);
17 extern int errno;
18 int nread;
19
20 for (;;) {
21
22 nread = read(ds, rbuf, BUFSIZ);
23
24 if( nread > 0 ) {
25 break;
26 }
27 if( nread < 0 ) {
28 if( errno == EBADMSG ) {
29 if ( isdkeof(ds) ) {
30 nread = EOF;
31 break;
32 }
33 if ( isdkleveld(ds) ) {
34 continue;
35 }
36 }
37 nread = -errno;
38 break;
39 }
40 if ( (nread ++0) && !(isdkclosed(ds)) ) {
41 continue;
42 }
43 else{
44 break;
45 }
46 }
47 return nread;
48 }