Sirikata
|
#include <MultiplexedSocket.hpp>
Classes | |
class | RawRequest |
class | StreamIDCallbackPair |
Workaround for VC8 bug that does not define std::pair<Stream::StreamID,Callbacks*>::operator=. More... | |
Public Types | |
enum | SocketConnectionPhase { PRECONNECTION, WAITCONNECTING, CONNECTED, DISCONNECTED } |
Public Member Functions | |
TCPStream::StreamType | getStreamType () const |
IOStrand * | getStrand () |
public io service accessor for new stream construction | |
bool | canSendBytes (Stream::StreamID origin, size_t dataSize) const |
Finds if there is enough space to enqueue the particular bytes at this moment. | |
SocketConnectionPhase | addCallbacks (const Stream::StreamID &sid, TCPStream::Callbacks *cb) |
Adds callbacks onto the queue of callbacks-to-be-added Returns true if the callbacks will be actually used or false if the socket is already disconnected. | |
Stream::StreamID | getNewID () |
function that searches mFreeStreamIDs or uses the mHighestStreamID to find the next unused free stream ID | |
MultiplexedSocket (IOStrand *io, const Stream::SubstreamCallback &substreamCallback, TCPStream::StreamType type) | |
Constructor for a connecting stream. | |
MultiplexedSocket (IOStrand *io, const UUID &uuid, const Stream::SubstreamCallback &substreamCallback, TCPStream::StreamType type) | |
Constructor for a listening stream with a prebuilt connection of ASIO sockets. | |
void | initFromSockets (const std::vector< TCPSocket * > &sockets, size_t max_send_buffer_size) |
call after construction to setup mSockets | |
~MultiplexedSocket () | |
erase all sockets and callbacks since the refcount is now zero; | |
void | shutDownClosedStream (unsigned int controlCode, const Stream::StreamID &id) |
a stream that has been closed and the other side has agreed not to send any more packets using that ID | |
void | receiveFullChunk (unsigned int whichSocket, Stream::StreamID id, Chunk &newChunk, const Stream::PauseReceiveCallback &pauseReceive) |
Process an entire packet when received from the IO reactor thread. | |
void | receivePing (unsigned int whichSocket, MemoryReference data, bool isPong) |
Process a socket-level ping. | |
void | connectionFailedCallback (unsigned int whichSocket, const std::string &error) |
The a particular socket's connection failed This function will call all substreams disconnected methods. | |
template<class ErrorCode > | |
void | connectionFailedCallback (const ErrorCode &error) |
The connection failed to connect before any sockets had been established (ex: host not found) This function will call all substreams disconnected methods. | |
template<class ErrorCode > | |
void | connectionFailedCallback (unsigned int whichSocket, const ErrorCode &error) |
The a particular socket's connection failed This function will call all substreams disconnected methods. | |
template<class ErrorCode > | |
void | connectionFailedCallback (const ASIOSocketWrapper *whichSocket, const ErrorCode &error) |
The a particular socket's connection failed This function will call all substreams disconnected methods. | |
void | hostDisconnectedCallback (unsigned int whichSocket, const std::string &error) |
The a particular socket's connection failed This function will call all substreams disconnected methods. | |
template<class ErrorCode > | |
void | hostDisconnectedCallback (unsigned int whichSocket, const ErrorCode &error) |
The a particular socket's connection failed This function will call all substreams disconnected methods. | |
template<class ErrorCode > | |
void | hostDisconnectedCallback (const ASIOSocketWrapper *whichSocket, const ErrorCode &error) |
The a particular socket's connection failed This function will call all substreams disconnected methods. | |
void | connectedCallback () |
The a particular established a connection: This function will call all substreams connected methods. | |
void | unpauseSendStreams (const std::vector< Stream::StreamID > &toUnpause) |
void | connect (const Address &address, unsigned int numSockets, size_t maxEnqueuedSendSize, bool noDelay, unsigned int kernelSendBufferSize, unsigned int kernelReceiveBufferSize) |
Connect a newly constructed MultiplexedSocket to a given address. | |
void | prepareConnect (unsigned int numSockets, size_t maxEnqueuedSendSize, bool noDelay, unsigned int kernelSendBufferSize, unsigned int kernelReceiveBufferSize) |
Prepare a socket for an outbound connection. | |
unsigned int | numSockets () const |
ASIOSocketWrapper & | getASIOSocketWrapper (unsigned int whichSocket) |
const ASIOSocketWrapper & | getASIOSocketWrapper (unsigned int whichSocket) const |
Address | getRemoteEndpoint (Stream::StreamID id) const |
Address | getLocalEndpoint (Stream::StreamID id) const |
Duration | averageSendLatency () const |
Duration | averageReceiveLatency () const |
Static Public Member Functions | |
static void | closeStream (const MultiplexedSocketPtr &thus, const Stream::StreamID &sid, TCPStream::TCPStreamControlCodes code=TCPStream::TCPStreamCloseStream) |
Sends a packet telling the other side that this stream is closed (or alternatively if its a closeAck that the close request was received and no further packets for that stream will be sent with that streamID. | |
static bool | sendBytes (const MultiplexedSocketPtr &thus, const RawRequest &data, unsigned int maxSendQueueSize=2147483647) |
Either sends or queues bytes in the data request depending on the connection state if the state is not connected then it must take a lock and place them on the mNewRequests queue. | |
static Stream::StreamID | getFirstStreamID (bool connector) |
gets the first stream ID for a newly created stream | |
static void | sendAllProtocolHeaders (const MultiplexedSocketPtr &thus, const std::string &origin, const std::string &host, const std::string &port, const std::string &resource_name, const std::string &subprotocol, bool doSendSubProtocol, const std::map< TCPSocket *, std::string > &response, TCPStream::StreamType streamType) |
Sends the protocol headers to all ASIO socket wrappers when a known fully open connection has been listened for. | |
static void | ioReactorThreadResumeRead (const MultiplexedSocketWPtr &, Stream::StreamID id) |
static void | ioReactorThreadPauseSend (const MultiplexedSocketWPtr &mp, Stream::StreamID id) |
Private Types | |
typedef std::tr1::unordered_map < Stream::StreamID, TCPStream::Callbacks *, Stream::StreamID::Hasher > | CallbackMap |
Private Member Functions | |
void | ioReactorThreadCommitCallback (StreamIDCallbackPair &newcallback) |
Copies items from newcallback to mCallbacks: must be called from the single io thread so no one would be looking to call the callbacks at the same time. | |
bool | CommitCallbacks (std::deque< StreamIDCallbackPair > ®istration, SocketConnectionPhase status, bool setConnectedStatus=false) |
reads the current list of id-callback pairs to the registration list and if setConectedStatus is set, changes the status of the overall MultiplexedSocket at the same time | |
size_t | leastBusyStream (size_t preferredStream) |
Returns the least busy stream upon which unordered data may be piled. It will always favor preferred stream if that is less busy. | |
float | dropChance (const Chunk *data, size_t whichStream) |
chance in the current load that an unreliable packet may be dropped (due to busy queues, etc). | |
void | connectionFailureOrSuccessCallback (SocketConnectionPhase status, Stream::ConnectionStatus reportedProblem, const std::string &errorMessage=std::string()) |
Calls the connected callback with the succeess or failure status. | |
void | connectionFailedCallback (const std::string &error) |
The connection failed before any sockets were established (or as a helper function after they have been cleaned) This function will call all substreams disconnected methods. | |
void | hostDisconnectedCallback (const std::string &error) |
The connection failed before any sockets were established (or as a helper function after they have been cleaned) This function will call all substreams disconnected methods. | |
Static Private Member Functions | |
static bool | sendBytesNow (const MultiplexedSocketPtr &thus, const RawRequest &data, bool force) |
sends bytes to the network directly. | |
Private Attributes | |
IOStrand * | mIO |
ASIO strand which guarantees serialized callbacks. | |
std::vector< ASIOSocketWrapper > | mSockets |
a vector of ASIO sockets (wrapped in with a simple send-full-packet abstraction) | |
Stream::SubstreamCallback | mNewSubstreamCallback |
This callback is called whenever a newly encountered StreamID is picked up. | |
SizedThreadSafeQueue < RawRequest > * | mNewRequests |
list of packets that must be sent before mSocketConnectionPhase switches to CONNECTION | |
volatile SocketConnectionPhase | mSocketConnectionPhase |
must be set to PRECONNECTION when items are being placed on mNewRequests queue and WAITCONNECTING when it is emptying the queue (with lock held) and finally CONNECTED when the user can send directly to the socket. DISCONNECTED must be set as soon as the socket fails to write or read | |
std::deque< StreamIDCallbackPair > | mCallbackRegistration |
This is a list of items for callback registration so that when packets are received by those streamIDs the appropriate callback may be called. | |
CallbackMap | mCallbacks |
a map of ID to callback, only to be touched by the io reactor thread | |
TCPStream::StreamType | mStreamType |
Whether the streams are zero delimited and in a base64 encoding (useful for interaction with web sockets) | |
std::tr1::unordered_map < Stream::StreamID, unsigned int, Stream::StreamID::Hasher > | mAckedClosingStreams |
a map from StreamID to count of number of acked close requests--to avoid any unordered packets coming in | |
std::tr1::unordered_set < Stream::StreamID, Stream::StreamID::Hasher > | mOneSidedClosingStreams |
a set of StreamIDs to hold the streams that were requested closed but have not been acknowledged, to prevent received packets triggering NewStream callbacks as if a new ID were received | |
AtomicValue< uint32 > | mHighestStreamID |
The highest streamID that has been used for making new streams on this side. | |
ThreadSafeStack< Stream::StreamID > | mFreeStreamIDs |
actually free stream IDs that will not be sent out until recalimed by this side | |
Static Private Attributes | |
static boost::mutex | sConnectingMutex |
these next items (mCallbackRegistration, mNewRequests, mSocketConnectionPhase) are synced together take the lock, check for preconnection,,, if connected, don't take lock...otherwise take lock and push data onto the new requests queue | |
Friends | |
class | ASIOReadBuffer |
typedef std::tr1::unordered_map<Stream::StreamID,TCPStream::Callbacks*,Stream::StreamID::Hasher> Sirikata::Network::MultiplexedSocket::CallbackMap [private] |
Sirikata::Network::MultiplexedSocket::MultiplexedSocket | ( | IOStrand * | io, |
const Stream::SubstreamCallback & | substreamCallback, | ||
TCPStream::StreamType | type | ||
) |
Constructor for a connecting stream.
References mNewRequests, mSocketConnectionPhase, mStreamType, and PRECONNECTION.
Sirikata::Network::MultiplexedSocket::MultiplexedSocket | ( | IOStrand * | io, |
const UUID & | uuid, | ||
const Stream::SubstreamCallback & | substreamCallback, | ||
TCPStream::StreamType | type | ||
) |
Constructor for a listening stream with a prebuilt connection of ASIO sockets.
References mNewRequests, mSocketConnectionPhase, mStreamType, and PRECONNECTION.
Sirikata::Network::MultiplexedSocket::~MultiplexedSocket | ( | ) |
erase all sockets and callbacks since the refcount is now zero;
References Sirikata::Logging::detailed, Sirikata::Network::Stream::ignoreSubstreamCallback(), mCallbackRegistration, mCallbacks, mNewRequests, mNewSubstreamCallback, mSockets, Sirikata::SizedThreadSafeQueue< T, ResourceMonitor, Superclass >::popAll(), sConnectingMutex, and SILOG.
MultiplexedSocket::SocketConnectionPhase Sirikata::Network::MultiplexedSocket::addCallbacks | ( | const Stream::StreamID & | sid, |
TCPStream::Callbacks * | cb | ||
) |
Adds callbacks onto the queue of callbacks-to-be-added Returns true if the callbacks will be actually used or false if the socket is already disconnected.
References mCallbackRegistration, mSocketConnectionPhase, and sConnectingMutex.
Referenced by Sirikata::Network::TCPSetCallbacks::operator()().
bool Sirikata::Network::MultiplexedSocket::canSendBytes | ( | Stream::StreamID | origin, |
size_t | dataSize | ||
) | const |
Finds if there is enough space to enqueue the particular bytes at this moment.
References CONNECTED, mSocketConnectionPhase, and mSockets.
void Sirikata::Network::MultiplexedSocket::closeStream | ( | const MultiplexedSocketPtr & | thus, |
const Stream::StreamID & | sid, | ||
TCPStream::TCPStreamControlCodes | code = TCPStream::TCPStreamCloseStream |
||
) | [static] |
Sends a packet telling the other side that this stream is closed (or alternatively if its a closeAck that the close request was received and no further packets for that stream will be sent with that streamID.
References Sirikata::Network::ASIOSocketWrapper::constructControlPacket(), Sirikata::Network::MultiplexedSocket::RawRequest::data, Sirikata::Network::MultiplexedSocket::RawRequest::originStream, sendBytes(), Sirikata::Network::MultiplexedSocket::RawRequest::unordered, and Sirikata::Network::MultiplexedSocket::RawRequest::unreliable.
Referenced by Sirikata::Network::TCPStream::close(), and receiveFullChunk().
bool Sirikata::Network::MultiplexedSocket::CommitCallbacks | ( | std::deque< StreamIDCallbackPair > & | registration, |
SocketConnectionPhase | status, | ||
bool | setConnectedStatus = false |
||
) | [private] |
reads the current list of id-callback pairs to the registration list and if setConectedStatus is set, changes the status of the overall MultiplexedSocket at the same time
References CONNECTED, Sirikata::SelfWeakPtr< MultiplexedSocket >::getSharedPtr(), ioReactorThreadCommitCallback(), mCallbackRegistration, mNewRequests, mSocketConnectionPhase, Sirikata::SizedThreadSafeQueue< T, ResourceMonitor, Superclass >::popAll(), sConnectingMutex, sendBytesNow(), and WAITCONNECTING.
Referenced by connectionFailureOrSuccessCallback(), receiveFullChunk(), shutDownClosedStream(), and unpauseSendStreams().
void Sirikata::Network::MultiplexedSocket::connect | ( | const Address & | address, |
unsigned int | numSockets, | ||
size_t | maxEnqueuedSendSize, | ||
bool | noDelay, | ||
unsigned int | kernelSendBufferSize, | ||
unsigned int | kernelReceiveBufferSize | ||
) |
Connect a newly constructed MultiplexedSocket to a given address.
address | is a protocol-agnostic string of endpoint and service ID |
numSockets | indicates how many TCP sockets should manage the orderlessness of this connection |
maxEnqueuedSendSize | the maximum number of enqueued bytes for sending that have not been committed to the underlying network implementation. |
noDelay | if true, disables Nagle's algorithm on the underling sockets. |
kernelSendBufferSize | the size of the buffer allocated for sending data in the underlying networking implementation. Note that this is additional space on top of that allocated by this library. |
kernelReceiveBufferSize | the size of the buffer allocated for receiving data in the underlying networking implementation. Note that this is additional space on top of that allocated by this library. |
References Sirikata::SelfWeakPtr< MultiplexedSocket >::getSharedPtr(), prepareConnect(), and Sirikata::UUID::random().
void Sirikata::Network::MultiplexedSocket::connectedCallback | ( | ) | [inline] |
The a particular established a connection: This function will call all substreams connected methods.
References Sirikata::Network::Stream::Connected, CONNECTED, and connectionFailureOrSuccessCallback().
void Sirikata::Network::MultiplexedSocket::connectionFailedCallback | ( | unsigned int | whichSocket, |
const std::string & | error | ||
) |
The a particular socket's connection failed This function will call all substreams disconnected methods.
References connectionFailedCallback().
void Sirikata::Network::MultiplexedSocket::connectionFailedCallback | ( | const ErrorCode & | error | ) | [inline] |
The connection failed to connect before any sockets had been established (ex: host not found) This function will call all substreams disconnected methods.
References connectionFailedCallback().
void Sirikata::Network::MultiplexedSocket::connectionFailedCallback | ( | const std::string & | error | ) | [private] |
The connection failed before any sockets were established (or as a helper function after they have been cleaned) This function will call all substreams disconnected methods.
References Sirikata::Network::Stream::ConnectionFailed, connectionFailureOrSuccessCallback(), and DISCONNECTED.
Referenced by connectionFailedCallback().
void Sirikata::Network::MultiplexedSocket::connectionFailedCallback | ( | unsigned int | whichSocket, |
const ErrorCode & | error | ||
) | [inline] |
The a particular socket's connection failed This function will call all substreams disconnected methods.
References connectionFailedCallback().
void Sirikata::Network::MultiplexedSocket::connectionFailedCallback | ( | const ASIOSocketWrapper * | whichSocket, |
const ErrorCode & | error | ||
) | [inline] |
The a particular socket's connection failed This function will call all substreams disconnected methods.
References connectionFailedCallback(), and mSockets.
void Sirikata::Network::MultiplexedSocket::connectionFailureOrSuccessCallback | ( | SocketConnectionPhase | status, |
Stream::ConnectionStatus | reportedProblem, | ||
const std::string & | errorMessage = std::string() |
||
) | [private] |
Calls the connected callback with the succeess or failure status.
Sets status while holding the sConnectingMutex lock so that after that point no more Connected responses will be sent out. Then inserts the registrations into the mCallbacks map during the ioReactor thread.
References CommitCallbacks(), Sirikata::Network::Stream::Connected, Sirikata::Network::Stream::ignoreConnectionCallback(), and mCallbacks.
Referenced by connectedCallback(), connectionFailedCallback(), and hostDisconnectedCallback().
float Sirikata::Network::MultiplexedSocket::dropChance | ( | const Chunk * | data, |
size_t | whichStream | ||
) | [private] |
chance in the current load that an unreliable packet may be dropped (due to busy queues, etc).
ASIOSocketWrapper& Sirikata::Network::MultiplexedSocket::getASIOSocketWrapper | ( | unsigned int | whichSocket | ) | [inline] |
References mSockets.
Referenced by Sirikata::Network::ASIOReadBuffer::processError().
const ASIOSocketWrapper& Sirikata::Network::MultiplexedSocket::getASIOSocketWrapper | ( | unsigned int | whichSocket | ) | const [inline] |
References mSockets.
Stream::StreamID Sirikata::Network::MultiplexedSocket::getFirstStreamID | ( | bool | connector | ) | [static] |
gets the first stream ID for a newly created stream
References Sirikata::Network::TCPStream::sFragmentPackets.
Referenced by Sirikata::Network::ASIOStreamBuilder::buildStream(), and Sirikata::Network::TCPStream::connect().
Address Sirikata::Network::MultiplexedSocket::getLocalEndpoint | ( | Stream::StreamID | id | ) | const |
References CONNECTED, mSocketConnectionPhase, mSockets, and Sirikata::Network::Address::null().
Stream::StreamID Sirikata::Network::MultiplexedSocket::getNewID | ( | ) |
function that searches mFreeStreamIDs or uses the mHighestStreamID to find the next unused free stream ID
References mFreeStreamIDs, and mHighestStreamID.
Address Sirikata::Network::MultiplexedSocket::getRemoteEndpoint | ( | Stream::StreamID | id | ) | const |
References CONNECTED, mSocketConnectionPhase, mSockets, and Sirikata::Network::Address::null().
IOStrand* Sirikata::Network::MultiplexedSocket::getStrand | ( | ) | [inline] |
public io service accessor for new stream construction
References mIO.
TCPStream::StreamType Sirikata::Network::MultiplexedSocket::getStreamType | ( | ) | const [inline] |
References mStreamType.
void Sirikata::Network::MultiplexedSocket::hostDisconnectedCallback | ( | unsigned int | whichSocket, |
const ErrorCode & | error | ||
) | [inline] |
The a particular socket's connection failed This function will call all substreams disconnected methods.
References hostDisconnectedCallback().
void Sirikata::Network::MultiplexedSocket::hostDisconnectedCallback | ( | const std::string & | error | ) | [private] |
The connection failed before any sockets were established (or as a helper function after they have been cleaned) This function will call all substreams disconnected methods.
References connectionFailureOrSuccessCallback(), Sirikata::Network::Stream::Disconnected, and DISCONNECTED.
Referenced by hostDisconnectedCallback(), Sirikata::Network::ASIOReadBuffer::processError(), and Sirikata::Network::triggerMultiplexedConnectionError().
void Sirikata::Network::MultiplexedSocket::hostDisconnectedCallback | ( | unsigned int | whichSocket, |
const std::string & | error | ||
) |
The a particular socket's connection failed This function will call all substreams disconnected methods.
References hostDisconnectedCallback().
void Sirikata::Network::MultiplexedSocket::hostDisconnectedCallback | ( | const ASIOSocketWrapper * | whichSocket, |
const ErrorCode & | error | ||
) | [inline] |
The a particular socket's connection failed This function will call all substreams disconnected methods.
References hostDisconnectedCallback(), and mSockets.
void Sirikata::Network::MultiplexedSocket::initFromSockets | ( | const std::vector< TCPSocket * > & | sockets, |
size_t | max_send_buffer_size | ||
) |
call after construction to setup mSockets
References ASIO_SEND_BUFFER_SIZE, Sirikata::SelfWeakPtr< MultiplexedSocket >::getSharedPtr(), and mSockets.
void Sirikata::Network::MultiplexedSocket::ioReactorThreadCommitCallback | ( | StreamIDCallbackPair & | newcallback | ) | [private] |
Copies items from newcallback to mCallbacks: must be called from the single io thread so no one would be looking to call the callbacks at the same time.
References Sirikata::Logging::error, Sirikata::Network::MultiplexedSocket::StreamIDCallbackPair::mCallback, mCallbacks, Sirikata::Network::MultiplexedSocket::StreamIDCallbackPair::mID, mOneSidedClosingStreams, Sirikata::Network::MultiplexedSocket::StreamIDCallbackPair::pair(), and SILOG.
Referenced by CommitCallbacks().
void Sirikata::Network::MultiplexedSocket::ioReactorThreadPauseSend | ( | const MultiplexedSocketWPtr & | mp, |
Stream::StreamID | id | ||
) | [static] |
Referenced by Sirikata::Network::TCPStream::requestReadySendCallback().
void Sirikata::Network::MultiplexedSocket::ioReactorThreadResumeRead | ( | const MultiplexedSocketWPtr & | weak_thus, |
Stream::StreamID | id | ||
) | [static] |
Referenced by Sirikata::Network::TCPStream::readyRead().
size_t Sirikata::Network::MultiplexedSocket::leastBusyStream | ( | size_t | preferredStream | ) | [private] |
Returns the least busy stream upon which unordered data may be piled. It will always favor preferred stream if that is less busy.
References mSockets.
unsigned int Sirikata::Network::MultiplexedSocket::numSockets | ( | ) | const [inline] |
References mSockets.
Referenced by prepareConnect(), and sendAllProtocolHeaders().
void Sirikata::Network::MultiplexedSocket::prepareConnect | ( | unsigned int | numSockets, |
size_t | maxEnqueuedSendSize, | ||
bool | noDelay, | ||
unsigned int | kernelSendBufferSize, | ||
unsigned int | kernelReceiveBufferSize | ||
) |
Prepare a socket for an outbound connection.
After this call messages may be queued and number of redundant connections set Additionally this socket may now be cloned
References ASIO_SEND_BUFFER_SIZE, Sirikata::SelfWeakPtr< MultiplexedSocket >::getSharedPtr(), mSocketConnectionPhase, mSockets, numSockets(), and PRECONNECTION.
Referenced by connect().
void Sirikata::Network::MultiplexedSocket::receiveFullChunk | ( | unsigned int | whichSocket, |
Stream::StreamID | id, | ||
Chunk & | newChunk, | ||
const Stream::PauseReceiveCallback & | pauseReceive | ||
) |
Process an entire packet when received from the IO reactor thread.
Control packets come in on Stream::StreamID() and others should be directed to the appropriate callback
References closeStream(), CommitCallbacks(), CONNECTED, Sirikata::SelfWeakPtr< MultiplexedSocket >::getSharedPtr(), mAckedClosingStreams, Sirikata::Network::TCPStream::Callbacks::mBytesReceivedCallback, Sirikata::Network::TCPSetCallbacks::mCallbacks, mCallbacks, mNewSubstreamCallback, mOneSidedClosingStreams, mSockets, shutDownClosedStream(), SILOG, Sirikata::Network::TCPStream::TCPStreamAckCloseStream, Sirikata::Network::TCPStream::TCPStreamCloseStream, and Sirikata::Logging::warning.
void Sirikata::Network::MultiplexedSocket::receivePing | ( | unsigned int | whichSocket, |
MemoryReference | data, | ||
bool | isPong | ||
) |
Process a socket-level ping.
If expectPong, send a pong as a reply.
References Sirikata::Network::ASIOSocketWrapper::constructPing(), Sirikata::SelfWeakPtr< MultiplexedSocket >::getSharedPtr(), and mSockets.
void Sirikata::Network::MultiplexedSocket::sendAllProtocolHeaders | ( | const MultiplexedSocketPtr & | thus, |
const std::string & | origin, | ||
const std::string & | host, | ||
const std::string & | port, | ||
const std::string & | resource_name, | ||
const std::string & | subprotocol, | ||
bool | doSendSubProtocol, | ||
const std::map< TCPSocket *, std::string > & | response, | ||
TCPStream::StreamType | streamType | ||
) | [static] |
Sends the protocol headers to all ASIO socket wrappers when a known fully open connection has been listened for.
References CONNECTED, Sirikata::Network::MakeASIOReadBuffer(), numSockets(), and sConnectingMutex.
Referenced by Sirikata::Network::ASIOStreamBuilder::buildStream().
bool Sirikata::Network::MultiplexedSocket::sendBytes | ( | const MultiplexedSocketPtr & | thus, |
const RawRequest & | data, | ||
unsigned int | maxSendQueueSize = 2147483647 |
||
) | [static] |
Either sends or queues bytes in the data request depending on the connection state if the state is not connected then it must take a lock and place them on the mNewRequests queue.
References CONNECTED, Sirikata::Network::MultiplexedSocket::RawRequest::data, DISCONNECTED, PRECONNECTION, Sirikata::SizedThreadSafeQueue< T, ResourceMonitor, Superclass >::push(), sConnectingMutex, sendBytesNow(), and TCPSSTLOG.
Referenced by closeStream(), and Sirikata::Network::TCPStream::send().
bool Sirikata::Network::MultiplexedSocket::sendBytesNow | ( | const MultiplexedSocketPtr & | thus, |
const RawRequest & | data, | ||
bool | force | ||
) | [static, private] |
sends bytes to the network directly.
assumes that the mSocketConnectionPhase in the CONNECTED state
References Sirikata::Network::MultiplexedSocket::RawRequest::data, Sirikata::Network::MultiplexedSocket::RawRequest::originStream, TCPSSTLOG, Sirikata::Network::MultiplexedSocket::RawRequest::unordered, and Sirikata::Network::MultiplexedSocket::RawRequest::unreliable.
Referenced by CommitCallbacks(), and sendBytes().
void Sirikata::Network::MultiplexedSocket::shutDownClosedStream | ( | unsigned int | controlCode, |
const Stream::StreamID & | id | ||
) |
a stream that has been closed and the other side has agreed not to send any more packets using that ID
References Sirikata::Network::TCPStream::closeSendStatus(), CommitCallbacks(), CONNECTED, Sirikata::Network::Stream::Disconnected, mCallbacks, mFreeStreamIDs, mHighestStreamID, mOneSidedClosingStreams, Sirikata::AtomicValue< T >::read(), and Sirikata::Network::TCPStream::TCPStreamCloseStream.
Referenced by receiveFullChunk().
void Sirikata::Network::MultiplexedSocket::unpauseSendStreams | ( | const std::vector< Stream::StreamID > & | toUnpause | ) |
References CommitCallbacks(), CONNECTED, Sirikata::Logging::debug, mCallbacks, and SILOG.
friend class ASIOReadBuffer [friend] |
std::tr1::unordered_map<Stream::StreamID,unsigned int,Stream::StreamID::Hasher> Sirikata::Network::MultiplexedSocket::mAckedClosingStreams [private] |
a map from StreamID to count of number of acked close requests--to avoid any unordered packets coming in
Referenced by receiveFullChunk().
std::deque<StreamIDCallbackPair> Sirikata::Network::MultiplexedSocket::mCallbackRegistration [private] |
This is a list of items for callback registration so that when packets are received by those streamIDs the appropriate callback may be called.
Referenced by addCallbacks(), CommitCallbacks(), and ~MultiplexedSocket().
a map of ID to callback, only to be touched by the io reactor thread
Referenced by connectionFailureOrSuccessCallback(), ioReactorThreadCommitCallback(), receiveFullChunk(), shutDownClosedStream(), unpauseSendStreams(), and ~MultiplexedSocket().
ThreadSafeStack<Stream::StreamID> Sirikata::Network::MultiplexedSocket::mFreeStreamIDs [private] |
actually free stream IDs that will not be sent out until recalimed by this side
Referenced by getNewID(), and shutDownClosedStream().
AtomicValue<uint32> Sirikata::Network::MultiplexedSocket::mHighestStreamID [private] |
The highest streamID that has been used for making new streams on this side.
Referenced by getNewID(), and shutDownClosedStream().
ASIO strand which guarantees serialized callbacks.
Referenced by getStrand().
list of packets that must be sent before mSocketConnectionPhase switches to CONNECTION
Referenced by CommitCallbacks(), MultiplexedSocket(), and ~MultiplexedSocket().
This callback is called whenever a newly encountered StreamID is picked up.
Referenced by receiveFullChunk(), and ~MultiplexedSocket().
std::tr1::unordered_set<Stream::StreamID,Stream::StreamID::Hasher> Sirikata::Network::MultiplexedSocket::mOneSidedClosingStreams [private] |
a set of StreamIDs to hold the streams that were requested closed but have not been acknowledged, to prevent received packets triggering NewStream callbacks as if a new ID were received
Referenced by ioReactorThreadCommitCallback(), receiveFullChunk(), and shutDownClosedStream().
volatile SocketConnectionPhase Sirikata::Network::MultiplexedSocket::mSocketConnectionPhase [private] |
must be set to PRECONNECTION when items are being placed on mNewRequests queue and WAITCONNECTING when it is emptying the queue (with lock held) and finally CONNECTED when the user can send directly to the socket. DISCONNECTED must be set as soon as the socket fails to write or read
Referenced by addCallbacks(), canSendBytes(), CommitCallbacks(), getLocalEndpoint(), getRemoteEndpoint(), MultiplexedSocket(), and prepareConnect().
std::vector<ASIOSocketWrapper> Sirikata::Network::MultiplexedSocket::mSockets [private] |
a vector of ASIO sockets (wrapped in with a simple send-full-packet abstraction)
Referenced by averageReceiveLatency(), averageSendLatency(), canSendBytes(), connectionFailedCallback(), getASIOSocketWrapper(), getLocalEndpoint(), getRemoteEndpoint(), hostDisconnectedCallback(), initFromSockets(), leastBusyStream(), numSockets(), prepareConnect(), receiveFullChunk(), receivePing(), and ~MultiplexedSocket().
Whether the streams are zero delimited and in a base64 encoding (useful for interaction with web sockets)
Referenced by getStreamType(), and MultiplexedSocket().
boost::mutex Sirikata::Network::MultiplexedSocket::sConnectingMutex [static, private] |
these next items (mCallbackRegistration, mNewRequests, mSocketConnectionPhase) are synced together take the lock, check for preconnection,,, if connected, don't take lock...otherwise take lock and push data onto the new requests queue
Referenced by addCallbacks(), CommitCallbacks(), sendAllProtocolHeaders(), sendBytes(), and ~MultiplexedSocket().