Go to main content

STREAMS Programming Guide

Exit Print View

Updated: March 2019
 
 

Closing the Stream

The last close to a STREAMS device dismantles the stream. Dismantling consists of popping any modules on the stream and closing the driver. Before a module is popped, the close may delay to allow any messages on the write message queue of the module to be drained by the module processing. Similarly, before the driver is closed, the close may delay to allow any messages on the write message queue of the driver to be drained by the driver processing. If O_NDELAY or O_NONBLOCK is clear, close waits up to 15 seconds for each module to drain and up to 15 seconds for the driver to drain, The default close delay is 15 seconds. The close delay can be changed on a per-stream basis with the I_SETCLTIME ioctl. For more information, see the close(2), open(2), fcntl(2), and ioctl(2) man pages.

The close delay is independent of any delay that the module or driver's close() routine itself chooses to impose. If O_NDELAY or O_NONBLOCK is set, the pop is performed immediately and the driver is closed without delay.

Messages can remain queued, if the flow control is inhibiting execution of the write queue service procedure. When all modules are popped and any wait for the driver to drain is completed, the driver close() routine is called. On return from the driver close(), any messages left on the driver's queues are freed, and the queue and stream head structures are released.