ServerSocket Class Reference

Socket connection, disconnection, and buffered data receives. More...

Inheritance diagram for ServerSocket:

MemCacheClient::Server

List of all members.

Public Member Functions

 ServerSocket ()
 constructor
 ~ServerSocket ()
 destructor
bool Connect (unsigned long a_nIpAddress, int a_nPort, int a_nTimeout)
 connect the socket to an address
bool IsConnected () const
 Determine if we are currently connected to a server.
void Disconnect ()
 Disconnect from the server.
void SendBytes (const char *a_pszBuf, size_t a_nBufSiz)
 Send the supplied bytes to the server.
int GetBytes (char *a_pszBuf, int a_nBufSiz)
 Receive a block of data from the server.
void DiscardBytes (int a_nBytes)
 Receive and discard bytes.
char GetByte ()
 Receive a single byte.

Private Member Functions

 ServerSocket (const ServerSocket &)
 copy constructor is disabled
ServerSocketoperator= (const ServerSocket &)
 copy operator is disabled
int ReceiveBytes (char *a_pszBuf, int a_nBufSiz)
 Receive data into a buffer with as many bytes as possible up to the size of the buffer.

Private Attributes

SOCKET mSocket
 socket being abstracted
char mBuf [MAXBUF]
 internal data buffer
int mIdx
 current read index for mBuf
int mBufLen
 current end index for mBuf

Static Private Attributes

static const int MAXBUF = 1024
 size of internal data buffer

Classes

class  Exception
 Exception thrown on any send or receive error. More...


Detailed Description

Socket connection, disconnection, and buffered data receives.

Definition at line 61 of file MemCacheClient.cpp.


Member Function Documentation

int ServerSocket::ReceiveBytes ( char *  a_pszBuf,
int  a_nBufSiz 
) [private]

Receive data into a buffer with as many bytes as possible up to the size of the buffer.

Parameters:
a_pszBuf Buffer to be filled
a_nBufSiz Maximum number of bytes to receive
Returns:
number of bytes actually received

Definition at line 268 of file MemCacheClient.cpp.

References Disconnect(), and mSocket.

Referenced by DiscardBytes(), GetByte(), and GetBytes().

bool ServerSocket::Connect ( unsigned long  a_nIpAddress,
int  a_nPort,
int  a_nTimeout 
)

connect the socket to an address

Parameters:
a_nIpAddress Server IP address as returned from inet_addr
a_nPort Server port
a_nTimeout Connection timeout period in milliseconds

Definition at line 193 of file MemCacheClient.cpp.

References Disconnect(), and mSocket.

Referenced by MemCacheClient::Server::Connect().

void ServerSocket::SendBytes ( const char *  a_pszBuf,
size_t  a_nBufSiz 
)

Send the supplied bytes to the server.

A blocking send is used, so the function will block until either all bytes are sent or an error occurs.

Parameters:
a_pszBuf Bytes to send to the server
a_nBufSiz Number of bytes to send to the server
Exceptions:
Exception on socket error

Definition at line 252 of file MemCacheClient.cpp.

References Disconnect(), and mSocket.

Referenced by MemCacheClient::Combine(), MemCacheClient::FlushAll(), MemCacheClient::IncDec(), and MemCacheClient::Store().

int ServerSocket::GetBytes ( char *  a_pszBuf,
int  a_nBufSiz 
)

Receive a block of data from the server.

Parameters:
a_pszBuf Buffer to receive the data into
a_nBufSiz Maximum number of bytes to be received
Returns:
number of bytes that were actually received
Exceptions:
Exception on socket error

Definition at line 282 of file MemCacheClient.cpp.

References mBuf, mBufLen, mIdx, and ReceiveBytes().

Referenced by MemCacheClient::HandleGetResponse().

void ServerSocket::DiscardBytes ( int  a_nBytes  ) 

Receive and discard bytes.

Parameters:
a_nBytes Number of bytes to be received and ignored.
Exceptions:
Exception on socket error

Definition at line 299 of file MemCacheClient.cpp.

References MAXBUF, mBuf, mBufLen, mIdx, and ReceiveBytes().

Referenced by MemCacheClient::HandleGetResponse().

char ServerSocket::GetByte (  )  [inline]

Receive a single byte.

Returns:
received byte
Exceptions:
Exception on socket error

Definition at line 144 of file MemCacheClient.cpp.

References MAXBUF, mBuf, mBufLen, mIdx, and ReceiveBytes().

Referenced by MemCacheClient::FlushAll(), MemCacheClient::HandleDelResponse(), MemCacheClient::HandleGetResponse(), MemCacheClient::HandleStoreResponse(), and MemCacheClient::IncDec().


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

Generated on Tue Jun 3 17:24:05 2008 for MemCacheClient by  doxygen 1.5.6