Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Networking With Open Transport / Part 1 - Open Transport Essentials
Chapter 5 - Programming With Open Transport


Handling Multiple Simultaneous Connections

This section describes the problems of handling multiple simultaneous connections and explains the use of the tilisten module as a means of handling these problems.

Problems With Accepting Multiple Simultaneous Connections

One of the big challenges of programming Open Transport is accepting multiple simultaneous incoming connections. The problem is that the obvious code stream can produce unexpected results. Take, for example, the following sequence:

  1. You have a listening endpoint (one bound with a qlen greater than 0 )in asynchronous mode. (The problem is independent of the mode of the listening endpoint but, for the sake of this example, we'll assume the listening endpoint is in asynchronous mode.)

  2. An incoming connection arrives, and the listening endpoint calls your notifier with a T_LISTEN event.

  3. Your notifier reads the details of the incoming connection using the OTListen routine.

  4. Your notifier decides to accept the incoming connection by calling the function OTAccept.

  5. However, the OTAccept call fails with a kOTLookErr because there is another pending T_LISTEN event on the listening endpoint. (This behavior is explicitly allowed in the XTI specification.)

There are a number of ways to solve this problem. The easiest approach is to use a qlen of 1 when you bind the endpoint. If you do this, the provider will reject connection attempts while you are in the process of accepting a connection attempt. The drawback to this approach is that the remote peer will receive unnecessary connection rejections.

A second approach is to program around the problem using the existing Open Transport APIs. When you call OTAccept and get a look error, you turn around and call OTLook. If the pending event is a T_LISTEN, put the first connection on hold and deal with this new connection. Of course, the attempt to accept the new connection can also fail because of a pending T_LISTEN, which means you have to put this second connection attempt on hold, and so on. This requires you to have a queue of pending incoming connection attempts. You must also deal with T_DISCONNECT events on the listening endpoint, and delete the corresponding connection attempts from the queue.

This second approach requires a lot of code, and is very hard to get right.

The third, and recommended, approach is to use the tilisten module to serialize incoming connection requests. This approach is described in the next section.

Using "tilisten" to Accept Multiple Simultaneous Connections

The tilisten module is provided to simplify the job of accepting multiple simultaneous incoming connections. The module sits on top of the provider associated with the listening endpoint and monitors connection requests being sent up to the client. When a connection request arrives while the client is still in the process of dealing with an earlier connection request, the tilisten module holds on to the second connection request until the client is accepts or rejects the first one.

Thus, when the tilisten module is installed in the stream, the OTAccept function will never fail because of a pending T_LISTEN event, and only fail with a pending T_DISCONNECT event if that disconnection event is for the current connection request.

You can use the tilisten module in your listening endpoint by specifying it in the configuration you use to build the listening endpoint. For example, if you want to create an TCP endpoint with the "tilisten" module, you would do so with the following code:

ep = OTOpenEndpoint(OTCreateConfiguration("tilisten,tcp"), 0, nil, &err);
You should should only include the tilisten module in connection-oriented, listening endpoints. The module is not appropriate for use in hand-off endpoints, or endpoints used for outgoing connections.

Note
The tilisten module is not available in versions of Open Transport prior to version 1.1.1.

Subtopics
Problems With Accepting Multiple Simultaneous Connections
Using "tilisten" to Accept Multiple Simultaneous Connections

Previous Book Contents Book Index Next

© Apple Computer, Inc.
15 JAN 1998