7.5.1 Example: Ending a Simple Conversation

The following figure shows a simple conversation between A and B that terminates gracefully.

Figure 7-2 Simple Conversation Terminated Gracefully


Simple Conversation Terminated Gracefully Diagram

The program flow is as follows:

  1. A sets up the connection by calling tpconnect() with the TPSENDONLY flag set, indicating that process B is on the receiving end of the conversation.
  2. A turns control of the connection over to B by calling tpsend() with the TPRECVONLY flag set, resulting in the generation of a TPEV_SENDONLY event.
  3. The next call by B to tprecv() returns a value of -1, sets tperrno(5) to TPEEVENT, and returns TPEV_SENDONLY in the revent argument, indicating that control has passed to B.
  4. B calls tpreturn() with rval set to TPSUCCESS. This call generates a TPEV_SVCSUCC event for A and gracefully brings down the connection.
  5. A calls tprecv(), learns of the event, and recognizes that the conversation has been terminated. Data can be received on this call to tprecv() even if the event is set to TPEV_SVCFAIL.

Note:

In this example, A can be either a client or a server, but B must be a server.