Important: The information in this document is obsolete and should not be used for new development.
Handling Multiple Simultaneous Connections
This section describes the problems of handling multiple simultaneous connections and explains the use of thetilisten
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:
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.
- 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.)
- An incoming connection arrives, and the listening endpoint calls your notifier with a
T_LISTEN
event.- Your notifier reads the details of the incoming connection using the
OTListen
routine.- Your notifier decides to accept the incoming connection by calling the function
OTAccept
.- However, the OTAccept call fails with a
kOTLookErr
because there is another pendingT_LISTEN
event on the listening endpoint. (This behavior is explicitly allowed in the XTI specification.)
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 callOTLook
. If the pending event is aT_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 pendingT_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 withT_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
Thetilisten
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, thetilisten
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 pendingT_LISTEN
event, and only fail with a pendingT_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 thetilisten
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