Handling disconnects

If an Open Server application is in the middle of returning results to a client and the client abruptly disconnects, the application continues to return results until it detects that the connection has been closed. Open Server subsequently calls the SRV_DISCONNECT event handler. In this scenario, the application continues to send results to a client that can no longer receive them. An abrupt client disconnect can occur if:

To avoid this situation, an application can request that Open Server first calls the application’s SRV_ATTENTION event handler in response to a client disconnect, and then calls the SRV_DISCONNECT event handler. For Open Server to handle disconnects in this fashion, an application must use srv_props to set the SRV_S_DISCONNECT property to CS_TRUE. The SRV_DISCONNECT event handler is still called in the usual way, but it is called after the SRV_ATTENTION handler. The SRV_S_DISCONNECT property defaults to CS_FALSE.

The SRV_ATTENTION handler initiates the appropriate steps to terminate the I/O activity and stop the return of results from the routine that was executing at the time of the disconnect. An application can thus respond to disconnects in the same way that it would to attentions.

Using its SRV_ATTENTION event handler, an application can determine which event triggered the handler—an attention or a disconnect—by calling srv_props with cmd set to CS_GET and property set to SRV_S_ATTNREASON.