# Terminating and shutting down

After a fax session completes, the application must release the call and tear down or reset any document queues.

A normal fax session ends with the transmitter sending the DCN (disconnect) frame, signaling the remote fax terminal to disconnect. Some fax terminals disconnect the call before they receive or transmit the DCN frame. Under these conditions, the NaturalFax application receives an NCCEVN_CALL_DISCONNECTED event before it receives the NFXEVN_SESSION_DONE event.

The application should wait for the NFXEVN_SESSION_DONE event, and then release the call as usual. The NFXEVN_SESSION_DONE event contains a CTA_REASON_RELEASED or CTA_REASON_FINISHED reason code. Refer to nfxReceiveFax for more information.

A NaturalFax fax session terminates differently if the application terminating the fax is the:

- Natural Call Control service or NMS ISDN for Natural Call Control service (layer 4)

- NMS ISDN Messaging API

Terminating application | Termination type | The application...
Natural Call Control service or NMS ISDN for Natural Call Control | Normal | Receives NFXEVN_SESSION_DONE with reason code CTA_REASON_FINISHED and issues nccDisconnectCall.
Abnormal | Receives NFXEVN_SESSION_DONE with reason code CTA_REASON_RELEASED (or other error) and issues nccDisconnectCall.
Application-initiated | Calls nfxStopSession and waits for NFXEVN_SESSION_DONE with reason code CTA_REASON_STOPPED. It then calls nccDisconnectCall.
NMS ISDN Messaging | Normal | Receives NFXEVN_SESSION_DONE with reason code CTA_REASON_FINISHED and issues a clear request (ACU_CLEAR_RQ).
Abnormal | Receives a clear indication (ACU_CLEAR_IN) and issues nfxStopSession. It then waits for NFXEVN_SESSION_DONE. The application issues a clear response (ACU_CLEAR_RS). Or, the application receives a clear confirmation (ACU_CLEAR_CO) and issues nfxStopSession. It then waits for NFXEVN_SESSION_DONE.
Application-initiated | Calls nfxStopSession and waits for NFXEVN_SESSION_DONE with reason code CTA_REASON_STOPPED. The application issues a clear request (ACU_CLEAR_RQ).

For information about releasing and terminating calls, refer to the ADI Service Developer's Reference Manual, NMS ISDN for Natural Call Control Developer's Manual, and NMS ISDN Messaging API Developer's Reference Manual.

## Tearing down or resetting a document queue

A NaturalFax application can initiate multiple fax sessions during its execution, either simultaneously or in a series, according to the programming model used. It can also reset a document queue and use it again in a subsequent fax session.

Call nfxDestroyQueue to destroy a document queue.

To use a document queue after it successfully transmits or receives a fax, call nfxResetQueue. Resetting a send queue resets the flags for each page of each of its component documents from sent to unsent. Resetting a receive queue changes it to a send queue, with all its component documents flagged as unsent. Once a receive queue is changed to a send queue, it cannot be changed back to a receive queue.