HP X.25/9000 Programmer's Guide
32 Chapter3
Establishing and Terminating a Socket Connection
Connection Establishment for the Server Process
ioctl(X25_SEND_CALL_ACEPT) calls are used to control CALL
ACCEPTED packets (see “Controlling Call Acceptance”).
If you set up the listen socket to perform nonblocking I/O, your process
will not block. Your request will return –1, and
errno
will contain
EWOULDBLOCK. This means that there is no SVC connection request
available at that time, but the accept() call is ready to process when it
arrives. You can test the socket with ioctl(X25_NEXT_MSG_STAT),
(described in the next chapter) or with select(2). The select() call
allows you to specify when you want this test to take place.
Refer to the accept(7) entry in your man pages for more information.
Strategies for Server Design
HP suggests that you build a server process that creates a socket, binds
an address, attaches a listen queue, and waits for the arrival of a CALL
INDICATION packet with the accept() call. When the request packet
arrives, the server process forks a child process to handle the newly
established SVC.
The child process closes the socket descriptor for the listen socket, and
the parent process closes the socket descriptor returned by accept().
The child process goes on to service the needs of the remote process.
When the job is completed, it closes the connection and calls exit(2).
Meanwhile, the parent process calls accept() and waits for the next
CALL INDICATION packet to service.
This technique may not suit all situations. If the server process will act
on one call request at a time, it can wait for a call, accept a call, execute a
service request, close the call, and go back to wait for another call. In a
database application, for example, it is not unusual for the server to
accept only one incoming call at a time, completing the service request
before accepting another.
In this case you would not fork a child process to accept the call. Instead
the server might follow these steps:
1. Create a socket, bind an X.25 address to it, execute listen() on the
socket.
2. Use accept() to get a connection.
3. Determine which service is requested.
4. Perform the requested service.
36960-90061.bk Page 32 Friday, November 10, 2000 3:42 PM










