adchpp::ManagedSocket Class Reference

An asynchronous socket managed by SocketManager. More...

#include <ManagedSocket.h>

Inheritance diagram for adchpp::ManagedSocket:
Inheritance graph
[legend]
Collaboration diagram for adchpp::ManagedSocket:
Collaboration graph
[legend]

List of all members.

Public Types

typedef std::function< void()> ConnectedHandler
typedef std::function< void(const
BufferPtr &)> 
DataHandler
typedef std::function< void(const
boost::system::error_code &)> 
FailedHandler

Public Member Functions

ADCHPP_DLL void disconnect (size_t timeout, Util::Reason reason) throw ()
 Asynchronous disconnect.
const std::string & getIp () const
time_t getLastWrite ()
size_t getMaxBufferSize ()
time_t getOverflow ()
ADCHPP_DLL size_t getQueuedBytes () const
 Returns the number of bytes in the output buffer; buffers must be locked.
 ManagedSocket (const AsyncStreamPtr &sock_)
void setConnectedHandler (const ConnectedHandler &handler)
void setDataHandler (const DataHandler &handler)
void setFailedHandler (const FailedHandler &handler)
void setIp (const std::string &ip_)
void setMaxBufferSize (size_t newSize)
ADCHPP_DLL void write (const BufferPtr &buf, bool lowPrio=false) throw ()
 Asynchronous write.
 ~ManagedSocket () throw ()

Static Public Member Functions

static size_t getDefaultMaxBufferSize ()
static time_t getOverflowTimeout ()
static void setDefaultMaxBufferSize (size_t newSize)

Private Member Functions

void completeAccept (const boost::system::error_code &) throw ()
void completeRead (const boost::system::error_code &ec, size_t bytes) throw ()
void completeWrite (const boost::system::error_code &ec, size_t bytes) throw ()
void failSocket (const boost::system::error_code &error) throw ()
void prepareRead () throw ()
void prepareRead2 (const boost::system::error_code &ec, size_t bytes) throw ()
void prepareWrite () throw ()

Private Attributes

ConnectedHandler connectedHandler
DataHandler dataHandler
uint32_t disc
 Disconnection scheduled for this socket.
FailedHandler failedHandler
BufferPtr inBuf
 Input buffer used when receiving data.
std::string ip
time_t lastWrite
 Last time that a write started, 0 if no active write.
size_t maxBufferSize
 Max allowed write buffer size for this socket.
BufferList outBuf
 Output buffer, for storing data that's waiting to be transmitted.
time_t overflow
 Overflow timer, the time when the socket started to overflow.
AsyncStreamPtr sock

Static Private Attributes

static size_t defaultMaxBufferSize = 16 * 1024
static time_t overflowTimeout = 60

Friends

class SocketFactory
class SocketManager

Detailed Description

An asynchronous socket managed by SocketManager.

Definition at line 35 of file ManagedSocket.h.


Member Typedef Documentation

typedef std::function<void()> adchpp::ManagedSocket::ConnectedHandler

Definition at line 51 of file ManagedSocket.h.

typedef std::function<void(const BufferPtr&)> adchpp::ManagedSocket::DataHandler

Definition at line 53 of file ManagedSocket.h.

typedef std::function<void(const boost::system::error_code&)> adchpp::ManagedSocket::FailedHandler

Definition at line 55 of file ManagedSocket.h.


Constructor & Destructor Documentation

adchpp::ManagedSocket::ManagedSocket ( const AsyncStreamPtr sock_  )  [inline]

Definition at line 37 of file ManagedSocket.h.

adchpp::ManagedSocket::~ManagedSocket (  )  throw ()

Definition at line 35 of file ManagedSocket.cpp.

References dcdebug.


Member Function Documentation

void adchpp::ManagedSocket::completeAccept ( const boost::system::error_code &  ec  )  throw () [private]

Definition at line 180 of file ManagedSocket.cpp.

void adchpp::ManagedSocket::completeRead ( const boost::system::error_code &  ec,
size_t  bytes 
) throw () [private]

Definition at line 158 of file ManagedSocket.cpp.

References adchpp::Stats::recvBytes, and adchpp::Stats::recvCalls.

void adchpp::ManagedSocket::completeWrite ( const boost::system::error_code &  ec,
size_t  bytes 
) throw () [private]

Definition at line 98 of file ManagedSocket.cpp.

References adchpp::Stats::sendBytes, and adchpp::Stats::sendCalls.

void adchpp::ManagedSocket::disconnect ( size_t  timeout,
Util::Reason  reason 
) throw ()

Asynchronous disconnect.

Pending data will be written, but no more data will be read.

Definition at line 206 of file ManagedSocket.cpp.

References adchpp::SocketManager::addJob(), GET_TICK, adchpp::Singleton< SocketManager >::getInstance(), and adchpp::Util::reasons.

Referenced by prepareWrite().

Here is the call graph for this function:

Here is the caller graph for this function:

void adchpp::ManagedSocket::failSocket ( const boost::system::error_code &  error  )  throw () [private]

Definition at line 190 of file ManagedSocket.cpp.

References adchpp::SocketManager::errors, and adchpp::Singleton< SocketManager >::getInstance().

Referenced by prepareRead2().

Here is the call graph for this function:

Here is the caller graph for this function:

