The C++ framework for developing highly scalable, high performance servers on Windows platforms.

CSocket Class Reference
[RAII - Resource Acquisition Is InitializationSockets utility code]

Collaboration diagram for CSocket:

List of all members.


Detailed Description

A slightly confused class that acts as both a scope based wrapper around a SOCKET and that also provides static member functions that enable you to call wrapped socket functions on a bare SOCKET.

Public Types

typedef char TimeToLive

Public Member Functions

 CSocket ()
 Create an object that isn't attached to a SOCKET, you'll need to call Attach() before you can call any of the socket functions.
 CSocket (SOCKET theSocket)
 Creates an object that is attached to the supplied SOCKET. The object takes ownership of the SOCKET and will call AbortiveClose() on it when destroyed.
 CSocket (const CSocket &rhs)
 ~CSocket ()
CSocketoperator= (const CSocket &rhs)
void Attach (SOCKET theSocket)
 Attaches the supplied SOCKET to the object. The object takes ownership of the SOCKET and will call AbortiveClose() on it when destroyed.
SOCKET GetSocket () const
SOCKET Detach ()
 Passes ownership of the SOCKET to the caller.
void Close ()
 Issues a lingering close.
void AbortiveClose ()
 Issues a non-lingering close, data may be lost.
void Shutdown (int how)
 Shut the connection down.
void Listen (ListenBacklog backlog)
 Set the socket into listening state with a pending connection queue of the specified size.
void Bind (const IAddress &address)
 Bind the socket to the supplied local address.
DWORD TryBind (const IAddress &address)
 Bind the socket to the supplied local address.
void Connect (const IAddress &address)
 Connects the socket to the given address. Throws an exception on failure.
bool ConnectNoThrow (const IAddress &address)
 Attempts to connect the socket to the given address. Returns false on failure.
void SetReadTimeout (DWORD timeout)
void Read (BYTE *pBuffer, DWORD bufferSize, DWORD &bytesRead)
 Performs a synchronous read on the socket.
void Write (const BYTE *pData, DWORD dataLength)
 Performs a synchronous write on the socket.
CAddress GetLocalAddress () const
CAddress GetRemoteAddress () const
bool IsValid () const
 Returns true if the object is attached to a valid SOCKET.

Static Public Member Functions

static void Connect (SOCKET socket, const IAddress &address)
 Connects the supplied socket to the given address. Throws an exception on failure.
static bool ConnectNoThrow (SOCKET socket, const IAddress &address)
 Attempts to connect the supplied socket to the given address. Returns false on failure.
static CAddress GetLocalAddress (SOCKET socket)
static CAddress GetRemoteAddress (SOCKET socket)
static void JoinMulticastGroup (SOCKET socket, const IAddress &groupAddress, const IAddress &interfaceAddress)
static void BlockMulticastGroupSource (SOCKET socket, const IAddress &groupAddress, const IAddress &interfaceAddress, const IAddress &sourceAddress)
static void UnblockMulticastGroupSource (SOCKET socket, const IAddress &groupAddress, const IAddress &interfaceAddress, const IAddress &sourceAddress)
static void LeaveMulticastGroup (SOCKET socket, const IAddress &groupAddress, const IAddress &interfaceAddress)
static void IncludeMulticastSource (SOCKET socket, const IAddress &groupAddress, const IAddress &interfaceAddress, const IAddress &sourceAddress)
static void ExcludeMulticastSource (SOCKET socket, const IAddress &groupAddress, const IAddress &interfaceAddress, const IAddress &sourceAddress)
static void SetMulticastSendInterface (SOCKET socket, const IAddress &interfaceAddress, TimeToLive multicastTTL, bool enableLoopback)

Member Typedef Documentation

typedef char TimeToLive


Constructor & Destructor Documentation

CSocket (  ) 

Create an object that isn't attached to a SOCKET, you'll need to call Attach() before you can call any of the socket functions.

CSocket ( SOCKET  theSocket  )  [explicit]

Creates an object that is attached to the supplied SOCKET. The object takes ownership of the SOCKET and will call AbortiveClose() on it when destroyed.

CSocket ( const CSocket rhs  ) 

~CSocket (  ) 


Member Function Documentation

CSocket& operator= ( const CSocket rhs  ) 

void Attach ( SOCKET  theSocket  ) 

Attaches the supplied SOCKET to the object. The object takes ownership of the SOCKET and will call AbortiveClose() on it when destroyed.

SOCKET GetSocket (  )  const

SOCKET Detach (  ) 

Passes ownership of the SOCKET to the caller.

void Close (  ) 

Issues a lingering close.

void AbortiveClose (  ) 

Issues a non-lingering close, data may be lost.

void Shutdown ( int  how  ) 

Shut the connection down.

void Listen ( ListenBacklog  backlog  ) 

Set the socket into listening state with a pending connection queue of the specified size.

void Bind ( const IAddress address  ) 

Bind the socket to the supplied local address.

DWORD TryBind ( const IAddress address  ) 

Bind the socket to the supplied local address.

void Connect ( const IAddress address  ) 

Connects the socket to the given address. Throws an exception on failure.

void Connect ( SOCKET  socket,
const IAddress address 
) [static]

Connects the supplied socket to the given address. Throws an exception on failure.

bool ConnectNoThrow ( const IAddress address  ) 

Attempts to connect the socket to the given address. Returns false on failure.

bool ConnectNoThrow ( SOCKET  socket,
const IAddress address 
) [static]

Attempts to connect the supplied socket to the given address. Returns false on failure.

void SetReadTimeout ( DWORD  timeout  ) 

void Read ( BYTE pBuffer,
DWORD  bufferSize,
DWORD bytesRead 
)

Performs a synchronous read on the socket.

void Write ( const BYTE pData,
DWORD  dataLength 
)

Performs a synchronous write on the socket.

CAddress GetLocalAddress (  )  const

CAddress GetRemoteAddress (  )  const

bool IsValid (  )  const

Returns true if the object is attached to a valid SOCKET.

CAddress GetLocalAddress ( SOCKET  socket  )  [static]

CAddress GetRemoteAddress ( SOCKET  socket  )  [static]

void JoinMulticastGroup ( SOCKET  socket,
const IAddress groupAddress,
const IAddress interfaceAddress 
) [static]

void BlockMulticastGroupSource ( SOCKET  socket,
const IAddress groupAddress,
const IAddress interfaceAddress,
const IAddress sourceAddress 
) [static]

void UnblockMulticastGroupSource ( SOCKET  socket,
const IAddress groupAddress,
const IAddress interfaceAddress,
const IAddress sourceAddress 
) [static]

void LeaveMulticastGroup ( SOCKET  socket,
const IAddress groupAddress,
const IAddress interfaceAddress 
) [static]

void IncludeMulticastSource ( SOCKET  socket,
const IAddress groupAddress,
const IAddress interfaceAddress,
const IAddress sourceAddress 
) [static]

void ExcludeMulticastSource ( SOCKET  socket,
const IAddress groupAddress,
const IAddress interfaceAddress,
const IAddress sourceAddress 
) [static]

void SetMulticastSendInterface ( SOCKET  socket,
const IAddress interfaceAddress,
TimeToLive  multicastTTL,
bool  enableLoopback 
) [static]


Generated on Sun Sep 12 19:10:37 2021 for The Server Framework - v7.4 by doxygen 1.5.3