STREAMS Programming Guide

Read Device Interrupt Handler

Example 8–3 is an example of a read device interrupt handler.

Example 8–3 Device Interrupt Handler

#include <sys/types.h>
#include <sys/param.h>
#include <sys/stream.h>
buffcall_id_t id;						/* hold id val for unbufcall */

 	/* process incoming message ... */
 	/* allocate new buffer for device */

 * Reload device with a new receive buffer
 	mblk_t *bp;
 	id = 0;						/* begin with no waiting for buffers */
 	if ((bp = allocb(DEVBLKSZ, BPRI_MED)) == NULL) {
 			 * Allocation failed. Use bufcall to
 			 * schedule a call to ourselves.
 			id = bufcall(DEVBLKSZ,BPRI_MED,dev_re_load,dev);

 	/* pass buffer to device ... */

See Chapter 12, Multithreaded STREAMS for more information on the uses of unbufcall(9F). These references to unbufcall are protected by MT locks.

Because bufcall(9F) can fail, there is still a chance that the device will hang. A better strategy if bufcall(9F) fails is to discard the current input message and resubmit that buffer to the device. Losing input data is preferable to the device hanging.