STREAMS/UX for the HP 9000 Reference Manual

146
Debugging STREAMS/UX Modules and Drivers
STREAMS/UX Debugging Tool
Example 1: Flow Control and Fragmentation
In this example, the user has written a loopback driver which uses the qreply
STREAMS/UX utility to send all incoming messages up to the stream head
read queue.
Figure 2 Stream Created By Opening Loopback (lo) Driver
The user writes a simple test for the driver. The test opens lo, writes data to
it, reads the data, and then closes the driver. The program is shown below.
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
main()
{
char wbuf[1024];
char rbuf[1024];
int fd, i, n, cnt;
printf(“Open the loopback driver.\n”);
fd = open(“/dev/lo0”, O_RDWR);
Read Queue
Write Queue
Read Queue
Write Queue
Stream Head
lo driver
qreply moves
message to
stream head
lo_write_put(q,m) ; lo_write_srv(q) ;
if m not hipri if stream head not flow controlled
putq qreply
else else
qreply putbq