28.5.2 Server Applications and Connect Data

The use of connect data by a server application differs implicitly from a client application's use in two important ways. First, a server application receives the client's connect data before it sends its own. Second, because the socket interface does not support the concept of delayed accept, a server application is limited to sending the same response connect data to all clients.

A server application that is to receive connect data should use setsockopt with the SO_CONNDATALEN option to force the Windows Sockets DLL to reserve buffer space for receiving connect data for incoming connect requests. The specified amount of connect data buffer space is used for all incoming connects, but each connect gets a separate buffer. After a newly connected socket is accepted with accept, the application calls getsockopt with the SO_CONNDATA option and a buffer large enough to hold expected response data. The Windows Sockets DLL fills in this buffer with the connect data sent by the client.

To send connect data, a server application calls setsockopt with the SO_CONNDATA option and a buffer of data before incoming connections are accepted (typically before listen). Thereafter, any client that connects to the server receives the specified connect data. The connect data sent by a server may be changed at any time with another setsockopt call, which discards the previous data and replaces it with new connect data.