Platform SDK: Windows Sockets |
The NSPSetService function registers or deregisters a service instance within a name space.
int NSPSetService ( LPGUID lpProviderId, LPWSASERVICECLASSINFOW lpServiceClassInfo, LPWSAQUERYSETW lpqsRegInfo, WSAESETSERVICEOP essOperation, DWORD dwControlFlags );
The available values for essOperation and dwControlFlags combine to give meanings as shown in the following table.
Operation | Flags | Service already exists | Service does not exist |
---|---|---|---|
RNRSERVICE_ REGISTER |
None | Overwrites the object. Uses only addresses specified. Object is REGISTERED. | Creates a new object. Uses only addresses specified. Object is REGISTERED. |
RNRSERVICE_ REGISTER |
SERVICE _MULTIPLE |
Updates object. Adds new addresses to existing set. Object is REGISTERED. | Creates a new object. Uses all addresses specified. Object is REGISTERED. |
RNRSERVICE_ DEREGISTER |
None | Removes all addresses, but does not remove object from name space. Object is DEREGISTERED. | WSASERVICE_ NOT_FOUND |
RNRSERVICE_ DEREGISTER |
SERVICE _MULTIPLE |
Updates object. Removes only addresses that are specified. Only mark object as DEREGISTERED if no addresses are present. Does not remove from the name space. | WSASERVICE_ NOT_FOUND |
RNRSERVICE_ DELETE |
None | Removes object from the name space. | WSASERVICE_ NOT_FOUND |
RNRSERVICE_ DELETE |
SERVICE _MULTIPLE |
Removes only addresses that are specified. Only removes object from the name space if no addresses remain. | WSASERVICE_ NOT_FOUND |
The function should return NO_ERROR (zero) if the routine succeeds. It should return SOCKET_ERROR (–1) if the routine fails and it must set the appropriate error code using SetLastError.
SERVICE_MULTIPLE lets an application manage its addresses independently. This is useful when the application wants to manage its protocols individually or when the service resides on more than one machine. For instance, when a service uses more than one protocol, it may find that one listening socket aborts but the others remain operational. In this case, the service could deregister the aborted address without affecting the other addresses.
When using SERVICE_MULTIPLE, an application must not let stale addresses remain in the object. This can happen if the application aborts without issuing a DEREGISTER request. When a service registers, it should store its addresses. On its next invocation, the service should explicitly deregister these old stale addresses before registering new addresses.
The following table describes how service property data is represented in a WSAQUERYSET structure. Members labeled as (Optional) can be supplied with a NULL pointer.
WSAQUERYSET member name | Service property description |
---|---|
dwSize | Must be set to sizeof(WSAQUERYSET). This is a versioning mechanism. |
DwOuputFlags | Not applicable and ignored. |
LpszServiceInstanceName | Referenced string contains the service instance name. |
LpServiceClassId | GUID corresponding to this service class. |
LpVersion | (Optional) Supplies service instance version number. |
LpszComment | (Optional) An optional comment string. |
DwNameSpace | Ignored for this operation. |
LpNSProviderId | Ignored for this operation, provider identifier is contained in the lpProviderId parameter. |
LpszContext | (Optional) Specifies the starting point of the query in a hierarchical name space. |
DwNumberOfProtocols | Ignored. |
LpafpProtocols | Ignored. |
LpszQueryString | Ignored. |
DwNumberOfCsAddrs | Number of elements in the array of CSADDRO_INFO structures referenced by lpcsaBuffer. |
LpcsaBuffer | Pointer to an array of CSADDRO_INFO structures that contain the address[es] that the service is listening on. |
LpBlob | (Optional) Pointer to a provider-specific entity. |
Note It is acceptable for the iProtocol member of the CSADDR_INFO structure to contain the manifest constant IPROTOCOL_ANY, signifying a wildcard value. The name-space provider should substitute a value that is reasonable for the given address family and socket type.
Error code | Meaning |
---|---|
WSAEACCES | Calling routine does not have sufficient privileges to install the service. |
WSAEINVAL | One or more parameters were invalid or missing for this provider. |
WSA_NOT_ENOUGH_MEMORY | Not enough free memory available to perform this operation. |
WSASERVICE_NOT_FOUND | No such service is known. The service cannot be found in the specified name space. |
Version: Requires Windows Sockets 2.0.
Header: Declared in Ws2spi.h.