OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
wskservm.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1995, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Winsock for OWL subsystem.
7/// Based on work by Paul Pedriana, 70541.3223@compuserve.com
8//----------------------------------------------------------------------------
9#include <owl/pch.h>
10#include <owl/defs.h>
11#include <owl/winsock.h>
12
13namespace owl {
14
16
17//
18//
19//
20DEFINE_RESPONSE_TABLE1(TServiceWindow, TWindow)
23
24//
25/// A TServiceWindow requires a TServiceManager parent.
26//
28:
30 ServiceManagerParent(serviceManagerParent)
31{
32 Attr.Style = 0; // Turn off WS_CHILD (the default) style).
33}
34
35//
36/// This function merely calls the parent notification function. Since Windows is
37/// designed to receive only system messages, there is a dummy window that does
38/// nothing but simulate the concept of Objects receiving messages (in this case,
39/// the ServceManager object). The TServiceWindow hides this from the user
40/// (programmer).
41//
47
48//----------------------------------------------------------------------------
49
50//
51/// Initializes all data members of servent to 0.
52//
54{
55 s_name = 0;
56 s_aliases = 0;
57 s_port = 0;
58 s_proto = 0;
59}
60
61//----------------------------------------------------------------------------
62
63//
64/// This function creates the hidden window and initializes data members.
65//
67:
68 Window(this)
69{
70 ServiceEntry = (TServiceEntry*)&ServiceBuffer;
72 LastError = 0;
75 try {
76 Window.Create();
77 }
78 catch (...) {
79 //Invalid Window exception.
80 }
81}
82
83//
84/// If there are any outstanding requests, this cancels them.
85//
87{
88 // If there is an outstanding request...
89 //
92}
93
94//
95/// Implements the blocking getservbyport(). sEntry is a pointer to a ServiceEntry*.
96/// The caller does not allocate a ServiceEntry; it will be set by the system. Do
97/// not change any data in the returned structure. port is passed to this function
98/// in network byte ordering. szProtocol is the protocol name, but may be passed as
99/// 0 to mean default or first found. The returned entry has the port in network
100/// byte order.
101//
111
112//
113/// This function implements the blocking getservbyname(). sEntry is a pointer to a
114/// ServiceEntry*. If the caller does not allocate a ServiceEntry; it will be set by
115/// the system. Do not change any data in the returned structure. The szname
116/// argument points to the string representing the service name, such as ftp. It is
117/// generally case-sensitive. szProtocol is the protocol name, but may be passed as
118/// 0 to mean default or first found. The returned entry has the port in network
119/// byte order.
120//
130
131//
132/// This function is blocking. Given an input service in szName, this function fills
133/// nPort with the port (in network order). The port is a reference to an int. If
134/// the call returns OK, this will be the port in network ordering. szProtocol is
135/// the protocol name, but may be passed as 0 to mean default or first found.
136//
138{
140
142 port = tempServiceEntry->s_port; // Note that port is already in host byte order.
143 return returnValue;
144}
145
146//
147/// This function is blocking. The szName needs to be big enough to hold the
148/// service's name (N_MAX_SERVICE_NAME). The port must be passed in network byte
149/// ordering. szProtocol is the protocol name, but may be passed as 0 to mean
150/// default or first found.
151//
153{
154 // Note that because we are calling our own member function, we don't convert
155 // the address from local to network format.
156 //
160 strcpy(name, tempServiceEntry->s_name);
161 return returnValue;
162}
163
164//
165/// This function cancels a pending service that equals the hService. Note that if
166/// the service is 0 or unspecified, this function uses its own current service.
167//
185
186//
187/// This call is non-blocking. It sets up a callback to its own member window.
188/// hService is a HANDLE reference. If the call is successful, it will hold the
189/// handle for the asynchrous call. Note that the caller can save the handle, but
190/// also that this class stores the handle for itself as well. port is passed into
191/// this function in network byte ordering.
192/// Note that due to the design of this class, you cannot have two outstanding
193/// Service requests that get notified directly to this class. You may use the
194/// hwnd-specific notification version of this function to manage multiple requests
195/// at a time. You may also simply create more than one instance of this class. The
196/// service is complete when bServiceRequestCompleted is TRUE. You must look at
197/// nLastError in this case to see if there was an error.
198//
212
213//
214/// This call is nonblocking. It sets up a callback to its own member window.
215/// hService is a HANDLE reference. If the call is successful, it will hold the
216/// handle for the asynchrous call. Note that the caller can save the handle, but
217/// also that this class stores the handle for itself as well. port is passed into
218/// this function in network byte ordering.
219/// Note that due to the design of this class, you cannot have two outstanding
220/// Service requests that get notified directly to this class. You may use the
221/// hwnd-specific notification version of this function to manage multiple requests
222/// at a time. You may also simply create more than one instance of this class. The
223/// service is complete when bServiceRequestCompleted is TRUE. You must look at
224/// nLastError in this case to see if there was an error.
225//
238
239//
240/// This function notifies the given wndNotify about the completion of the request.
241/// nMessage is the message that the hwndNotify will receive. It defaults to
242/// MSG_SERVICE_NOTIFY, which is defined in the TServiceManager's header file. The
243/// hService will hold a handle that the caller can use to reference the request on
244/// call-back. nPort should be passed in network byte ordering. The chBuffer is a
245/// pointer to buffer that will be filled in with a SERVENT. It needs to be at least
246/// MAXGETHOSTSTRUCT bytes.
247/// If chBuffer is 0 (or not specified), the TServiceManager's internal buffer will
248/// be used. szProtocol is the protocol name, but may be passed as 0 to mean default
249/// or first found. This class will NOT save the hServcice for itself. wParam will
250/// be equal to the hService returned. WSAGETSYNCERROR(lParam) holds an error, if
251/// any (0 is OK). WSAGETSYNCBUFLEN(lParam) holds actual length of the buffer.
252//
268
269//
270/// This function notifies the given wndNotify about the completion of the request.
271/// nMessage is the message that the hwndNotify will receive. It defaults to
272/// MSG_SERVICE_NOTIFY, which is defined in the TServiceManager's header file. The
273/// hService will hold a handle that the caller can use to reference the request on
274/// call-back. The chBuffer is a pointer to a buffer that will be filled in with a
275/// SERVENT. It needs to be at least MAXGETHOSTSTRUCT bytes.
276/// If chBuffer is 0 (or not specified), the TServiceManager's internal buffer will
277/// be used. szName is a pointer to a c string service name, such as ftp. szProtocol
278/// is the protocol name, but may be passed as 0 to mean default or first found.
279/// This class will NOT save the hService for itself. wParam will be equal to the
280/// hService returned. WSAGETSYNCERROR(lParam) holds an error, if any (0 is OK).
281/// WSAGETSYNCBUFLEN(lParam) holds actual length of the buffer.
282//
298
299//
300/// This function is called whenever an internal window callback is used for an
301/// asynchronous call. When this function is called, the ServiceRequestCompleted
302/// member is true (it got set to true right before this function was called). You
303/// may want to override this function. If you do, you must call the base version.
304//
312
313} // OWL namespace
314/* ========================================================================== */
315
Encapsulates information about a service.
Definition wskservm.h:63
TServiceEntry()
Initializes all data members of servent to 0.
Definition wskservm.cpp:53
The TServiceManager class (and its friend class TServiceWindow) encapsulate the Winsock database func...
Definition wskservm.h:77
virtual ~TServiceManager()
If there are any outstanding requests, this cancels them.
Definition wskservm.cpp:86
HANDLE LastServiceRequest
Handle of last service request.
Definition wskservm.h:110
bool LastServiceRequestCompleted
Is the last request done?
Definition wskservm.h:108
int GetServiceName(uint16 nPort, char *szName, const char *szProtocol=0)
This function is blocking.
Definition wskservm.cpp:152
int GetServiceAsync(HANDLE &hService, uint16 nPort, const char *szProtocol=0)
This call is non-blocking.
Definition wskservm.cpp:199
int GetServicePort(char *szName, uint16 &nPort, const char *szProtocol=0)
This function is blocking.
Definition wskservm.cpp:137
TServiceWindow Window
Private window for catching notification.
Definition wskservm.h:111
void ServiceCompleted(int nError)
This function is called whenever an internal window callback is used for an asynchronous call.
Definition wskservm.cpp:305
int GetService(TServiceEntry *&sEntry, uint16 nPort, const char *szProtocol=0)
Implements the blocking getservbyport().
Definition wskservm.cpp:102
TServiceManager()
This function creates the hidden window and initializes data members.
Definition wskservm.cpp:66
int CancelServiceRequest(HANDLE hService=0)
This function cancels a pending service that equals the hService.
Definition wskservm.cpp:168
char ServiceBuffer[MAXGETHOSTSTRUCT]
Used for calls to WSAAsync...()
Definition wskservm.h:109
int OutstandingServiceRequests
Count of total requests done by myself that haven't completed yet.
Definition wskservm.h:107
int LastError
Last error code.
Definition wskservm.h:106
TServiceWindow is a private class created by the TServiceManager to catch notifications.
Definition wskservm.h:44
TServiceManager * ServiceManagerParent
Object to pass notifications.
Definition wskservm.h:51
TResult DoNotification(TParam1, TParam2)
This function merely calls the parent notification function.
Definition wskservm.cpp:42
static HANDLE WSAAsyncGetServByPort(HWND hWnd, uint msg, int port, LPCSTR proto, char *buf, int bufLen)
Definition winsock.cpp:339
static struct servent * getservbyname(LPCSTR name, LPCSTR proto)
Definition winsock.cpp:237
static int WSAGetLastError(void)
Definition winsock.cpp:294
static int WSACancelAsyncRequest(HANDLE hTaskHandle)
Definition winsock.cpp:384
static struct servent * getservbyport(int port, LPCSTR proto)
Definition winsock.cpp:245
static HANDLE WSAAsyncGetServByName(HWND hWnd, uint msg, LPCSTR name, LPCSTR proto, char *buf, int bufLen)
Definition winsock.cpp:330
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
virtual bool Create()
Creates the window interface element to be associated with this ObjectWindows interface element.
Definition window.cpp:2399
#define _T(x)
Definition cygwin.h:51
#define DEFINE_RESPONSE_TABLE1(cls, base)
Macro to define a response table for a class with one base.
Definition eventhan.h:492
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
LPARAM TParam2
Second parameter type.
Definition dispatch.h:55
WPARAM TParam1
First parameter type.
Definition dispatch.h:54
OWL_DIAGINFO
Definition animctrl.cpp:14
END_RESPONSE_TABLE
Definition button.cpp:26
unsigned short uint16
Definition number.h:33
unsigned int uint
Definition number.h:25
General definitions used by all ObjectWindows programs.
#define EV_MESSAGE(message, method)
Response table entry for raw message handling Uses a dispatcher that just forwards WPARAM and LPARAM.
Definition windowev.h:113
Main header of the Winsock OWL subsystem.
#define WINSOCK_NOERROR
Definition wskhostm.h:30
#define WINSOCK_ERROR
Definition wskhostm.h:31
#define MSG_SERVICE_NOTIFY
Definition wskservm.h:32