Sirikata
|
#include <ASIOReadBuffer.hpp>
Public Types | |
enum | { sBufferLength = 64*1024, sLowWaterMark = sBufferLength } |
Public Member Functions | |
void | ioReactorThreadResumeRead (MultiplexedSocketPtr &thus) |
If read was paused by a user that could not proocess a packet This call attempts to deliver the packet to a user again If the user accepts the packet then the system is asked for future packets This function may be called if the read was not paused. | |
~ASIOReadBuffer () | |
Private Types | |
enum | ReceivedResponse { StreamNotPaused, PausedStream } |
enum | ReadStatus { PAUSED_FIXED_BUFFER = 0x0, READING_FIXED_BUFFER = 0x1, PAUSED_NEW_CHUNK = 0x2, READING_NEW_CHUNK = 0x3 } |
typedef boost::system::error_code | ErrorCode |
Private Member Functions | |
void | bindFunctions (IOStrand *strand) |
void | processError (MultiplexedSocket *parentSocket, const ErrorCode &error) |
This forwards the error message to the MultiplexedSocket so the appropriate action may be taken (including,possibly, disconnecting and shutting down the socket connections and all associated streams. | |
ReceivedResponse | processFullChunk (const MultiplexedSocketPtr &parentSocket, unsigned int whichSocket, const Stream::StreamID &sid, Chunk &newChunk, const Stream::PauseReceiveCallback &pauseReceive) |
This function passes the contents of a chunk to the multiplexed socket for callback handling. | |
void | readIntoFixedBuffer (const MultiplexedSocketPtr &parentSocket) |
This function is called when either 0 information is known about the data to be read (such as size, etc) or if the data is known but the packet is sufficiently small that other packets may be conjoined with it in the buffer This function tells asio to read data from the socket into mBuffer at offset mBufferPos upto the end of the buffer. | |
void | readIntoChunk (const MultiplexedSocketPtr &parentSocket) |
This function is called when a sufficiently large chunk needs to be filled up from a previous readIntoFixedBuffer call. | |
void | processPartialChunk (uint8 *dataBuffer, uint32 packetLength, uint32 &bufferReceived, Chunk &retval) |
Examines a buffer of bytes and converts it into a partially or totally filled chunk and gives back information about unprocessed bytes and the StreamID that sent the chunk Updates mNewChunkId with the StreamID that this chunk was sent from. | |
void | translateFixedBuffer (const MultiplexedSocketPtr &thus) |
Examines the class variable mBuffer from the beginning to mBufferPos and translates all packets contained within to chunks and calls the appropriate callback If the information in the last unprocessed chunk is less than sLowWaterMark that excess information is moved to the front of the buffer and readIntoFixedBuffer is called If the information in the last unprocessed chunk is greater than the sLowWaterMark then a new chunk is made specifically for the remaining data using the processPartialChunk function and readIntoChunk is called. | |
void | asioReadIntoChunk (const ErrorCode &error, std::size_t bytes_read) |
The ASIO callback when ASIO was reading into a singleChunk The function reacts to errors by calling processErrors or a missing MultiplexedSocket by deleting this Otherwise the function reacts to a partially full packet by calling readIntoFixedChunk and a full packet by calling processFullChunk to invoke appropriate callbacks then readIntoFixedBuffer. | |
void | asioReadIntoFixedBuffer (const ErrorCode &error, std::size_t bytes_read) |
The ASIO callback when ASIO was reading into the mBuffer from mBufferPos The function reacts to errors by calling processErrors or a missing MultiplexedSocket by deleting this Otherwise the function farms work off to translateBuffer. | |
ASIOReadBuffer (const MultiplexedSocketPtr &parentSocket, unsigned int whichSocket, TCPStream::StreamType streamType) | |
ASIOReadBuffer (const ASIOReadBuffer &) | |
unimplemented: will fail due to bound function | |
Private Attributes | |
enum Sirikata::Network::ASIOReadBuffer::ReadStatus | mReadStatus |
uint8 | mBuffer [sBufferLength] |
A fixed length buffer to read incoming requests when the data is unknown in size or so far small in size. | |
unsigned int | mFixedBufferPos |
Where is ASIO writing to in mBuffer. | |
unsigned int | mChunkBufferPos |
std::vector< uint8 > | mPartialStreamId |
if a header is delivered in a chunk that's too small to contain it, need to hold the bytes temporarily | |
bool | mFirstFrame |
First frame in a series of continuations (has stream id) | |
bool | mLastFrame |
Last frame in a series of continuations (we actually process) | |
unsigned int | mWhichBuffer |
Which actual low level tcp socket from the mParentSocket is used for communication. | |
Chunk | mNewChunk |
A new chunk being read directly into--usually this member is only used to hold a large packet of information, otherwise the fixed length buffer is used. | |
Chunk * | mCachedRejectedChunk |
Stream::StreamID | mNewChunkID |
The StreamID of a new, partially examined new chunk. | |
uint8 | mDataMask [4] |
WebSocket permits packets to be XORed by a repeating 32-bit value. We need to store it after reading a partial packet. | |
TCPStream::StreamType | mStreamType |
Local copy of the stream type to avoid locking. | |
std::tr1::weak_ptr < MultiplexedSocket > | mParentSocket |
The shared structure responsible for holding state about the associated TCPStream that this class reads and interprets data from. | |
std::tr1::function< void(const ErrorCode &, std::size_t)> | mAsioReadIntoFixedBuffer |
std::tr1::function< void(const ErrorCode &, std::size_t)> | mAsioReadIntoChunk |
Friends | |
struct | ASIOReadBufferUtil |
ASIOReadBuffer * | MakeASIOReadBuffer (const MultiplexedSocketPtr &parentSocket, unsigned int whichSocket, const MemoryReference &strayBytesAfterHeader, TCPStream::StreamType streamType) |
The only public interface to TCPReadBuffer is the constructor-like-function which takes in a MultiplexedSocket and an integer offset. |
typedef boost::system::error_code Sirikata::Network::ASIOReadBuffer::ErrorCode [private] |
anonymous enum |
enum Sirikata::Network::ASIOReadBuffer::ReadStatus [private] |
enum Sirikata::Network::ASIOReadBuffer::ReceivedResponse [private] |
Sirikata::Network::ASIOReadBuffer::ASIOReadBuffer | ( | const MultiplexedSocketPtr & | parentSocket, |
unsigned int | whichSocket, | ||
TCPStream::StreamType | streamType | ||
) | [private] |
Sirikata::Network::ASIOReadBuffer::ASIOReadBuffer | ( | const ASIOReadBuffer & | ) | [private] |
unimplemented: will fail due to bound function
Sirikata::Network::ASIOReadBuffer::~ASIOReadBuffer | ( | ) |
void Sirikata::Network::ASIOReadBuffer::asioReadIntoChunk | ( | const ErrorCode & | error, |
std::size_t | bytes_read | ||
) | [private] |
The ASIO callback when ASIO was reading into a singleChunk The function reacts to errors by calling processErrors or a missing MultiplexedSocket by deleting this Otherwise the function reacts to a partially full packet by calling readIntoFixedChunk and a full packet by calling processFullChunk to invoke appropriate callbacks then readIntoFixedBuffer.
References Sirikata::Network::ASIOReadBufferUtil::_pause_receive_callback__status_full(), Sirikata::Network::BufferPrint(), mChunkBufferPos, mFixedBufferPos, mNewChunk, mNewChunkID, mParentSocket, mReadStatus, mWhichBuffer, PAUSED_NEW_CHUNK, processError(), processFullChunk(), readIntoChunk(), readIntoFixedBuffer(), StreamNotPaused, and TCPSSTLOG.
Referenced by bindFunctions().
void Sirikata::Network::ASIOReadBuffer::asioReadIntoFixedBuffer | ( | const ErrorCode & | error, |
std::size_t | bytes_read | ||
) | [private] |
The ASIO callback when ASIO was reading into the mBuffer from mBufferPos The function reacts to errors by calling processErrors or a missing MultiplexedSocket by deleting this Otherwise the function farms work off to translateBuffer.
References Sirikata::Network::BufferPrint(), mBuffer, mFixedBufferPos, mParentSocket, processError(), TCPSSTLOG, and translateFixedBuffer().
Referenced by bindFunctions(), and Sirikata::Network::MakeASIOReadBuffer().
void Sirikata::Network::ASIOReadBuffer::bindFunctions | ( | IOStrand * | strand | ) | [private] |
References asioReadIntoChunk(), asioReadIntoFixedBuffer(), mAsioReadIntoChunk, mAsioReadIntoFixedBuffer, and Sirikata::Network::IOStrand::wrap().
Referenced by ASIOReadBuffer().
void Sirikata::Network::ASIOReadBuffer::ioReactorThreadResumeRead | ( | MultiplexedSocketPtr & | thus | ) |
If read was paused by a user that could not proocess a packet This call attempts to deliver the packet to a user again If the user accepts the packet then the system is asked for future packets This function may be called if the read was not paused.
References Sirikata::Network::ASIOReadBufferUtil::_pause_receive_callback_noop(), mFixedBufferPos, mNewChunk, mNewChunkID, mReadStatus, mWhichBuffer, PAUSED_FIXED_BUFFER, PAUSED_NEW_CHUNK, processFullChunk(), READING_FIXED_BUFFER, READING_NEW_CHUNK, readIntoFixedBuffer(), StreamNotPaused, and translateFixedBuffer().
void Sirikata::Network::ASIOReadBuffer::processError | ( | MultiplexedSocket * | parentSocket, |
const ErrorCode & | error | ||
) | [private] |
This forwards the error message to the MultiplexedSocket so the appropriate action may be taken (including,possibly, disconnecting and shutting down the socket connections and all associated streams.
References Sirikata::Network::ASIOSocketWrapper::clearReadBuffer(), Sirikata::Network::MultiplexedSocket::getASIOSocketWrapper(), Sirikata::Network::MultiplexedSocket::hostDisconnectedCallback(), and mWhichBuffer.
Referenced by asioReadIntoChunk(), and asioReadIntoFixedBuffer().
ASIOReadBuffer::ReceivedResponse Sirikata::Network::ASIOReadBuffer::processFullChunk | ( | const MultiplexedSocketPtr & | parentSocket, |
unsigned int | whichSocket, | ||
const Stream::StreamID & | sid, | ||
Chunk & | newChunk, | ||
const Stream::PauseReceiveCallback & | pauseReceive | ||
) | [private] |
This function passes the contents of a chunk to the multiplexed socket for callback handling.
parentSocket | is the MultiplexedSocket responsible for this stream with the relevant callback information |
whichSocket | is the current ASIO socket responsible for having read the data. It must equal mWhichBuffer |
sid | is the StreamID that sent the data which made it to this socket and got processed. It will help determine which callback to call |
newChunk | is the chunk that was sent from the other side to this side and is ready for client processing (or server processing if sid==Stream::StreamID()) |
pauseReceive | callback which pauses receiving packets on the stream |
References Sirikata::Network::ASIOReadBufferUtil::_mark_pause_bool_true(), mChunkBufferPos, mDataMask, mLastFrame, mNewChunk, PausedStream, and StreamNotPaused.
Referenced by asioReadIntoChunk(), ioReactorThreadResumeRead(), and translateFixedBuffer().
void Sirikata::Network::ASIOReadBuffer::processPartialChunk | ( | uint8 * | dataBuffer, |
uint32 | packetLength, | ||
uint32 & | bufferReceived, | ||
Chunk & | retval | ||
) | [private] |
Examines a buffer of bytes and converts it into a partially or totally filled chunk and gives back information about unprocessed bytes and the StreamID that sent the chunk Updates mNewChunkId with the StreamID that this chunk was sent from.
dataBuffer | is the buffer to be read and turned into an active Chunk |
packetLength | is the length of the to-be-returned Chunk plus the length of that chunk's streamID |
bufferReceived | is the length of the dataBuffer, and the value returned in the bufferReceived is number of useful bytes copied to the returned chunk |
retval | is the newly allocated chunk sized appropriately to hold all data that will ever be copied to it |
References Sirikata::Logging::debug, mChunkBufferPos, mDataMask, mFirstFrame, mLastFrame, mNewChunkID, mPartialStreamId, and SILOG.
Referenced by translateFixedBuffer().
void Sirikata::Network::ASIOReadBuffer::readIntoChunk | ( | const MultiplexedSocketPtr & | parentSocket | ) | [private] |
This function is called when a sufficiently large chunk needs to be filled up from a previous readIntoFixedBuffer call.
This function will tell ASIO to read directly into the mNewChunk class, offset by the mBufferPos upto the value of mNewChunk.size()
References mAsioReadIntoChunk, mChunkBufferPos, mNewChunk, mReadStatus, mWhichBuffer, and READING_NEW_CHUNK.
Referenced by asioReadIntoChunk(), and translateFixedBuffer().
void Sirikata::Network::ASIOReadBuffer::readIntoFixedBuffer | ( | const MultiplexedSocketPtr & | parentSocket | ) | [private] |
This function is called when either 0 information is known about the data to be read (such as size, etc) or if the data is known but the packet is sufficiently small that other packets may be conjoined with it in the buffer This function tells asio to read data from the socket into mBuffer at offset mBufferPos upto the end of the buffer.
References mAsioReadIntoFixedBuffer, mBuffer, mFixedBufferPos, mReadStatus, mWhichBuffer, READING_FIXED_BUFFER, and sBufferLength.
Referenced by asioReadIntoChunk(), ioReactorThreadResumeRead(), Sirikata::Network::MakeASIOReadBuffer(), and translateFixedBuffer().
void Sirikata::Network::ASIOReadBuffer::translateFixedBuffer | ( | const MultiplexedSocketPtr & | thus | ) | [private] |
Examines the class variable mBuffer from the beginning to mBufferPos and translates all packets contained within to chunks and calls the appropriate callback If the information in the last unprocessed chunk is less than sLowWaterMark that excess information is moved to the front of the buffer and readIntoFixedBuffer is called If the information in the last unprocessed chunk is greater than the sLowWaterMark then a new chunk is made specifically for the remaining data using the processPartialChunk function and readIntoChunk is called.
References Sirikata::Network::ASIOReadBufferUtil::_pause_receive_callback__status_full(), mBuffer, mChunkBufferPos, mDataMask, mFirstFrame, mFixedBufferPos, mLastFrame, mNewChunk, mNewChunkID, mReadStatus, mStreamType, mWhichBuffer, PAUSED_FIXED_BUFFER, processFullChunk(), processPartialChunk(), Sirikata::VariableLength::read(), readIntoChunk(), readIntoFixedBuffer(), Sirikata::Network::TCPStream::RFC_6455, sLowWaterMark, StreamNotPaused, and Sirikata::VariableLength::unserialize().
Referenced by asioReadIntoFixedBuffer(), and ioReactorThreadResumeRead().
friend struct ASIOReadBufferUtil [friend] |
ASIOReadBuffer* MakeASIOReadBuffer | ( | const MultiplexedSocketPtr & | parentSocket, |
unsigned int | whichSocket, | ||
const MemoryReference & | strayBytesAfterHeader, | ||
TCPStream::StreamType | streamType | ||
) | [friend] |
The only public interface to TCPReadBuffer is the constructor-like-function which takes in a MultiplexedSocket and an integer offset.
parentSocket | the MultiplexedSocket which defines the whole connection (if the weak_ptr fails, the connection is bunk |
whichSocket | indicates which substream this read buffer is for, so the appropriate ASIO socket can be retrieved |
std::tr1::function<void(const ErrorCode&,std::size_t)> Sirikata::Network::ASIOReadBuffer::mAsioReadIntoChunk [private] |
Referenced by bindFunctions(), and readIntoChunk().
std::tr1::function<void(const ErrorCode&,std::size_t)> Sirikata::Network::ASIOReadBuffer::mAsioReadIntoFixedBuffer [private] |
Referenced by bindFunctions(), and readIntoFixedBuffer().
uint8 Sirikata::Network::ASIOReadBuffer::mBuffer[sBufferLength] [private] |
A fixed length buffer to read incoming requests when the data is unknown in size or so far small in size.
Referenced by asioReadIntoFixedBuffer(), Sirikata::Network::MakeASIOReadBuffer(), readIntoFixedBuffer(), and translateFixedBuffer().
Referenced by ASIOReadBuffer().
unsigned int Sirikata::Network::ASIOReadBuffer::mChunkBufferPos [private] |
Referenced by ASIOReadBuffer(), asioReadIntoChunk(), processFullChunk(), processPartialChunk(), readIntoChunk(), and translateFixedBuffer().
uint8 Sirikata::Network::ASIOReadBuffer::mDataMask[4] [private] |
WebSocket permits packets to be XORed by a repeating 32-bit value. We need to store it after reading a partial packet.
Referenced by ASIOReadBuffer(), processFullChunk(), processPartialChunk(), and translateFixedBuffer().
bool Sirikata::Network::ASIOReadBuffer::mFirstFrame [private] |
First frame in a series of continuations (has stream id)
Referenced by ASIOReadBuffer(), processPartialChunk(), and translateFixedBuffer().
unsigned int Sirikata::Network::ASIOReadBuffer::mFixedBufferPos [private] |
Where is ASIO writing to in mBuffer.
Referenced by ASIOReadBuffer(), asioReadIntoChunk(), asioReadIntoFixedBuffer(), ioReactorThreadResumeRead(), readIntoFixedBuffer(), and translateFixedBuffer().
bool Sirikata::Network::ASIOReadBuffer::mLastFrame [private] |
Last frame in a series of continuations (we actually process)
Referenced by ASIOReadBuffer(), processFullChunk(), processPartialChunk(), and translateFixedBuffer().
A new chunk being read directly into--usually this member is only used to hold a large packet of information, otherwise the fixed length buffer is used.
Referenced by asioReadIntoChunk(), ioReactorThreadResumeRead(), processFullChunk(), readIntoChunk(), and translateFixedBuffer().
The StreamID of a new, partially examined new chunk.
Referenced by asioReadIntoChunk(), ioReactorThreadResumeRead(), processPartialChunk(), and translateFixedBuffer().
std::tr1::weak_ptr<MultiplexedSocket> Sirikata::Network::ASIOReadBuffer::mParentSocket [private] |
The shared structure responsible for holding state about the associated TCPStream that this class reads and interprets data from.
Referenced by asioReadIntoChunk(), and asioReadIntoFixedBuffer().
std::vector<uint8> Sirikata::Network::ASIOReadBuffer::mPartialStreamId [private] |
if a header is delivered in a chunk that's too small to contain it, need to hold the bytes temporarily
Referenced by processPartialChunk().
Local copy of the stream type to avoid locking.
Referenced by ASIOReadBuffer(), and translateFixedBuffer().
unsigned int Sirikata::Network::ASIOReadBuffer::mWhichBuffer [private] |
Which actual low level tcp socket from the mParentSocket is used for communication.
Referenced by ASIOReadBuffer(), asioReadIntoChunk(), ioReactorThreadResumeRead(), processError(), readIntoChunk(), readIntoFixedBuffer(), and translateFixedBuffer().