Sirikata
|
#include <ASIOConnectAndHandshake.hpp>
Public Member Functions | |
ASIOConnectAndHandshake (const MultiplexedSocketPtr &connection, const UUID &sharedUuid) | |
Static Public Member Functions | |
static void | connect (const ASIOConnectAndHandshakePtr &thus, const std::tr1::shared_ptr< MultiplexedSocket > &connection, const Address &address, bool noDelay) |
This function transforms the member mConnection from the PRECONNECTION socket phase to the CONNECTED socket phase It first performs a resolution on the address and handles the callback in handleResolve. | |
Private Types | |
typedef boost::system::error_code | ErrorCode |
Private Member Functions | |
void | checkHeaderContents (const std::tr1::shared_ptr< MultiplexedSocket > &connection, bool no_delay, unsigned int whichSocket, Array< uint8, TCPStream::MaxWebSocketHeaderSize > *buffer, const ErrorCode &error, std::size_t bytes_received) |
This function checks a particular sockets initial handshake header. | |
Static Private Member Functions | |
static void | checkHeader (const ASIOConnectAndHandshakePtr &thus, const std::tr1::shared_ptr< MultiplexedSocket > &connection, bool no_delay, unsigned int whichSocket, Array< uint8, TCPStream::MaxWebSocketHeaderSize > *buffer, const ErrorCode &error, std::size_t bytes_received) |
This function simply wraps checkHeaderContents having been passed a shared_ptr from an asio_callback. | |
static void | connectToIPAddress (const ASIOConnectAndHandshakePtr &thus, const MultiplexedSocketPtr &connection, const Address &address, bool no_delay, unsigned int whichSocket, const boost::asio::ip::tcp::resolver::iterator &it, const ErrorCode &error) |
This function checks if a particular sockets has connected to its destination IP address If everything is successful it will decrement the first header check integer If the last resolver fails and it is the first time, it will decrement the first header check integer below zero to indiate error and call connectionFailed If anything goes wrong and the first header check integer is already below zero it will decline to take action The buffer passed in will be deleted by this function. | |
static void | handleResolve (const ASIOConnectAndHandshakePtr &thus, const std::tr1::shared_ptr< MultiplexedSocket > &connection, const Address &address, bool no_delay, const boost::system::error_code &error, boost::asio::ip::tcp::resolver::iterator it) |
This function is a callback from the async_resolve call from ASIO initialized from the public interface connect It may get an error if the host was not found or otherwise a valid iterator to a number of ip addresses. | |
Private Attributes | |
TCPResolver | mResolver |
MultiplexedSocketWPtr | mConnection |
int | mFinishedCheckCount |
num positive checks remaining (or -n for n sockets of which at least 1 failed) | |
UUID | mHeaderUUID |
Array< uint8, TCPStream::MaxWebSocketHeaderSize > | mFirstReceivedHeader |
typedef boost::system::error_code Sirikata::Network::ASIOConnectAndHandshake::ErrorCode [private] |
Sirikata::Network::ASIOConnectAndHandshake::ASIOConnectAndHandshake | ( | const MultiplexedSocketPtr & | connection, |
const UUID & | sharedUuid | ||
) |
static void Sirikata::Network::ASIOConnectAndHandshake::checkHeader | ( | const ASIOConnectAndHandshakePtr & | thus, |
const std::tr1::shared_ptr< MultiplexedSocket > & | connection, | ||
bool | no_delay, | ||
unsigned int | whichSocket, | ||
Array< uint8, TCPStream::MaxWebSocketHeaderSize > * | buffer, | ||
const ErrorCode & | error, | ||
std::size_t | bytes_received | ||
) | [inline, static, private] |
This function simply wraps checkHeaderContents having been passed a shared_ptr from an asio_callback.
Referenced by connectToIPAddress().
void Sirikata::Network::ASIOConnectAndHandshake::checkHeaderContents | ( | const std::tr1::shared_ptr< MultiplexedSocket > & | connection, |
bool | no_delay, | ||
unsigned int | whichSocket, | ||
Array< uint8, TCPStream::MaxWebSocketHeaderSize > * | buffer, | ||
const ErrorCode & | error, | ||
std::size_t | bytes_received | ||
) | [private] |
This function checks a particular sockets initial handshake header.
If this is the first header read, it will save it for comparison If this is the nth header read and everythign is successful it will decrement the first header check integer If anything goes wrong and it is the first time, it will decrement the first header check integer below zero to indiate error and call connectionFailed If anything goes wrong and the first header check integer is already below zero it will decline to take action The buffer passed in will be deleted by this function
References Sirikata::Array< T, N, integral_type >::begin(), Sirikata::Network::MakeASIOReadBuffer(), and Sirikata::Network::TCPStream::RFC_6455.
void Sirikata::Network::ASIOConnectAndHandshake::connect | ( | const ASIOConnectAndHandshakePtr & | thus, |
const std::tr1::shared_ptr< MultiplexedSocket > & | connection, | ||
const Address & | address, | ||
bool | noDelay | ||
) | [static] |
This function transforms the member mConnection from the PRECONNECTION socket phase to the CONNECTED socket phase It first performs a resolution on the address and handles the callback in handleResolve.
If the header checks out and matches with the other live sockets to the same sockets
References Sirikata::Logging::error, Sirikata::Network::Address::getHostName(), Sirikata::Network::Address::getService(), and handleResolve().
void Sirikata::Network::ASIOConnectAndHandshake::connectToIPAddress | ( | const ASIOConnectAndHandshakePtr & | thus, |
const MultiplexedSocketPtr & | connection, | ||
const Address & | address, | ||
bool | no_delay, | ||
unsigned int | whichSocket, | ||
const boost::asio::ip::tcp::resolver::iterator & | it, | ||
const ErrorCode & | error | ||
) | [static, private] |
This function checks if a particular sockets has connected to its destination IP address If everything is successful it will decrement the first header check integer If the last resolver fails and it is the first time, it will decrement the first header check integer below zero to indiate error and call connectionFailed If anything goes wrong and the first header check integer is already below zero it will decline to take action The buffer passed in will be deleted by this function.
References Sirikata::Array< T, N, integral_type >::begin(), checkHeader(), Sirikata::Logging::error, Sirikata::Network::TCPStream::MaxWebSocketHeaderSize, and Sirikata::Network::ASIOReadBuffer::sBufferLength.
void Sirikata::Network::ASIOConnectAndHandshake::handleResolve | ( | const ASIOConnectAndHandshakePtr & | thus, |
const std::tr1::shared_ptr< MultiplexedSocket > & | connection, | ||
const Address & | address, | ||
bool | no_delay, | ||
const boost::system::error_code & | error, | ||
boost::asio::ip::tcp::resolver::iterator | it | ||
) | [static, private] |
This function is a callback from the async_resolve call from ASIO initialized from the public interface connect It may get an error if the host was not found or otherwise a valid iterator to a number of ip addresses.
Referenced by connect().
num positive checks remaining (or -n for n sockets of which at least 1 failed)
Array<uint8,TCPStream::MaxWebSocketHeaderSize> Sirikata::Network::ASIOConnectAndHandshake::mFirstReceivedHeader [private] |