HP X.25/9000 Programmer's Guide

Chapter 3 41
Establishing and Terminating a Socket Connection
Terminating a Connection
Terminating a Connection
When data communications activity over an SVC is completed,
terminate the connection to free network memory and other resources.
Terminating the connection also reduces communications costs since
most PDNs charge for transmission and connection time.
An SVC is terminated when a CLEAR REQUEST packet is transmitted.
A CLEAR packet can be transmitted to both ends of an SVC by the
network provider, or it can be transmitted by one of the processes using
the SVC. An X.25 application can transmit a CLEAR REQUEST packet
by issuing a close() call on the last open socket descriptor for the socket
associated with that SVC, or by issuing a shutdown() call on the socket
associated with that SVC.
When a process terminates, all open socket descriptors are closed
automatically.
Closing a Socket Descriptor
The close() system call closes a socket descriptor. If a close() is issued
on the last open socket descriptor for an SVC socket, a CLEAR
REQUEST packet is transmitted on the SVC.
If a process is no longer using a socket descriptor, it should be closed
using the close() system call. This technique prevents the SVC from
remaining connected after the last process has completed using it.
One of the design strategies described earlier suggested that a server
process monitor a listen socket and then fork a child process to handle
SVCs as they arrive. The server should close the socket descriptor for the
newly-created socket immediately after spawning the child process. This
allows the child process to close its socket descriptor and transmit a
CLEAR REQUEST packet when needed. If the server did not close its
socket descriptor, no CLEAR packet would be transmitted and the SVC
would remain connected.
Syntax for close()
The following is the syntax for the close() system call and its
parameters:
int err;
36960-90061.bk Page 41 Friday, November 10, 2000 3:42 PM