OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
winsock.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/// Implementation of TWinSockDll, a WinSock dll loader & wrapper
7//----------------------------------------------------------------------------
8#include <owl/pch.h>
9#include <owl/defs.h>
10#include <owl/winsock.h>
11#include <owl/module.h>
12
13namespace owl {
14
16
17 static tchar WinSockDllName[] = _T("WSock32.dll");
18
19//
20// Construct wrapper object and load DLL
21//
22
24:
25 TModule(WinSockDllName, true, true, false) // shouldLoad, mustLoad and !addToList
26{}
27
28//
29// Standard socket functions
30//
31
32SOCKET
33TWinSockDll::accept(SOCKET s, struct sockaddr * addr, int * addrLen)
34{
35 static TModuleProc3<SOCKET,SOCKET,struct sockaddr *, int *>
36 accept(WinSockModule(), "accept");
37 return accept(s, addr, addrLen);
38}
39
40int
41TWinSockDll::bind(SOCKET s, struct sockaddr * addr, int nameLen)
42{
43 static TModuleProc3<int,SOCKET,struct sockaddr *,int>
44 bind(WinSockModule(), "bind");
45 return bind(s, addr, nameLen);
46}
47
48int
50{
51 static TModuleProc1<int,SOCKET> closesocket(WinSockModule(), "closesocket");
52 return closesocket(s);
53}
54
55int
56TWinSockDll::connect(SOCKET s, struct sockaddr * name, int nameLen)
57{
58 static TModuleProc3<int,SOCKET,struct sockaddr *,int>
59 connect(WinSockModule(), "connect");
60 return connect(s, name, nameLen);
61}
62
63int
64TWinSockDll::getpeername(SOCKET s, struct sockaddr * name, int * nameLen)
65{
66 static TModuleProc3<int,SOCKET,struct sockaddr *,int *>
67 getpeername(WinSockModule(), "getpeername");
68 return getpeername(s, name, nameLen);
69}
70
71int
72TWinSockDll::getsockname(SOCKET s, struct sockaddr * name, int * nameLen)
73{
74 static TModuleProc3<int,SOCKET,struct sockaddr *,int *>
75 getsockname(WinSockModule(), "getsockname");
76 return getsockname(s, name, nameLen);
77}
78
79int
80TWinSockDll::getsockopt(SOCKET s, int level, int optName, char * optVal, int * optLen)
81{
82 static TModuleProc5<int,SOCKET,int,int,char *,int *>
83 getsockopt(WinSockModule(), "getsockopt");
84 return getsockopt(s, level, optName, optVal, optLen);
85}
86
89{
90 static TModuleProc1<ulong,ulong> _htonl(WinSockModule(), "htonl");
91 return _htonl(hostLong);
92}
93
96{
97 static TModuleProc1<ushort,ushort> _htons(WinSockModule(), "htons");
98 return _htons(hostShort);
99}
100
101ulong
103{
104 static TModuleProc1<ulong,LPCSTR> inet_addr(WinSockModule(), "inet_addr");
105 return inet_addr(cp);
106}
107
108char *
109TWinSockDll::inet_ntoa(struct in_addr in)
110{
111 static TModuleProc1<char *,struct in_addr> inet_ntoa(WinSockModule(), "inet_ntoa");
112 return inet_ntoa(in);
113}
114
115int
116TWinSockDll::ioctlsocket(SOCKET s, long cmd, ulong * argp)
117{
118 static TModuleProc3<int,SOCKET,long,ulong *>
119 ioctlsocket(WinSockModule(), "ioctlsocket");
120 return ioctlsocket(s, cmd, argp);
121}
122
123int
124TWinSockDll::listen(SOCKET s, int backlog)
125{
126 static TModuleProc2<int,SOCKET,int> listen(WinSockModule(), "listen");
127 return listen(s, backlog);
128}
129
130ulong
132{
133 static TModuleProc1<ulong,ulong> _ntohl(WinSockModule(), "ntohl");
134 return _ntohl(netLong);
135}
136
137ushort
139{
140 static TModuleProc1<ushort,ushort> _ntohs(WinSockModule(), "ntohs");
141 return _ntohs(netShort);
142}
143
144int
145TWinSockDll::recv(SOCKET s, char * buf, int len, int flags)
146{
147 static TModuleProc4<int,SOCKET,char *,int,int> recv(WinSockModule(), "recv");
148 return recv(s, buf, len, flags);
149}
150
151int
152TWinSockDll::recvfrom(SOCKET s, char * buf, int len, int flags,
153 struct sockaddr * from, int* fromLen)
154{
155 static TModuleProc6<int,SOCKET,char *,int,int,struct sockaddr *,int*>
156 recvfrom(WinSockModule(), "recvfrom");
157 return recvfrom(s, buf, len, flags, from, fromLen);
158}
159
160int
161TWinSockDll::select(int nfds, struct fd_set * readfds,
162 struct fd_set * writefds, struct fd_set * exceptfds,
163 const struct timeval * timeout)
164{
165 static TModuleProc5<int,int,struct fd_set *,struct fd_set *,
166 struct fd_set *,const struct timeval *> select(WinSockModule(), "select");
167 return select(nfds, readfds, writefds, exceptfds, timeout);
168}
169
170int
171TWinSockDll::send(SOCKET s, LPCSTR buf, int len, int flags)
172{
173 static TModuleProc4<int,SOCKET,LPCSTR,int,int> send(WinSockModule(), "send");
174 return send(s, buf, len, flags);
175}
176
177int
178TWinSockDll::sendto(SOCKET s, LPCSTR buf, int len, int flags,
179 const struct sockaddr * to, int toLen)
180{
181 static TModuleProc6<int,SOCKET,LPCSTR,int,int,
182 const struct sockaddr *,int> sendto(WinSockModule(), "sendto");
183 return sendto(s, buf, len, flags, to, toLen);
184}
185
186int
187TWinSockDll::setsockopt(SOCKET s, int level, int optName,
188 LPCSTR optVal, int optLen)
189{
190 static TModuleProc5<int,SOCKET,int,int,LPCSTR,int>
191 setsockopt(WinSockModule(), "setsockopt");
192 return setsockopt(s, level, optName, optVal, optLen);
193}
194
195int
196TWinSockDll::shutdown(SOCKET s, int how)
197{
198 static TModuleProc2<int,SOCKET,int> shutdown(WinSockModule(), "shutdown");
199 return shutdown(s, how);
200}
201
202SOCKET
203TWinSockDll::socket(int af, int type, int protocol)
204{
205 static TModuleProc3<SOCKET,int,int,int> socket(WinSockModule(), "socket");
206 return socket(af, type, protocol);
207}
208
209//
210// Database functions
211//
212
213struct hostent *
214TWinSockDll::gethostbyaddr(LPCSTR addr, int len, int type)
215{
216 static TModuleProc3<struct hostent *,LPCSTR,int,int>
217 gethostbyaddr(WinSockModule(), "gethostbyaddr");
218 return gethostbyaddr(addr, len, type);
219}
220
221struct hostent *
223{
224 static TModuleProc1<struct hostent *,LPCSTR>
225 gethostbyname(WinSockModule(), "gethostbyname");
226 return gethostbyname(name);
227}
228
229int
230TWinSockDll::gethostname(char * name, int nameLen)
231{
232 static TModuleProc2<int,char *,int> gethostname(WinSockModule(), "gethostname");
233 return gethostname(name, nameLen);
234}
235
236struct servent *
237TWinSockDll::getservbyname(LPCSTR name, LPCSTR proto)
238{
239 static TModuleProc2<struct servent *,LPCSTR, LPCSTR>
240 getservbyname(WinSockModule(), "getservbyname");
241 return getservbyname(name, proto);
242}
243
244struct servent *
245TWinSockDll::getservbyport(int port, LPCSTR proto)
246{
247 static TModuleProc2<struct servent *,int,LPCSTR>
248 getservbyport(WinSockModule(), "getservbyport");
249 return getservbyport(port, proto);
250}
251
252struct protoent *
254{
255 static TModuleProc1<struct protoent *, LPCSTR>
256 getprotobyname(WinSockModule(), "getprotobyname");
257 return getprotobyname(name);
258}
259
260struct protoent *
262{
263 static TModuleProc1<struct protoent *, int>
264 getprotobynumber(WinSockModule(), "getprotobynumber");
265 return getprotobynumber(proto);
266}
267
268//
269// Microsoft Windows Extension functions
270//
271
272int
273TWinSockDll::WSAStartup(uint16 versionRequested, LPWSADATA WSAData)
274{
275 static TModuleProc2<int,uint16,LPWSADATA> WSAStartup(WinSockModule(), "WSAStartup");
276 return WSAStartup(versionRequested, WSAData);
277}
278
279int
281{
282 static TModuleProc0<int> WSACleanup(WinSockModule(), "WSACleanup");
283 return WSACleanup();
284}
285
286void
288{
289 static TModuleProcV1<int> WSASetLastError(WinSockModule(), "WSASetLastError");
290 WSASetLastError(error);
291}
292
293int
295{
296 static TModuleProc0<int> WSAGetLastError(WinSockModule(), "WSAGetLastError");
297 return WSAGetLastError();
298}
299
300BOOL
302{
303 static TModuleProc0<int> WSAIsBlocking(WinSockModule(), "WSAIsBlocking");
304 return WSAIsBlocking();
305}
306
307int
309{
310 static TModuleProc0<int> WSAUnhookBlockingHook(WinSockModule(), "WSAUnhookBlockingHook");
311 return WSAUnhookBlockingHook();
312}
313
314FARPROC
316{
317 static TModuleProc1<FARPROC,FARPROC>
318 WSASetBlockingHook(WinSockModule(), "WSASetBlockingHook");
319 return WSASetBlockingHook(blockFunc);
320}
321
322int
324{
325 static TModuleProc0<int> WSACancelBlockingCall(WinSockModule(), "WSACancelBlockingCall");
326 return WSACancelBlockingCall();
327}
328
329HANDLE
330TWinSockDll::WSAAsyncGetServByName(HWND hWnd, uint msg, LPCSTR name,
331 LPCSTR proto, char * buf, int bufLen)
332{
333 static TModuleProc6<HANDLE,HWND,uint,LPCSTR,LPCSTR,
334 char *,int> WSAAsyncGetServByName(WinSockModule(), "WSAAsyncGetServByName");
335 return WSAAsyncGetServByName(hWnd, msg, name, proto, buf, bufLen);
336}
337
338HANDLE
340 LPCSTR proto, char * buf, int bufLen)
341{
342 static TModuleProc6<HANDLE,HWND,uint,int,LPCSTR,char *,int>
343 WSAAsyncGetServByPort(WinSockModule(), "WSAAsyncGetServByPort");
344 return WSAAsyncGetServByPort(hWnd, msg, port, proto, buf, bufLen);
345}
346
347HANDLE
348TWinSockDll::WSAAsyncGetProtoByName(HWND hWnd, uint msg, LPCSTR name,
349 char * buf, int bufLen)
350{
351 static TModuleProc5<HANDLE,HWND,uint,LPCSTR,char *,int>
352 WSAAsyncGetProtoByName(WinSockModule(), "WSAAsyncGetProtoByName");
353 return WSAAsyncGetProtoByName(hWnd, msg, name, buf, bufLen);
354}
355
356HANDLE
358 char * buf, int bufLen)
359{
360 static TModuleProc5<HANDLE,HWND,uint,int,char *,int>
361 WSAAsyncGetProtoByNumber(WinSockModule(), "WSAAsyncGetProtoByNumber");
362 return WSAAsyncGetProtoByNumber(hWnd, msg, number, buf, bufLen);
363}
364
365HANDLE
366TWinSockDll::WSAAsyncGetHostByName(HWND hWnd, uint msg, LPCSTR name,
367 char * buf, int bufLen)
368{
369 static TModuleProc5<HANDLE,HWND,uint,LPCSTR,char *,int>
370 WSAAsyncGetHostByName(WinSockModule(), "WSAAsyncGetHostByName");
371 return WSAAsyncGetHostByName(hWnd, msg, name, buf, bufLen);
372}
373
374HANDLE
375TWinSockDll::WSAAsyncGetHostByAddr(HWND hWnd, uint msg, LPCSTR addr,
376 int len, int type, char * buf, int bufLen)
377{
378 static TModuleProc7<HANDLE,HWND,uint,LPCSTR,int,int,char *,int>
379 WSAAsyncGetHostByAddr(WinSockModule(), "WSAAsyncGetHostByAddr");
380 return WSAAsyncGetHostByAddr(hWnd, msg, addr, len, type, buf, bufLen);
381}
382
383int
385{
386 static TModuleProc1<int,HANDLE>
387 WSACancelAsyncRequest(WinSockModule(), "WSACancelAsyncRequest");
388 return WSACancelAsyncRequest(hTaskHandle);
389}
390
391int
392TWinSockDll::WSAAsyncSelect(SOCKET s, HWND hWnd, uint msg, long event)
393{
394 static TModuleProc4<int,SOCKET,HWND,uint,long>
395 WSAAsyncSelect(WinSockModule(), "WSAAsyncSelect");
396 return WSAAsyncSelect(s, hWnd, msg, event);
397}
398
399int
400TWinSockDll::WSARecvEx(SOCKET s, char * buf, int len, int * flags)
401{
402 TModuleProc4<int,SOCKET,char *,int,int *> WSARecvEx(WinSockModule(), "WSARecvEx");
403 return WSARecvEx(s, buf, len, flags);
404}
405
406TModule&
408{
409 static TModule winSockModule(WinSockDllName, true, true);
410 return winSockModule;
411}
412
413bool
418
419/// Returns true if the DLL implementing WinSock is available and loaded, or false
420/// otherwise.
421bool
426
429{
430 static TWinSockDll winSockDll;
431 return &winSockDll;
432}
433
434
435} // OWL namespace
436/* ========================================================================== */
437
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:78
The TWinSockDll class encapsulates the WinSock DLL (WINSOCK.DLL).
Definition winsock.h:52
static int getpeername(SOCKET s, struct sockaddr *name, int *nameLen)
Definition winsock.cpp:64
static struct hostent * gethostbyname(LPCSTR name)
Definition winsock.cpp:222
static ulong inet_addr(const char *cp)
Definition winsock.cpp:102
static int getsockname(SOCKET s, struct sockaddr *name, int *nameLen)
Definition winsock.cpp:72
static int select(int nfds, struct fd_set *readfds, struct fd_set *writefds, struct fd_set *exceptfds, const struct timeval *timeout)
Definition winsock.cpp:161
static BOOL WSAIsBlocking(void)
Definition winsock.cpp:301
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 struct protoent * getprotobyname(LPCSTR name)
Definition winsock.cpp:253
static FARPROC WSASetBlockingHook(FARPROC blockFunc)
Definition winsock.cpp:315
static int ioctlsocket(SOCKET s, long cmd, ulong *argp)
Definition winsock.cpp:116
static int setsockopt(SOCKET s, int level, int optName, LPCSTR optVal, int optLen)
Definition winsock.cpp:187
static ushort _ntohs(ushort netShort)
Definition winsock.cpp:138
static ulong _ntohl(ulong netLong)
Definition winsock.cpp:131
static HANDLE WSAAsyncGetHostByAddr(HWND hWnd, uint msg, LPCSTR addr, int len, int type, char *buf, int bufLen)
Definition winsock.cpp:375
static int gethostname(char *name, int nameLen)
Definition winsock.cpp:230
static HANDLE WSAAsyncGetHostByName(HWND hWnd, uint msg, LPCSTR name, char *buf, int bufLen)
Definition winsock.cpp:366
static struct hostent * gethostbyaddr(LPCSTR addr, int len, int type)
Definition winsock.cpp:214
static int shutdown(SOCKET s, int how)
Definition winsock.cpp:196
static int WSAUnhookBlockingHook(void)
Definition winsock.cpp:308
static SOCKET socket(int af, int type, int protocol)
Definition winsock.cpp:203
static int sendto(SOCKET s, LPCSTR buf, int len, int flags, const struct sockaddr *to, int toLen)
Definition winsock.cpp:178
static int listen(SOCKET s, int backlog)
Definition winsock.cpp:124
static int WSACancelBlockingCall(void)
Definition winsock.cpp:323
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 int WSAStartup(uint16 versionRequested, LPWSADATA WSAData)
Definition winsock.cpp:273
static SOCKET accept(SOCKET s, struct sockaddr *addr, int *addrLen)
Definition winsock.cpp:33
static int WSACleanup(void)
Definition winsock.cpp:280
static HANDLE WSAAsyncGetProtoByName(HWND hWnd, uint msg, LPCSTR name, char *buf, int bufLen)
Definition winsock.cpp:348
static ushort _htons(ushort hostShort)
Definition winsock.cpp:95
static struct protoent * getprotobynumber(int proto)
Definition winsock.cpp:261
static int closesocket(SOCKET s)
Definition winsock.cpp:49
static int bind(SOCKET s, struct sockaddr *addr, int nameLen)
Definition winsock.cpp:41
static int connect(SOCKET s, struct sockaddr *name, int nameLen)
Definition winsock.cpp:56
static char * inet_ntoa(struct in_addr in)
Definition winsock.cpp:109
static int getsockopt(SOCKET s, int level, int optName, char *optVal, int *optLen)
Definition winsock.cpp:80
static HANDLE WSAAsyncGetServByName(HWND hWnd, uint msg, LPCSTR name, LPCSTR proto, char *buf, int bufLen)
Definition winsock.cpp:330
static int send(SOCKET s, LPCSTR buf, int len, int flags)
Definition winsock.cpp:171
static void WSASetLastError(int error)
Definition winsock.cpp:287
static ulong _htonl(ulong hostLong)
Definition winsock.cpp:88
static int WSARecvEx(SOCKET s, char *buf, int len, int *flags)
Definition winsock.cpp:400
static HANDLE WSAAsyncGetProtoByNumber(HWND hWnd, uint msg, int number, char *buf, int bufLen)
Definition winsock.cpp:357
static TModule & WinSockModule()
Definition winsock.cpp:407
static int recvfrom(SOCKET s, char *buf, int len, int flags, struct sockaddr *from, int *fromLen)
Definition winsock.cpp:152
static int recv(SOCKET s, char *buf, int len, int flags)
Definition winsock.cpp:145
static int WSAAsyncSelect(SOCKET s, HWND hWnd, uint msg, long event)
Definition winsock.cpp:392
static bool IsAvailable()
Definition winsock.cpp:414
static bool IsAvailable(void)
Returns true if the DLL implementing WinSock is available and loaded, or false otherwise.
Definition winsock.cpp:422
static TWinSockDll * Dll(void)
Definition winsock.cpp:428
#define _T(x)
Definition cygwin.h:51
TModule(const tstring &name, bool shouldLoad=true, bool mustLoad=true, bool addToList=true)
Constructs a TModule object that is used as an alias for a DLL.
Definition module.cpp:308
bool IsLoaded() const
Returns a nonzero value if the instance handle is loaded.
Definition module.h:1263
Definition of class TModule.
Object Windows Library (OWLNext Core).
Definition animctrl.h:22
unsigned short ushort
Definition number.h:24
unsigned long ulong
Definition number.h:26
char tchar
Definition defs.h:77
OWL_DIAGINFO
Definition animctrl.cpp:14
unsigned short uint16
Definition number.h:33
unsigned int uint
Definition number.h:25
General definitions used by all ObjectWindows programs.
Main header of the Winsock OWL subsystem.