本文整理汇总了C++中OutputMessage_ptr::getMessageLength方法的典型用法代码示例。如果您正苦于以下问题:C++ OutputMessage_ptr::getMessageLength方法的具体用法?C++ OutputMessage_ptr::getMessageLength怎么用?C++ OutputMessage_ptr::getMessageLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OutputMessage_ptr
的用法示例。
在下文中一共展示了OutputMessage_ptr::getMessageLength方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: send
bool Connection::send(OutputMessage_ptr msg)
{
m_connectionLock.lock();
if(m_closeState == CLOSE_STATE_CLOSING || m_writeError)
{
m_connectionLock.unlock();
return false;
}
msg->getProtocol()->onSendMessage(msg);
if(m_pendingWrite == 0)
{
#ifdef __DEBUG_NET_DETAIL__
std::clog << "Connection::send " << msg->getMessageLength() << std::endl;
#endif
internalSend(msg);
}
else
{
#ifdef __DEBUG_NET__
std::clog << "Connection::send Adding to queue " << msg->getMessageLength() << std::endl;
#endif
m_outputQueue.push_back(msg);
}
m_connectionLock.unlock();
return true;
}
示例2: internalSend
void Connection::internalSend(OutputMessage_ptr msg)
{
m_pendingWrite++;
boost::asio::async_write(m_socket,
boost::asio::buffer(msg->getOutputBuffer(), msg->getMessageLength()),
boost::bind(&Connection::onWriteOperation, this, msg, boost::asio::placeholders::error));
}
示例3: sendAll
void OutputMessagePool::sendAll()
{
boost::recursive_mutex::scoped_lock lockClass(m_outputPoolLock);
OutputMessageMessageList::iterator it;
for(it = m_toAddQueue.begin(); it != m_toAddQueue.end();)
{
//drop messages that are older than 10 seconds
if(OTSYS_TIME() - (*it)->getFrame() > 10 * 1000)
{
(*it)->getProtocol()->onSendMessage(*it);
it = m_toAddQueue.erase(it);
continue;
}
(*it)->setState(OutputMessage::STATE_ALLOCATED);
m_autoSendOutputMessages.push_back(*it);
++it;
}
m_toAddQueue.clear();
for(it = m_autoSendOutputMessages.begin(); it != m_autoSendOutputMessages.end();)
{
OutputMessage_ptr omsg = *it;
#ifdef __NO_PLAYER_SENDBUFFER__
//use this define only for debugging
bool v = 1;
#else
//It will send only messages bigger then 1 kb or with a lifetime greater than 10 ms
bool v = omsg->getMessageLength() > 1024 || (m_frameTime - omsg->getFrame() > 10);
#endif
if(v)
{
#ifdef __DEBUG_NET_DETAIL__
std::cout << "Sending message - ALL" << std::endl;
#endif
if(omsg->getConnection())
{
if(!omsg->getConnection()->send(omsg))
{
// Send only fails when connection is closing (or in error state)
// This call will free the message
omsg->getProtocol()->onSendMessage(omsg);
}
}
else
{
#ifdef __DEBUG_NET__
std::cout << "Error: [OutputMessagePool::send] NULL connection." << std::endl;
#endif
}
it = m_autoSendOutputMessages.erase(it);
}
else
++it;
}
}
示例4: sendAll
void OutputMessagePool::sendAll()
{
OTSYS_THREAD_LOCK_CLASS lockClass(m_outputPoolLock);
OutputMessageList::iterator it;
for(it = m_toAddQueue.begin(); it != m_toAddQueue.end();)
{
//drop messages that are older than 10 seconds
if(OTSYS_TIME() - (*it)->getFrame() > 10000)
{
if((*it)->getProtocol())
(*it)->getProtocol()->onSendMessage(*it);
it = m_toAddQueue.erase(it);
continue;
}
(*it)->setState(OutputMessage::STATE_ALLOCATED);
m_autoSendOutputMessages.push_back(*it);
++it;
}
m_toAddQueue.clear();
for(it = m_autoSendOutputMessages.begin(); it != m_autoSendOutputMessages.end(); )
{
OutputMessage_ptr omsg = (*it);
#ifdef __NO_PLAYER_SENDBUFFER__
//use this define only for debugging
if(true)
#else
//It will send only messages bigger then 1 kb or with a lifetime greater than 10 ms
if(omsg->getMessageLength() > 1024 || (m_frameTime - omsg->getFrame() > 10))
#endif
{
#ifdef __DEBUG_NET_DETAIL__
std::cout << "Sending message - ALL" << std::endl;
#endif
if(omsg->getConnection())
{
if(!omsg->getConnection()->send(omsg) && omsg->getProtocol())
omsg->getProtocol()->onSendMessage(omsg);
}
#ifdef __DEBUG_NET__
else
std::cout << "Error: [OutputMessagePool::send] NULL connection." << std::endl;
#endif
it = m_autoSendOutputMessages.erase(it);
}
else
++it;
}
}
示例5: send
bool Connection::send(OutputMessage_ptr msg)
{
#ifdef __DEBUG_NET_DETAIL__
std::cout << "Connection::send init" << std::endl;
#endif
m_connectionLock.lock();
if(m_connectionState != CONNECTION_STATE_OPEN || m_writeError){
m_connectionLock.unlock();
return false;
}
if(m_pendingWrite == 0){
msg->getProtocol()->onSendMessage(msg);
TRACK_MESSAGE(msg);
#ifdef __DEBUG_NET_DETAIL__
std::cout << "Connection::send " << msg->getMessageLength() << std::endl;
#endif
internalSend(msg);
}
else{
#ifdef __DEBUG_NET__
std::cout << "Connection::send Adding to queue " << msg->getMessageLength() << std::endl;
#endif
TRACK_MESSAGE(msg);
OutputMessagePool* outputPool = OutputMessagePool::getInstance();
outputPool->addToAutoSend(msg);
}
m_connectionLock.unlock();
return true;
}
示例6: onWriteOperation
void Connection::onWriteOperation(OutputMessage_ptr msg, const boost::system::error_code& error)
{
#ifdef __DEBUG_NET_DETAIL__
std::clog << "onWriteOperation" << std::endl;
#endif
msg.reset();
m_connectionLock.lock();
if(!error)
{
if(m_pendingWrite > 0)
{
if(!m_outputQueue.empty())
{
OutputMessage_ptr msg = m_outputQueue.front();
m_outputQueue.pop_front();
internalSend(msg);
#ifdef __DEBUG_NET_DETAIL__
std::clog << "Connection::onWriteOperation send " << msg->getMessageLength() << std::endl;
#endif
}
m_pendingWrite--;
}
else
{
std::clog << "Error: [Connection::onWriteOperation] Getting unexpected notification!" << std::endl;
// Error. Pending operations counter is 0, but we are getting a
// notification!!
}
}
else
{
m_pendingWrite--;
handleWriteError(error);
}
if(m_closeState == CLOSE_STATE_CLOSING)
{
if(!closingConnection())
m_connectionLock.lock();
return;
}
m_connectionLock.unlock();
}
示例7: internalSend
void Connection::internalSend(OutputMessage_ptr msg)
{
try {
++m_pendingWrite;
m_writeTimer.expires_from_now(boost::posix_time::seconds(Connection::write_timeout));
m_writeTimer.async_wait( std::bind(&Connection::handleWriteTimeout, std::weak_ptr<Connection>(shared_from_this()),
std::placeholders::_1));
boost::asio::async_write(getHandle(),
boost::asio::buffer(msg->getOutputBuffer(), msg->getMessageLength()),
std::bind(&Connection::onWriteOperation, shared_from_this(), msg, std::placeholders::_1));
} catch (boost::system::system_error& e) {
if (m_logError) {
std::cout << "[Network error - Connection::internalSend] " << e.what() << std::endl;
m_logError = false;
}
}
}
示例8: internalSend
void Connection::internalSend(OutputMessage_ptr msg)
{
try {
++m_pendingWrite;
m_writeTimer.expires_from_now(boost::posix_time::seconds(Connection::write_timeout));
m_writeTimer.async_wait( boost::bind(&Connection::handleWriteTimeout, boost::weak_ptr<Connection>(shared_from_this()),
boost::asio::placeholders::error));
boost::asio::async_write(getHandle(),
boost::asio::buffer(msg->getOutputBuffer(), msg->getMessageLength()),
boost::bind(&Connection::onWriteOperation, shared_from_this(), msg, boost::asio::placeholders::error));
} catch (boost::system::system_error& e) {
if (m_logError) {
LOG_MESSAGE("NETWORK", LOGTYPE_ERROR, 1, e.what());
m_logError = false;
}
}
}
示例9: parsePacket
//.........这里部分代码省略.........
break;
}
output->AddByte(AP_MSG_KEY_EXCHANGE_OK);
output->AddByte(ENCRYPTION_RSA1024XTEA);
char RSAPublicKey[128];
rsa->getPublicKey(RSAPublicKey);
output->AddBytes(RSAPublicKey, 128);
} else {
output->AddByte(AP_MSG_KEY_EXCHANGE_FAILED);
addLogLine(this, LOGTYPE_WARNING, 1, "no valid client key type");
}
} else {
output->AddByte(AP_MSG_KEY_EXCHANGE_FAILED);
output->AddString("can not get public key");
addLogLine(this, LOGTYPE_WARNING, 1, "can not get public key");
}
break;
}
case AP_MSG_COMMAND: {
if (m_state != LOGGED_IN) {
addLogLine(this, LOGTYPE_ERROR, 1, "recvbyte == AP_MSG_COMMAND && m_state != LOGGED_IN !!!");
// We should never reach this point
break;
}
uint8_t command = msg.GetByte();
switch (command) {
case CMD_BROADCAST: {
const std::string message = msg.GetString();
addLogLine(this, LOGTYPE_EVENT, 1, "broadcast: " + message);
g_dispatcher.addTask(createTask(boost::bind(&Game::broadcastMessage, &g_game, message, MSG_STATUS_WARNING)));
output->AddByte(AP_MSG_COMMAND_OK);
break;
}
case CMD_CLOSE_SERVER: {
g_dispatcher.addTask(createTask(boost::bind(&ProtocolAdmin::adminCommandCloseServer, this)));
break;
}
case CMD_PAY_HOUSES: {
g_dispatcher.addTask(createTask(boost::bind(&ProtocolAdmin::adminCommandPayHouses, this)));
break;
}
case CMD_OPEN_SERVER: {
g_dispatcher.addTask(createTask(boost::bind(&ProtocolAdmin::adminCommandOpenServer, this)));
break;
}
case CMD_SHUTDOWN_SERVER: {
g_dispatcher.addTask(createTask(boost::bind(&ProtocolAdmin::adminCommandShutdownServer, this)));
getConnection()->closeConnection();
return;
}
case CMD_KICK: {
const std::string name = msg.GetString();
g_dispatcher.addTask(createTask(boost::bind(&ProtocolAdmin::adminCommandKickPlayer, this, name)));
break;
}
case CMD_SETOWNER: {
const std::string param = msg.GetString();
g_dispatcher.addTask(createTask(boost::bind(&ProtocolAdmin::adminCommandSetOwner, this, param)));
break;
}
default: {
output->AddByte(AP_MSG_COMMAND_FAILED);
output->AddString("not known server command");
addLogLine(this, LOGTYPE_WARNING, 1, "not known server command");
break;
}
}
break;
}
case AP_MSG_PING: {
output->AddByte(AP_MSG_PING_OK);
break;
}
default: {
output->AddByte(AP_MSG_ERROR);
output->AddString("not known command byte");
addLogLine(this, LOGTYPE_WARNING, 1, "not known command byte");
break;
}
}
if (output->getMessageLength() > 0) {
outputPool->send(output);
}
}