InetServerStop Function  
 
BOOL WINAPI InetServerStop(
  SOCKET hServer  
);

The InetServerStop function signals the server to stop listening for connections and terminates all client sessions.

Parameters

hServer
Handle to the server socket.

Return Value

If the function succeeds, the return value is non-zero. If the function fails, the return value is zero. To get extended error information, call InetGetLastError.

Remarks

The InetServerStop function signals the server to stop accepting client connections, disconnects all active client connections and terminates the thread that is managing the server session. The socket handle is no longer valid after the server has been stopped and should no longer be used. Note that it is possible that the actual handle value may be re-used at a later point when a new server is started. An application should always consider the socket handle to be opaque and never depend on it being a specific value.

If this function is called when there is one or more clients connected to the server, it will signal each client thread to terminate and then wait for the server thread to terminate. As the client sessions are terminated, the event handler will not be invoked. If you wish to ensure that all clients are disconnected normally before stopping the server, call the InetServerSuspendEx function with the INET_SUSPEND_DISCONNECT option and then stop the server after the last client has disconnected.

Because the InetServerStop function waits for the server thread to terminate, this function may cause your application to block. If this is not desirable, use the InetServerStopEx function which can perform the shutdown sequence asynchronously.

After the server thread has been terminated, the listening socket will go into a TIME-WAIT state which prevents an application from reusing the same address and port number bound to that socket for a brief period of time, typically two to four minutes. This is normal behavior designed to prevent delayed or misrouted packets of data from being read by a subsequent connection. To immediately start a new server using the same local address and port number, the option INET_OPTION_REUSEADDRESS must be specified when calling the InetServerStart function.

The socket handle for the server must be one that was created by calling the InetServerStart function, and cannot be a socket that was created using the InetListen or InetListenEx functions.

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cswsock11.h
Import Library: cswskv11.lib

See Also

InetGetServerStatus, InetServerRestart, InetServerStart, InetServerStopEx, InetServerSuspendEx