InetAsyncAcceptEx Function  
 
SOCKET WINAPI InetAsyncAcceptEx(
  SOCKET hSocket,  
  UINT nTimeout,  
  DWORD dwOptions,  
  LPSECURITYCREDENTIALS lpCredentials  
  HWND hEventWnd,  
  UINT uEventMsg  
);

The InetAsyncAcceptEx function is used to accept a pending client connection.

This function is designed for use in legacy single-threaded applications and requires the application to have a message pump to process event messages. It should not be used with applications which are designed to execute as a service or those which do not have a graphical user interface.

It is recommended you use the InetServerStart function to create a server application.

Parameters

hSocket
Handle to the listening socket.
nTimeout
The number of seconds that the server will wait for a client connection before failing the operation. This value is only used with blocking connections.
dwOptions
An unsigned integer that specifies one or more options. This parameter is constructed by using a bitwise operator with any of the following values:
Value Description
INET_OPTION_KEEPALIVE This option specifies that packets are to be sent to the remote system when no data is being exchanged to keep the connection active. This is only valid for stream sockets.
INET_OPTION_REUSEADDRESS This option specifies the local address can be reused. This option is commonly used by server applications.
INET_OPTION_NODELAY This option disables the Nagle algorithm, which buffers unacknowledged data and insures that a full-size packet can be sent to the remote host.
INET_OPTION_INLINE This option controls how urgent (out-of-band) data is handled when reading data from the socket. If set, urgent data is placed in the data stream along with non-urgent data.
INET_OPTION_NOINHERIT This option prevents the socket handle from being inherited by child processes created by the application. Using this option can mitigate situations in which a child process does not close the handle, leaving it open after the parent process has stopped the server.
INET_OPTION_SECURE This option determines if a secure connection is negotiated with the remote host.
INET_OPTION_SECURE_FALLBACK This option specifies the server should permit the use of less secure cipher suites for compatibility with legacy clients. If this option is specified, the server will allow connections using TLS 1.0 and cipher suites that use RC4, MD5 and SHA1.
INET_OPTION_FREETHREAD This option specifies the socket returned by this function may be used by any thread, and is not limited to the thread which created it. The application is responsible for ensuring that access to the socket is synchronized across multiple threads.
lpCredentials
Pointer to credentials structure SECURITYCREDENTIALS. This may be NULL, unless dwOptions includes INET_OPTION_SECURE. When INET_OPTION_SECURE is used, the fields dwSize, lpszCertStore, and lpszCertName must be defined, while other fields may be left undefined. Set dwSize to the size of the SECURITYCREDENTIALS structure.
hEventWnd
The handle to the event notification window. This window receives messages which notify the application of various asynchronous socket events that occur.
uEventMsg
The message identifier that is used when an asynchronous socket event occurs. This value should be greater than WM_USER as defined in the Windows header files.

Return Value

If the function succeeds, the return value is a handle to the socket. If the function fails, the return value is INVALID_SOCKET. To get extended error information, call InetGetLastError.

Remarks

When a connection is accepted by the server, the original listening socket continues to listen for more connections. The socket handle returned by InetAsyncAccept or InetAsyncAcceptEx should be used to exchange information with the client.

When a message is posted to the notification window, the low word of the lParam parameter contains the event identifier. The high word of lParam contains the low word of the error code, if an error has occurred. The wParam parameter contains the socket handle. One or more of the following event identifiers may be sent:

Value Description
INET_EVENT_DISCONNECT The remote host has closed the connection. The process should read any remaining data and disconnect.
INET_EVENT_READ Data is available to read by the calling process. No additional messages will be posted until the process has read at least some of the data from the socket. This event is only generated if the socket is in asynchronous mode.
INET_EVENT_WRITE The process can now write data. This notification is sent after a connection has been established, or after a previous attempt to write data has failed because it would result in a blocking operation. This event is only generated if the socket is in asynchronous mode.


It is recommended that you only establish an asynchronous connection if you understand the implications of doing so. In most cases, it is preferable to create a synchronous connection and create threads for each additional session if more than one active client session is required.

The dwOptions argument can be used to specify the threading model that is used by the library when a connection is established. By default, the handle is initially attached to the thread that created it. From that point on, until the handle is released, only the owner may call functions using that handle. The ownership of the handle may be transferred from one thread to another using the InetAttachThread function.

Specifying the INET_OPTION_FREETHREAD option enables any thread to call any function using the socket handle, regardless of which thread created it. It is important to note that this option disables certain internal safety checks which are performed by the library and may result in unexpected behavior unless access to the socket is synchronized. If one thread calls a function in the library, it must ensure that no other thread will call another function at the same time using the same socket handle.

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cswsock12.h
Import Library: cswskv12.lib
Unicode: Implemented as Unicode and ANSI versions

See Also