OWLNext
7.0
Borland's Object Windows Library for the modern age
Toggle main menu visibility
Loading...
Searching...
No Matches
wsksockm.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
13
namespace
owl
{
14
15
OWL_DIAGINFO
;
16
17
//
18
/// Default constructor. Initializes all data members to 0.
19
//
20
TSocketInfo::TSocketInfo
()
21
{
22
wVersion = 0;
23
wHighVersion = 0;
24
szDescription[0] = 0;
25
szSystemStatus[0] = 0;
26
iMaxSockets = 0;
27
iMaxUdpDg = 0;
28
lpVendorInfo = 0;
29
}
30
31
//----------------------------------------------------------------------------
32
33
//
34
/// The SocketManager constructor takes a major and minor version as parameters.
35
/// These version parameters are the Winsock versions that can be requested, as with
36
/// WSAStartup() calls.
37
//
38
TSocketManager::TSocketManager
(
short
versionMajor,
short
versionMinor,
bool
autoStartup)
39
{
40
TWinSock::IsAvailable
();
// !CQ throw an exception if not?
41
42
StartupCount
= 0;
43
Init
(versionMajor, versionMinor);
44
if
(autoStartup)
45
Startup
();
46
}
47
48
//
49
/// The TSocketManager destructor cleans up after itself. Every time Startup() (same
50
/// as WSAStartup()) is called, this destructor will call ShutDown (same as
51
/// WSACleanup()).
52
//
53
TSocketManager::~TSocketManager
()
54
{
55
while
(
StartupCount
)
56
ShutDown
();
// Call ShutDown() enough times to equal times Startup() was called.
57
}
58
59
//
60
/// The ITSocketManager function does some initialization for the TSocketManager.
61
/// This function is separate from the constructor so it can be called at any time
62
/// to re-specify the desired major and minor versions before a call to Startup().
63
/// nNewVersionMajor and nNewVersionMinor will be the values specified in the
64
/// Winsock WSAStartup() call that TSocketManager::Startup() makes. The return value
65
/// is TRUE or FALSE.
66
//
67
void
TSocketManager::Init
(
short
versionMajor,
short
versionMinor)
68
{
69
LastError
= 0;
70
VersionMajor
= versionMajor;
71
VersionMinor
= versionMinor;
72
}
73
74
//
75
/// The Startup() function is equivalent to the Winsock WSAStartup() function. This
76
/// function fills out the TSocketManager's SocketInfo structure (same as a WSAData
77
/// structure) with the return information. GetMaxSocketsAvailable(),
78
/// GetVendorInfo(), Available(), GetMajorVersion(), GetMinorVersion(), or
79
/// Information() functions can then be called to get the results of the call.
80
//
81
int
TSocketManager::Startup
()
82
{
83
uint16
packedValues = (
uint16
)(((
uint16
)
VersionMinor
) << 8) |
84
(
uint16
)
VersionMajor
;
85
LastError
=
TWinSockDll::WSAStartup
(packedValues, &
SocketInfo
);
86
if
(
LastError
)
87
return
WINSOCK_ERROR
;
88
89
StartupCount
++;
90
VersionMajor
=
HiUint8
(
SocketInfo
.wVersion);
91
VersionMinor
=
LoUint8
(
SocketInfo
.wVersion);
92
93
return
WINSOCK_NOERROR
;
94
}
95
96
//
97
/// The ShutDown() function is the equivalent to the Winsock WSACleanup() function.
98
/// You can call this function if you want, but in its destructor, the
99
/// TSocketManager will automatically call it once for every time Startup() was
100
/// called. Of course, the TSocketManager cannot know about any independent
101
/// WSAStartup() direct calls that are made.
102
//
103
int
TSocketManager::ShutDown
()
104
{
105
if
(
TWinSockDll::WSACleanup
()) {
106
LastError
=
TWinSockDll::WSAGetLastError
();
107
return
WINSOCK_ERROR
;
108
}
109
StartupCount
--;
110
return
WINSOCK_NOERROR
;
111
}
112
113
}
// OWL namespace
114
/* ========================================================================== */
115
owl::TSocketInfo::TSocketInfo
TSocketInfo()
Default constructor. Initializes all data members to 0.
Definition
wsksockm.cpp:20
owl::TSocketManager::Startup
int Startup()
The Startup() function is equivalent to the Winsock WSAStartup() function.
Definition
wsksockm.cpp:81
owl::TSocketManager::LastError
int LastError
Last error code.
Definition
wsksockm.h:70
owl::TSocketManager::StartupCount
short StartupCount
Make sure to not overflow number of connects.
Definition
wsksockm.h:72
owl::TSocketManager::Init
void Init(short versionMajor=1, short versionMinor=1)
The ITSocketManager function does some initialization for the TSocketManager.
Definition
wsksockm.cpp:67
owl::TSocketManager::TSocketManager
TSocketManager(short versionMajor=1, short versionMinor=1, bool autoStartup=true)
The SocketManager constructor takes a major and minor version as parameters.
Definition
wsksockm.cpp:38
owl::TSocketManager::ShutDown
int ShutDown()
The ShutDown() function is the equivalent to the Winsock WSACleanup() function.
Definition
wsksockm.cpp:103
owl::TSocketManager::~TSocketManager
virtual ~TSocketManager()
The TSocketManager destructor cleans up after itself.
Definition
wsksockm.cpp:53
owl::TSocketManager::VersionMajor
short VersionMajor
Major verion number.
Definition
wsksockm.h:74
owl::TSocketManager::SocketInfo
TSocketInfo SocketInfo
Information about this WinSocket implementation.
Definition
wsksockm.h:73
owl::TSocketManager::VersionMinor
short VersionMinor
Minor verion number.
Definition
wsksockm.h:75
owl::TWinSockDll::WSAGetLastError
static int WSAGetLastError(void)
Definition
winsock.cpp:294
owl::TWinSockDll::WSAStartup
static int WSAStartup(uint16 versionRequested, LPWSADATA WSAData)
Definition
winsock.cpp:273
owl::TWinSockDll::WSACleanup
static int WSACleanup(void)
Definition
winsock.cpp:280
owl::TWinSock::IsAvailable
static bool IsAvailable(void)
Returns true if the DLL implementing WinSock is available and loaded, or false otherwise.
Definition
winsock.cpp:422
pch.h
owl
Object Windows Library (OWLNext Core).
Definition
animctrl.h:22
owl::OWL_DIAGINFO
OWL_DIAGINFO
Definition
animctrl.cpp:14
owl::HiUint8
uint8 HiUint8(LRESULT r)
Definition
defs.h:282
owl::uint16
unsigned short uint16
Definition
number.h:33
owl::LoUint8
uint8 LoUint8(LRESULT r)
Definition
defs.h:276
defs.h
General definitions used by all ObjectWindows programs.
winsock.h
Main header of the Winsock OWL subsystem.
WINSOCK_NOERROR
#define WINSOCK_NOERROR
Definition
wskhostm.h:30
WINSOCK_ERROR
#define WINSOCK_ERROR
Definition
wskhostm.h:31
source
owlcore
wsksockm.cpp
Generated by
1.18.0