Public Member Functions | Static Public Member Functions | List of all members
AppSecInc::TcpIp::CWSAStartup Class Reference

#include <WSAStartup.h>

Public Member Functions

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

returns the loaded version of Winsock support.

void CWSAStartup::negotiatedVersion ( BYTE &  major,
BYTE &  minor 
) const
void CWSAStartup::negotiatedVersion ( int &  major,
int &  minor 
) const
static WORD AppSecInc::TcpIp::CWSAStartup::packVersion ( BYTE  major,
BYTE  minor 
)
inlinestatic
static WORD AppSecInc::TcpIp::CWSAStartup::packVersion ( int  major,
int  minor 
)
inlinestatic
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

const int AppSecInc::TcpIp::CWSAStartup::default_major_version = 2
static

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

const int AppSecInc::TcpIp::CWSAStartup::default_minor_version = 1
static
const int AppSecInc::TcpIp::CWSAStartup::default_version = MAKEWORD(default_major_version, default_minor_version)
static

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


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