OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
About TServiceManager

Using

The TServiceManager class (and its friend class TServiceWindow) encapsulate the Winsock database functions getservbyname(), getservbyport(), WSAAsyncGetServByName(), and WSAAsyncGetServByPort(). These blocking (get...) and non-blocking (WSA...) functions return information about the service name, port, and protocol when given only a service name or a port.

The Winsock service database functions return a pointer to a read-only servent structure.

The TServiceManager uses a subclass of the servent class called the TServiceEntry class. Since TServiceEntry is a subclass of servant, it can be used anywhere that Winsock or Windows Socket Class requires a servent. The TServiceManager supports direct equivalents to the blocking getservbyname() and getservbyport() Winsock functions. If you wanted to find the port that the service "ftp" resides on, you could use the TServiceManager to give you this information. Calling the Winsock function:

tempServent = getservbyport("ftp");

will store the service name, the port, and the protocol in the servent structure. Calling the TServiceManager function GetService() has the same effect:

nError = GetService(tempServent, "ftp");

The TServiceManager also supports asynchronous (non-blocking) Winsock service lookups. These correspond to the WSAGetServByName() and WSAGetServByPort() functions. To use these classes in Winsock, you need to pass an HWND to these functions and wait until Winsock calls you back with an answer. In the Windows Socket Class, you have two choices:

  1. You can give the TServiceManager a TWindow to notify upon completion using GetServiceAsync().
  2. You can let TServiceManager get the notification itself, and then get the information from the TServiceManager when the information is ready. This approach lets TServiceManager do all the work; you don't have to work with HWNDs, wMsgs, wParams, etc. This option is very similar to the Overlapped I/O concept of Windows NT: Reads and Writes don't block, but the function returns as if the data was read or sent, and a notification will be posted when the read/write actually occurs. This is very useful for times when one thread handles multiple sockets at a time.