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
33TWinSockDll::accept(SOCKET s, struct sockaddr * addr, int * addrLen)
34{
36 accept(WinSockModule(), "accept");
37 return accept(s, addr, addrLen);
38}
39
40int
41TWinSockDll::bind(SOCKET s, struct sockaddr * addr, int nameLen)
42{
44 bind(WinSockModule(), "bind");
45 return bind(s, addr, nameLen);
46}
47
48int
54
55int
56TWinSockDll::connect(SOCKET s, struct sockaddr * name, int nameLen)
57{
59 connect(WinSockModule(), "connect");
60 return connect(s, name, nameLen);
61}
62
63int
64TWinSockDll::getpeername(SOCKET s, struct sockaddr * name, int * nameLen)
65{
67 getpeername(WinSockModule(), "getpeername");
68 return getpeername(s, name, nameLen);
69}
70
71int
72TWinSockDll::getsockname(SOCKET s, struct sockaddr * name, int * nameLen)
73{
75 getsockname(WinSockModule(), "getsockname");
76 return getsockname(s, name, nameLen);
77}
78
79int
86
93
100
101ulong
103{
105 return inet_addr(cp);
106}
107
108char *
114
115int
117{
119 ioctlsocket(WinSockModule(), "ioctlsocket");
120 return ioctlsocket(s, cmd, argp);
121}
122
123int
125{
127 return listen(s, backlog);
128}
129
130ulong
136
137ushort
143
144int
145TWinSockDll::recv(SOCKET s, char * buf, int len, int flags)
146{
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{
156 recvfrom(WinSockModule(), "recvfrom");
157 return recvfrom(s, buf, len, flags, from, fromLen);
158}
159
160int
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");
168}
169
170int
171TWinSockDll::send(SOCKET s, LPCSTR buf, int len, int flags)
172{
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{
182 const struct sockaddr *,int> sendto(WinSockModule(), "sendto");
183 return sendto(s, buf, len, flags, to, toLen);
184}
185
186int
194
195int
197{
199 return shutdown(s, how);
200}
201
202SOCKET
204{
206 return socket(af, type, protocol);
207}
208
209//
210// Database functions
211//
212
213struct hostent *
220
221struct hostent *
228
229int
231{
233 return gethostname(name, nameLen);
234}
235
236struct servent *
243
244struct servent *
251
252struct protoent *
259
260struct protoent *
267
268//
269// Microsoft Windows Extension functions
270//
271
272int
278
279int
281{
282 static TModuleProc0<int> WSACleanup(WinSockModule(), "WSACleanup");
283 return WSACleanup();
284}
285
286void
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
321
322int
324{
325 static TModuleProc0<int> WSACancelBlockingCall(WinSockModule(), "WSACancelBlockingCall");
326 return WSACancelBlockingCall();
327}
328
329HANDLE
331 LPCSTR proto, char * buf, int bufLen)
332{
334 char *,int> WSAAsyncGetServByName(WinSockModule(), "WSAAsyncGetServByName");
336}
337
338HANDLE
346
347HANDLE
355
356HANDLE
364
365HANDLE
373
374HANDLE
382
383int
390
391int
398
399int
400TWinSockDll::WSARecvEx(SOCKET s, char * buf, int len, int * flags)
401{
403 return WSARecvEx(s, buf, len, flags);
404}
405
406TModule&
408{
409 static TModule winSockModule(WinSockDllName, true, true);
410 return winSockModule;
411}
412
413bool
415{
416 return WinSockModule().IsLoaded();
417}
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:75
The TWinSockDll class encapsulates the WinSock DLL (WINSOCK.DLL).
Definition winsock.h:48
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
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.