STREAMS/UX for the HP 9000 Reference Manual
162
Debugging STREAMS/UX Modules and Drivers
STREAMS/UX Debugging Tool
The user changes sp_timeout() to check if the list is empty, and sets
private->last_mp to 0 if it is. The corrected function is shown below.
static sp_timeout(private)
struct sp *private;
{
mblk_t *temp;
unsigned int s;
/* Make sure driver isn't being closed. */
if ((private->sp_state & SPOPEN) && (private->first_mp)) {
/* Take message off head of queue in private data structure. */
temp = private->first_mp;
private->first_mp = private->first_mp->b_next;
/* The following statement fixes the bug. */
if (private->first_mp == NULL) private->last_mp = NULL;
temp->b_next = NULL;
/* Call putq to put message on sp's read queue and send it upstream.
*/
putq(private->sp_rdq, temp);
}
}
Example 3: Simple Application Programming Error
In this example, the user writes a test program for the stream described in
Example 1. The test program opens several of these STREAMS/UX and
execs two processes, one that loops doing putmsgs() and another that loops
doing getmsgs(). The test prints a message to the terminal each time it
successfully receives 100 STREAMS/UX messages. Some code fragments
are shown below.
Put Process
/* Initialize the stream and poll structures */
for (i=0; i<stream_count; i++) {
upper_fd[i].fd = i + OPEN_FILES;
upper_fd[i].events = POLLOUT;
.
.
.
}
/* Loop polling to see which STREAMS are writable and writing to them */
while (1) {
if (poll(upper_fd, stream_count, -1) <= 0) {
err_handler(“Poll returned error %d.\n”,errno);
}
for (i=0; i < stream_count; i++) {
if (upper_fd[i].revents) {
do_a_put(&(str_ctl[i]), &(upper_fd[i]));
} /* if */
} /* for */