OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
winsock.h
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/// Main header of the Winsock OWL subsystem.
7//----------------------------------------------------------------------------
8
9#if !defined(OWL_WINSOCK_H)
10#define OWL_WINSOCK_H
11
12#include <owl/private/defs.h>
13#if defined(BI_HAS_PRAGMA_ONCE)
14# pragma once
15#endif
16
17#include <owl/module.h>
18
19#pragma pack(push, 8)
20#include <winsock.h>
21#pragma pack(pop)
22
23#include <owl/wskaddr.h>
24#include <owl/wsksock.h>
25#include <owl/wskerr.h>
26#include <owl/wskhostm.h>
27#include <owl/wsksockd.h>
28#include <owl/wsksockm.h>
29#include <owl/wskservm.h>
30
31
32namespace owl {
33
34#include <owl/preclass.h>
35
36//
37/// \class TWinSockDll
38// ~~~~~ ~~~~~~~~~~~
39/// The TWinSockDll class encapsulates the WinSock DLL (WINSOCK.DLL). It provides an
40/// easy method to dynamically test for the availability of the DLL and bind to its
41/// exported functions at runtime. By using the TWinSockDll class instead of direct
42/// calls to the WinSock DLL, ObjectWindows applications can provide the appropriate
43/// behaviour when running in an environment where the DLL is not available.
44///
45/// Each data member of the TWinSockDll class corresponds to the API with a similar
46/// name exposed by the WinSock DLL. For example, TWinSockDll::WSAStartup
47/// corresponds to the WSAStartup API exported by the WinSock DLL.
48///
49/// For more information about the members, consult
50/// the documentation about the corresponding API exposed by the WinSock DLL.
51//
53 public:
55
56 // Socket functions
57 //
58 static SOCKET accept(SOCKET s, struct sockaddr * addr,
59 int * addrLen);
60 static int bind(SOCKET s, struct sockaddr * addr, int nameLen);
61 static int closesocket(SOCKET s);
62 static int connect(SOCKET s, struct sockaddr * name, int nameLen);
63 static int getpeername(SOCKET s, struct sockaddr * name,
64 int * nameLen);
65 static int getsockname(SOCKET s, struct sockaddr * name,
66 int * nameLen);
67 static int getsockopt(SOCKET s, int level, int optName, char * optVal,
68 int * optLen);
69 static ulong _htonl(ulong hostLong);
70 static ushort _htons(ushort hostShort);
71 static ulong inet_addr(const char * cp);
72 static char * inet_ntoa(struct in_addr in);
73 static int ioctlsocket(SOCKET s, long cmd, ulong * argp);
74 static int listen(SOCKET s, int backlog);
75 static ulong _ntohl(ulong netLong);
76 static ushort _ntohs(ushort netShort);
77 static int recv(SOCKET s, char * buf, int len, int flags);
78 static int recvfrom(SOCKET s, char * buf, int len, int flags,
79 struct sockaddr * from, int* fromLen);
80 static int select(int nfds, struct fd_set * readfds,
81 struct fd_set * writefds,
82 struct fd_set * exceptfds,
83 const struct timeval * timeout);
84 static int send(SOCKET s, LPCSTR buf, int len, int flags);
85 static int sendto(SOCKET s, LPCSTR buf, int len, int flags,
86 const struct sockaddr * to, int toLen);
87 static int setsockopt(SOCKET s, int level, int optName,
88 LPCSTR optVal, int optLen);
89 static int shutdown(SOCKET s, int how);
90 static SOCKET socket(int af, int type, int protocol);
91
92 // Database functions
93 //
94 static struct hostent * gethostbyaddr(LPCSTR addr, int len, int type);
95 static struct hostent * gethostbyname(LPCSTR name);
96 static int gethostname(char * name, int nameLen);
97 static struct servent * getservbyname(LPCSTR name, LPCSTR proto);
98 static struct servent * getservbyport(int port, LPCSTR proto);
99 static struct protoent * getprotobyname(LPCSTR name);
100 static struct protoent * getprotobynumber(int proto);
101
102 // Microsoft Windows Extension functions
103 //
104 static int WSAStartup(uint16 versionRequested, LPWSADATA WSAData);
105 static int WSACleanup(void);
106 static void WSASetLastError(int error);
107 static int WSAGetLastError(void);
108 static BOOL WSAIsBlocking(void);
109 static int WSAUnhookBlockingHook(void);
110 static FARPROC WSASetBlockingHook(FARPROC blockFunc);
111 static int WSACancelBlockingCall(void);
112 static HANDLE WSAAsyncGetServByName(HWND hWnd, uint msg, LPCSTR name,
113 LPCSTR proto, char * buf, int bufLen);
114 static HANDLE WSAAsyncGetServByPort(HWND hWnd, uint msg, int port,
115 LPCSTR proto, char * buf, int bufLen);
116 static HANDLE WSAAsyncGetProtoByName(HWND hWnd, uint msg, LPCSTR name,
117 char * buf, int bufLen);
118 static HANDLE WSAAsyncGetProtoByNumber(HWND hWnd, uint msg, int number,
119 char * buf, int bufLen);
120 static HANDLE WSAAsyncGetHostByName(HWND hWnd, uint msg, LPCSTR name,
121 char * buf, int bufLen);
122 static HANDLE WSAAsyncGetHostByAddr(HWND hWnd, uint msg, LPCSTR addr,
123 int len, int type, char * buf, int bufLen);
124 static int WSACancelAsyncRequest(HANDLE hTaskHandle);
125 static int WSAAsyncSelect(SOCKET s, HWND hWnd, uint msg, long event);
126 static int WSARecvEx(SOCKET s, char * buf, int len, int * flags);
127
128 // Check for presence of Winsock DLL
129 //
130 static TModule& WinSockModule();
131 static bool IsAvailable();
132};
133
134//
135/// \class TWinSock
136// ~~~~~ ~~~~~~~~
137/// TWinSock is an alias for an instance of the TDllLoader template which ensures
138/// the underlying DLL is loaded and available. The 'IsAvailable' method (defined by
139/// the TDllLoader template) can be used to load the DLL. For example,
140/// \code
141/// if (TWinSock::IsAvailable()) {
142/// // DLL is loaded - Proceed with WinSock calls
143/// } else {
144/// // Error - Underlying DLL is not available.
145/// }
146/// \endcode
147//
148
150{
151 public:
152 static bool IsAvailable(void);
153 static TWinSockDll* Dll(void);
154};
155
156#include <owl/posclass.h>
157
158
159} // OWL namespace
160
161
162#endif // OWL_WSKDLL_H
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
TWinSock is an alias for an instance of the TDllLoader template which ensures the underlying DLL is l...
Definition winsock.h:150
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
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
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
unsigned short uint16
Definition number.h:33
unsigned int uint
Definition number.h:25
#define _OWLCLASS
Definition defs.h:338
Main header of the Winsock OWL subsystem.
Winsock for OWL subsystem.
Winsock for OWL subsystem.
Winsock for OWL subsystem.
Winsock for OWL subsystem.
Winsock for OWL subsystem.
Winsock for OWL subsystem.
Winsock for OWL subsystem.