STREAMS Programming Guide

close Routine

The close routine of devices is called only during the last close of the device. Module close routines are called during the last close or if the module is popped.

The syntax of the close entry point is:

int prefix close (queue *q, int flag, cred_t * cred_p)

q is a pointer to the read queue of the module. flag is analogous to the oflag parameter of the open entry point. If FNBLOCK or FNDELAY is set, then the module should attempt to avoid blocking during the close. cred_p is a pointer to the user credential structure.

Like open, the close entry point has user context and can block. Likewise, the blocking routines should return in the event of a signal. Device drivers must take into consideration that interrupts are not blocked during close. The close routine must cancel all pending timeout(9F) and qbufcall(9F) callbacks, and process any remaining data on its service queue.

The open and close procedures are only used on the read side of the queue and can be set to NULL in the write-side qinit structure initialization. Example 7-3 shows an example of a module close routine.

Example 7-2 Example of a Module Close

/* example of a module close */
static int
xx_close(queue_t *, *rq, int flag, cred_t *credp)
		struct xxstr   *xxp;
    * Disable xxput() and xxsrv() procedures on this queue.
		xxp = (struct xxstr *) rq->q_ptr;

    * Cancel any pending timeout.
    * This example assumes that the timeout was issued
    * against the write queue.

		if (xxp->xx_timeoutid != 0) {
			(void) quntimeout(WR(rq), xxp->xx_timeoutid);
    * Cancel any pending bufcalls.
    * This example assumes that the bufcall was issued
    * against the write queue.
		if (xxp->xx_bufcallid !=0) {
			(void) qunbufcall(WR(rq), xxp->xx_bufcallid);
 		xxp->xx_bufcallid = 0;
		rq->q_ptr = WR(rq)->q_ptr = NULL;

    * Free resources allocated during open
		kmem_free (xxp, sizeof (struct xxstr));
		return (0);