static size_t adchpp::ManagedSocket::getDefaultMaxBufferSize (  )  [inline, static]

Definition at line 66 of file ManagedSocket.h.

References defaultMaxBufferSize.

const std::string& adchpp::ManagedSocket::getIp (  )  const [inline]

Definition at line 48 of file ManagedSocket.h.

References ip.

time_t adchpp::ManagedSocket::getLastWrite (  )  [inline]

Definition at line 63 of file ManagedSocket.h.

References lastWrite.

size_t adchpp::ManagedSocket::getMaxBufferSize (  )  [inline]

Definition at line 59 of file ManagedSocket.h.

References maxBufferSize.

time_t adchpp::ManagedSocket::getOverflow (  )  [inline]

Definition at line 61 of file ManagedSocket.h.

References overflow.

static time_t adchpp::ManagedSocket::getOverflowTimeout (  )  [inline, static]

Definition at line 68 of file ManagedSocket.h.

References overflowTimeout.

size_t adchpp::ManagedSocket::getQueuedBytes (  )  const

Returns the number of bytes in the output buffer; buffers must be locked.

Definition at line 47 of file ManagedSocket.cpp.

References outBuf, and adchpp::sum().

Here is the call graph for this function:

void adchpp::ManagedSocket::prepareRead (  )  throw () [private]

Definition at line 133 of file ManagedSocket.cpp.

References sock.

void adchpp::ManagedSocket::prepareRead2 ( const boost::system::error_code &  ec,
size_t  bytes 
) throw () [private]

Definition at line 138 of file ManagedSocket.cpp.

References failSocket(), inBuf, and sock.

Here is the call graph for this function:

void adchpp::ManagedSocket::prepareWrite (  )  throw () [private]

Definition at line 89 of file ManagedSocket.cpp.

References disconnect(), adchpp::TimerManager::getTime(), lastWrite, outBuf, adchpp::Util::REASON_WRITE_TIMEOUT, and sock.

Here is the call graph for this function:

void adchpp::ManagedSocket::setConnectedHandler ( const ConnectedHandler handler  )  [inline]

Definition at line 52 of file ManagedSocket.h.

References connectedHandler.

void adchpp::ManagedSocket::setDataHandler ( const DataHandler handler  )  [inline]

Definition at line 54 of file ManagedSocket.h.

References dataHandler.

static void adchpp::ManagedSocket::setDefaultMaxBufferSize ( size_t  newSize  )  [inline, static]

Definition at line 65 of file ManagedSocket.h.

References defaultMaxBufferSize.

void adchpp::ManagedSocket::setFailedHandler ( const FailedHandler handler  )  [inline]

Definition at line 56 of file ManagedSocket.h.

References failedHandler.

void adchpp::ManagedSocket::setIp ( const std::string &  ip_  )  [inline]

Definition at line 49 of file ManagedSocket.h.

References ip.

void adchpp::ManagedSocket::setMaxBufferSize ( size_t  newSize  )  [inline]

Definition at line 58 of file ManagedSocket.h.

References maxBufferSize.

void adchpp::ManagedSocket::write ( const BufferPtr buf,
bool  lowPrio = false 
) throw ()

Friends And Related Function Documentation

friend class SocketFactory [friend]

Definition at line 76 of file ManagedSocket.h.

friend class SocketManager [friend]

Definition at line 75 of file ManagedSocket.h.


Member Data Documentation

Definition at line 108 of file ManagedSocket.h.

Referenced by setConnectedHandler().

Definition at line 109 of file ManagedSocket.h.

Referenced by setDataHandler().

size_t adchpp::ManagedSocket::defaultMaxBufferSize = 16 * 1024 [static, private]

Definition at line 72 of file ManagedSocket.h.

Referenced by getDefaultMaxBufferSize(), and setDefaultMaxBufferSize().

uint32_t adchpp::ManagedSocket::disc [private]

Disconnection scheduled for this socket.

Definition at line 98 of file ManagedSocket.h.

Definition at line 110 of file ManagedSocket.h.

Referenced by setFailedHandler().

Input buffer used when receiving data.

Definition at line 93 of file ManagedSocket.h.

Referenced by prepareRead2().

std::string adchpp::ManagedSocket::ip [private]

Definition at line 106 of file ManagedSocket.h.

Referenced by getIp(), and setIp().

Last time that a write started, 0 if no active write.

Definition at line 104 of file ManagedSocket.h.

Referenced by getLastWrite(), and prepareWrite().

Max allowed write buffer size for this socket.

Definition at line 101 of file ManagedSocket.h.

Referenced by getMaxBufferSize(), and setMaxBufferSize().

Output buffer, for storing data that's waiting to be transmitted.

Definition at line 90 of file ManagedSocket.h.

Referenced by getQueuedBytes(), and prepareWrite().

Overflow timer, the time when the socket started to overflow.

Definition at line 96 of file ManagedSocket.h.

Referenced by getOverflow().

time_t adchpp::ManagedSocket::overflowTimeout = 60 [static, private]

Definition at line 73 of file ManagedSocket.h.

Referenced by getOverflowTimeout().

Definition at line 87 of file ManagedSocket.h.

Referenced by prepareRead(), prepareRead2(), and prepareWrite().

Generated on Sat Nov 27 23:38:45 2010 for adchpp by  doxygen 1.6.3