InetServerLock
BOOL InetServerLock(
SOCKET hServer  
);

The InetServerLock function locks the specified server, causing other server threads to block until it is unlocked.

Parameters

hServer
The socket handle to the server.

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 InetServerLock function causes the specified server to enter a locked state where only the current thread may interact with the server and the clients that are connected to it. While a server is locked, all other threads will block when they attempt to perform a network operation. When the server is unlocked, the blocked threads will resume normal execution.

This function should be used carefully, and a server should never be left in a locked state for an extended period of time. It is meant to be used when the server process updates a global data structure and it must prevent any other threads from performing a network operation during the update. Only one server can be locked at any one time, and once a server has been locked, it can only be unlocked by the same thread.

The program should always check the return value from this function, and should never assume that the lock has been established. If more than one thread attempts to lock a server at the same time, there is no guarantee as to which thread will actually establish the lock. If a potential deadlock situation is detected, this function will fail and return a value of zero.

Every time the InetServerLock function is called, an internal lock counter is incremented, and the lock will not be released until the lock count drops to zero. This means that each call to InetServerLock must be matched by an equal number of calls to the InetServerUnlock function. Failure to do so will result in the server becoming non-responsive as it remains in a locked state.

Requirements

Client: Requires Windows Vista, Windows XP or Windows 2000 Professional.
Server: Requires Windows Server 2008, Windows Server 2003 or Windows 2000 Server.
Header: Include cswsock6.h.
Library: Use cswskav6.lib.

See Also

InetGetLockedServer, InetServerUnlock


Copyright © 2008 Catalyst Development Corporation. All rights reserved.