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
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
TWinSock is an alias for an instance of the TDllLoader template which ensures the underlying DLL is l...
Definition winsock.h:150
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.