5.12 Closing a Connection Endpoint

Figure 5.13 shows how a kernel-mode client closes a connection endpoint.

Figure 5.13 Closing a Local-Node Connection Endpoint

After an endpoint-to-endpoint connection has been disconnected, as already described in Section 5.11, a client can close the connection endpoint.

When a client no longer has any use for an open connection endpoint, it must close that connection endpoint as follows:

·Pass the file object pointer returned by ObReferenceObjectByHandle to ObDereferenceObject.

·Pass the file handle that was returned by ZwCreateFile when the connection endpoint was opened to ZwClose.

Then, the I/O Manager submits IRPs to the transport's TdiDispatchCleanup and, subsequently, TdiDispatchClose routines.

These transport routines immediately close the connection endpoint and free all associated transport driver resources. TdiDispatchCleanup also terminates any active connection involved with the endpoint by sending a disconnect notification to the corresponding remote-node transport.

As the preceding sentence implies, it is unnecessary for a TDI client to disassociate the connection endpoint from its associated transport address before making a close-connection-endpoint request. If necessary, the underlying transport driver simulates the effects of a disassociation.

However, a client can explicitly disassociate a connection endpoint from an open transport address before closing the connection endpoint by making a TDI_DISSOCIATE_ADDRESS request to the transport, set up with TdiBuildDisassociateAddress.

For example, a client might make a disassociate-address request and reassociate the open connection endpoint with another open transport address.