SK_PLUS_NetworkSemaphoreOpen Function

Keeps track of concurrent users of an application on a network by using semaphore files in a shared network location.

Remarks

A Network Semaphore File is a file, which contains no useful data, stored on a common network directory used to assist in enforcing a Network Floating License in an application. One file is created and locked exclusively for each active workstation or instance of your protected application. Other LAN users attempting to run the application will not be able to use any semaphore files that are locked, which is how this can enforce license compliance which limits the number of network "seats."

Any users who will use an application using this type of licensing will need access to read, write, modify, and delete the semaphore files.

Important Note

The absolute path to the semaphore files (including the name of each semaphore file) cannot exceed the maximum path limitation (260 characters). If the path does exceed the length limitation, this function may return SK_ResultCode.SK_ERROR_NETWORK_LICENSE_FULL as a result of not being able to create and lock any semaphores.

This functionality is supported on environments where semaphore files are hosted on a Windows (SMB/CIFS) share, which functions best on a Local Area Network (LAN). While this may be used in a Wide Area Network (WAN) environment (which includes scenarios where a user access a given "LAN" over a Virtual Private Network [VPN] connection), it is strongly advised testing is done before deploying to any given WAN environment. This is because the performance of this feature is centered around that of the Windows (SMB/CIFS) shares being used to host the semaphore files (and WAN/VPN environments can see much slower performance than a typical LAN configuration).

Important Note

The NetworkSemaphore class is only supported when the system hosting the Windows (SMB/CIFS) share that houses the semaphore files and the clients which access the share all run Windows Vista/Windows Server 2008 or later.

Important Note

The computer hosting the Windows (SMB/CIFS) share (the server) that houses the semaphore files is ultimately responsible for handling when a file is unlocked. In most cases, applications which are terminated gracefully will unlock and delete their semaphore files. If the application crashes, however, the server will eventually unlock the semaphore file, but it will not delete the file. Having many of these files present can lead to some performance degradation, as each of these orphaned files can take a while to try to lock or delete. The SK_PLUS_NetworkSemaphoreCleanup function can help avoid or limit this kind of performance degradation.

With very large and/or WAN deployments, the performance degradation described above can often be avoided or limited by using the SK_FLAGS_NETWORK_SEMAPHORE_SKIPLOCKATTEMPT flag. This flag prevents this function from attempting to lock existing files (which it does to check if perhaps one of the existing files has been orphaned). While this flag can improve performance, keep in mind that using the flag also means you are required to call SK_PLUS_NetworkSemaphoreCleanup to delete orphaned semaphore files. If your application uses this flag without calling SK_PLUS_NetworkSemaphoreCleanup, it is likely that the presence of orphaned files will cause this function to prematurely return SK_ResultCode.SK_ERROR_NETWORK_LICENSE_FULL (meaning no seats are available).

Syntax

C/C++
SK_ResultCode SK_PLUS_NetworkSemaphoreOpen(SK_ApiContext context, int flags, int seatsAllowed, const char *seatsAllowedXPath, const char *semaphorePath, const char *semaphorePrefix, const char *optionalIdentifier, char **filePath);
Visual Basic
Declare Function SK_PLUS_NetworkSemaphoreOpen(ByVal context As Long, ByVal flags As Long, ByVal seatsAllowed As Long, ByVal seatsAllowedXPath As String, ByVal semaphorePath As String, ByVal semaphorePrefix As String, ByVal optionalIdentifier As String, ByRef filePath As String) As Long

Arguments

context
The API Context handle.
flags
Any flags passed into this function-call.
seatsAllowed
The maximum number of seats allowed. When seatsAllowedXPath is not null or empty, the specified license file value overrides this value.
seatsAllowedXPath
An XPath that specifies the license file property/field, which overrides the seatsAllowed parameter. If this parameter receives a null or empty string, the seatsAllowed value is used.
semaphorePath
The absolute path to the directory or network share where semaphore files will be created and locked. When using a network share, a UNC-formatted path is strongly recommended.
semaphorePrefix
The prefix to use for semaphore file names.
optionalIdentifier
Reserved for future use. Pass a null or empty string.
filePath
The path to the semaphore file which was created and locked.

Returns

All possible return values are included in the SK_ResultCode enumeration. Return codes to expect include:

Result Code Description
SK_ResultCode.SK_ERROR_NONE No error.
SK_ResultCode.SK_ERROR_XML_PARSER_FAILED The XML parser encountered an error.
SK_ResultCode.SK_ERROR_XML_NODE_MISSING The requested XML node could not be found.
SK_ResultCode.SK_ERROR_INVALID_ARGUMENTS Some or all of the arguments are invalid.
SK_ResultCode.SK_ERROR_NETWORK_SEMAPHORE_INVALID_PATH The network path is not valid or is unavailable.
SK_ResultCode.SK_ERROR_NETWORK_LICENSE_FULL The number of allowed concurrent users has been reached.
SK_ResultCode.SK_ERROR_NETWORK_SEMAPHORE_LOCK_FAILED Failed to create or lock the network semaphore.
SK_ResultCode.SK_ERROR_UNSUPPORTED_OS The current operating system is not supported by this feature or function.
SK_ResultCode.SK_ERROR_MEMORY_ALLOCATION Memory could not be allocated.