Public Member Functions | Static Public Member Functions

AppSecInc::TcpIp::CWSAStartup Class Reference

#include <WSAStartup.h>

List of all members.

Public Member Functions

 CWSAStartup ()
 Calls WSAStartup to initialize Winsock for the default version: 2.1.
 CWSAStartup (WORD version)
 Calls WSAStartup to initialize Winsock for the given version.
 CWSAStartup (int major, int minor)
 Calls WSAStartup to initialize Winsock for the given version.
 ~CWSAStartup ()
 Calls WSACleanup, if necessary.
bool wasRequestedVersionNegotiated () const
 returns true if Winsock was successfully initialized to use the requested version, false otherwise.
bool initialized () const
 returns true if Winsock was successfully initialized, false otherwise.
int ErrorCode () const
 returns the error code returnd from WSAStartup, 0 on success.
std::wstring ErrorMessage () const
 returns the error message text if there was an error, or an empty string if there was no error.
const WSADATA & WsaData () const
WORD negotiatedVersion () const
 returns the loaded version of Winsock support.
BYTE negotiatedMajorVersion () const
BYTE negotiatedMinorVersion () const
void negotiatedVersion (BYTE &major, BYTE &minor) const
void negotiatedVersion (int &major, int &minor) const
WORD highestSupportedVersion () const
void highestSupportedVersion (WORD &major, WORD &minor) const
void highestSupportedVersion (int &major, int &minor) const

Static Public Member Functions

static std::wstring ErrorMessage (int errcode)
static BYTE majorVersion (WORD version)
static BYTE minorVersion (WORD version)
static WORD packVersion (BYTE major, BYTE minor)
static WORD packVersion (int major, int minor)

Static Public Attributes

static const int default_major_version = 2
 The application is written and built for this verion of Winsock.
static const int default_minor_version = 1
static const int default_version = MAKEWORD(default_major_version, default_minor_version)

Detailed Description

Initializes Winsock in its constructor, and cleans up in the destructor.

It's safe to instantiate this class more than once, but trying to load a second instance may result in an error, such as WSAEINPROGRESS, that may clear up in time. In fact, this can happen trying to load the first instance. Because of these oddities, all information returned from WSAStartup is retained and made available.

The Winsock implementation may support higher versions: if some functionality from a later version is desired, call highestSupportedVersion() to see if it's supported.


Constructor & Destructor Documentation

CWSAStartup::CWSAStartup ( )

Calls WSAStartup to initialize Winsock for the default version: 2.1.

CWSAStartup::CWSAStartup ( WORD  version) [explicit]

Calls WSAStartup to initialize Winsock for the given version.

CWSAStartup::CWSAStartup ( int  major,
int  minor 
)

Calls WSAStartup to initialize Winsock for the given version.

CWSAStartup::~CWSAStartup ( )

Calls WSACleanup, if necessary.


Member Function Documentation

int CWSAStartup::ErrorCode ( ) const

returns the error code returnd from WSAStartup, 0 on success.

std::wstring CWSAStartup::ErrorMessage ( ) const

returns the error message text if there was an error, or an empty string if there was no error.

std::wstring CWSAStartup::ErrorMessage ( int  errcode) [static]

returns the error message text for the given error code, an empty string for no error, or "unknown error code" if the code is unknown.

WORD CWSAStartup::highestSupportedVersion ( ) const

It's possible to use a higher version's functionality, but not to call functions that only exist in the later version. These functions let you test the highest version supported by the loaded Winsock library.

void CWSAStartup::highestSupportedVersion ( WORD &  major,
WORD &  minor 
) const
void CWSAStartup::highestSupportedVersion ( int &  major,
int &  minor 
) const
bool CWSAStartup::initialized ( ) const

returns true if Winsock was successfully initialized, false otherwise.

static BYTE AppSecInc::TcpIp::CWSAStartup::majorVersion ( WORD  version) [inline, static]
static BYTE AppSecInc::TcpIp::CWSAStartup::minorVersion ( WORD  version) [inline, static]
BYTE CWSAStartup::negotiatedMajorVersion ( ) const
BYTE CWSAStartup::negotiatedMinorVersion ( ) const
void CWSAStartup::negotiatedVersion ( BYTE &  major,
BYTE &  minor 
) const
void CWSAStartup::negotiatedVersion ( int &  major,
int &  minor 
) const
WORD CWSAStartup::negotiatedVersion ( ) const

returns the loaded version of Winsock support.

static WORD AppSecInc::TcpIp::CWSAStartup::packVersion ( int  major,
int  minor 
) [inline, static]
static WORD AppSecInc::TcpIp::CWSAStartup::packVersion ( BYTE  major,
BYTE  minor 
) [inline, static]
bool CWSAStartup::wasRequestedVersionNegotiated ( ) const

returns true if Winsock was successfully initialized to use the requested version, false otherwise.

const WSADATA & CWSAStartup::WsaData ( ) const

Member Data Documentation

The application is written and built for this verion of Winsock.


The documentation for this class was generated from the following files:


© Application Security Inc. - All Rights Reserved http://msiext.codeplex.com