Exemple #1
0
bool AwayEditorWindow::QuitRequested()
{
	if( !CheckMessage() )
		return false;

	BMessage* clsMessage = new BMessage(BEAIM_SINGLE_WINDOW_CLOSED);
	clsMessage->AddInt32( "wtype", SW_AWAY_EDITOR );
	PostAppMessage( clsMessage );
	
	return(true);
}
Exemple #2
0
int CReactorUDPClient::handle_input(ACE_HANDLE fd)
{
	if(fd == ACE_INVALID_HANDLE)
	{
		OUR_DEBUG((LM_ERROR, "[CReactorUDPClient::handle_input]fd is ACE_INVALID_HANDLE.\n"));
		return -1;
	}
	
	char szBuff[MAX_UDP_PACKET_LEN] = {'\0'};

	int nDataLen = m_skRemote.recv(szBuff, MAX_UDP_PACKET_LEN, m_addrRemote);
	if(nDataLen > 0)
	{
		CheckMessage(szBuff, (uint32)nDataLen);
	}

	return 0;
}
Exemple #3
0
void AwayEditorWindow::MessageReceived(BMessage* message)
{
	switch(message->what)
	{
	
		case AWAY_NEW:
			NewMessage();
			break;
			
		case AWAY_SAVE:
			SaveMessage();
			break;
			
		case AWAY_DELETE:
			DeleteMessage();
			break;
			
		case AWAY_CHANGED:
			isDirty = true;
			break;

		case BEAIM_RELOAD_PREF_SETTINGS:
			enterIsNewline = prefs->ReadBool( "EnterInsertsNewline", false );
			tabIsTab = prefs->ReadBool( "TabIsTab", false );
			break;

		case AWAY_SELECTED: {
			AwayItem* item = (AwayItem*)genView->listview->ItemAt( genView->listview->CurrentSelection() );
			if( !item || !CheckMessage() ) {
				EnableMessageStuff(false);
				return;
			}
			LoadMessage( item->GetName() );
			break;
		}
		
		case BEAIM_REFRESH_LANG_STRINGS:
			RefreshLangStrings();
			break;

		default:
			BWindow::MessageReceived(message);
	}
}
Exemple #4
0
int CReactorUDPHander::handle_input(ACE_HANDLE fd)
{
	if(fd == ACE_INVALID_HANDLE)
	{
		OUR_DEBUG((LM_ERROR, "[CReactorUDPHander::handle_input]fd is ACE_INVALID_HANDLE.\n"));
		return -1;
	}	
	
	char szBuff[MAX_UDP_PACKET_LEN] = {'\0'};

	int nDataLen = m_skRemote.recv(szBuff, MAX_UDP_PACKET_LEN, m_addrRemote);
	if(nDataLen > 0)
	{
		CheckMessage(szBuff, (uint32)nDataLen);

		m_pPacketParse = App_PacketParsePool::instance()->Create();
	}

	return 0;
}
Exemple #5
0
void AwayEditorWindow::NewMessage() {

	if( !CheckMessage() )
		return;
	
	currentMsg = BString(Language.get("AME_NEW_MESSAGE"));
	prefs->SetAwayMessage( currentMsg, "", "" );
	
	EnableMessageStuff( true );
	genView->messageName->SetText("");
	genView->textview->SetText("");
	genView->messageName->MakeFocus(true);
	genView->listview->AddItem( new AwayItem(currentMsg) );
	genView->listview->SetSelectionMessage( NULL );
	genView->listview->Select( prefs->FindAwayMessage(currentMsg) );
	genView->listview->SetSelectionMessage( new BMessage(AWAY_SELECTED) );
	genView->textview->MakeDirty(false);
	isDirty = false;
	hasSelection = true;
}
void CProactorUDPHandler::handle_read_dgram(const ACE_Asynch_Read_Dgram::Result& result)
{
	//因为UDP是一次性发送完整的数据包,所以不必做粘包处理
	ACE_Message_Block* pMBBuff = NULL;

	ACE_Message_Block* pMb = result.message_block();
	int nPacketLen = (int)result.bytes_transferred();
	int nTran = (int)result.bytes_transferred();

	result.remote_address(m_addrRemote);

	if(nPacketLen != 0 && nTran != 0)
	{
		//处理数据
		CheckMessage(pMb, (uint32)nTran);

		pMb->release();
		m_pPacketParse = App_PacketParsePool::instance()->Create();

		pMBBuff = App_MessageBlockManager::instance()->Create(MAX_UDP_PACKET_LEN);
	}
	else
	{
		OUR_DEBUG((LM_INFO, "[CProactorUDPHandler::handle_read_dgram]error=%d.\n", errno));
		//由于连接找不到远程对象,内存块不用释放,直接滚入下次IO
		pMBBuff = pMb;
	}

	if(NULL == pMBBuff)
	{
		OUR_DEBUG((LM_INFO, "[CProactorUDPHandler::handle_read_dgram]pMBBuff is NULL.\n"));
		return;
	}
	else
	{
		size_t stRecvLen = MAX_UDP_PACKET_LEN;
		//OUR_DEBUG((LM_INFO, "[CProactorUDPHandler::handle_read_dgram]pMBBuff=0x%08x.\n", pMBBuff));
		m_Read.recv(pMBBuff, stRecvLen, 0, PF_INET, m_szAct);  
	}
}
Exemple #7
0
    HRESULT DebuggerProxy::PollLoop()
    {
        HRESULT hr = S_OK;

        hr = mExec.Init( mCallback, this );
        if ( FAILED( hr ) )
            return hr;

        SetReadyThread();

        while ( !mShutdown )
        {
            hr = mExec.WaitForEvent( EventTimeoutMillis );
            if ( FAILED( hr ) )
            {
                if ( hr == E_HANDLE )
                {
                    // no debuggee has started yet
                    Sleep( EventTimeoutMillis );
                }
                else if ( hr != E_TIMEOUT )
                    break;
            }
            else
            {
                hr = mExec.DispatchEvent();
                if ( FAILED( hr ) )
                    break;
            }

            hr = CheckMessage();
            if ( FAILED( hr ) )
                break;
        }

        mExec.Shutdown();

        Log::LogMessage( "Poll loop shutting down.\n" );
        return hr;
    }
void CProactorUDPClient::handle_read_dgram(const ACE_Asynch_Read_Dgram::Result& result)
{
	//因为UDP是一次性发送完整的数据包,所以不必做粘包处理
	ACE_Message_Block* pMBBuff = NULL;

	ACE_Message_Block* pMb = result.message_block();
	int nPacketLen = (int)result.bytes_transferred();
	int nTran = (int)result.bytes_transferred();

	ACE_INET_Addr ServerAddr;  
	result.remote_address(ServerAddr);
	m_addrRemote.set(ServerAddr);

	if(nPacketLen != 0 && nTran != 0)
	{
		//处理数据
		CheckMessage(pMb, (uint32)nTran);
		pMb->release();

		pMBBuff = App_MessageBlockManager::instance()->Create(MAX_UDP_PACKET_LEN);
	}
	else
	{
		pMBBuff = pMb;
	}

	char* pAct = NULL;
	
	if(NULL == pMBBuff)
	{
		OUR_DEBUG((LM_INFO, "[CProactorUDPClient::handle_read_dgram]pMBBuff is NULL.\n"));
		return;
	}
	else
	{
		size_t stRecvLen = MAX_UDP_PACKET_LEN;
		m_Read.recv(pMBBuff, stRecvLen, 0, PF_INET, pAct);  
	}
}
 void OnChat(Player* player, uint32 /*type*/, uint32 lang, std::string& msg, Group* group)
 {
         CheckMessage(player, msg, lang, NULL, group, NULL, NULL);
 }
 void OnChat(Player* player, uint32 /*type*/, uint32 lang, std::string& msg, Player* receiver)
 {
         CheckMessage(player, msg, lang, receiver, NULL, NULL, NULL);
 }
Exemple #11
0
int Ctcs::SocketReady(fd_set *rfdp, fd_set *wfdp, int *nfds,
  fd_set *rfdnextp, fd_set *wfdnextp)
{
  if( DT_TRACKER_FREE == m_status ) return 0;

  if( DT_TRACKER_CONNECTING == m_status && FD_ISSET(m_sock, wfdp) ){
    int error = 0;
    socklen_t n = sizeof(error);
    (*nfds)--;
    FD_CLR(m_sock, wfdnextp);
    if( FD_ISSET(m_sock, rfdp) ){
      (*nfds)--;
      FD_CLR(m_sock, rfdnextp);
    }
    if( getsockopt(m_sock, SOL_SOCKET, SO_ERROR, &error, &n) < 0 )
      error = errno;
    if( error != 0 ){
      if( ECONNREFUSED != error )
        CONSOLE.Warning(2, "warn, connect to CTCS failed:  %s",
          strerror(error));
      Reset(15);
      return -1;
    }else{
      m_status = DT_TRACKER_READY;
      if(*cfg_verbose) CONSOLE.Debug("Connected to CTCS");
      if( Send_Protocol() != 0 && errno != EINPROGRESS ){
        CONSOLE.Warning(2, "warn, send protocol to CTCS failed:  %s",
          strerror(errno));
        return -1;
      }
      if( Send_Auth() != 0 && errno != EINPROGRESS ){
        CONSOLE.Warning(2, "warn, send password to CTCS failed:  %s",
          strerror(errno));
        return -1;
      }
      if( Send_Torrent(BTCONTENT.GetPeerId(),
            BTCONTENT.GetMetainfoFile()) < 0 && errno != EINPROGRESS ){
        CONSOLE.Warning(2, "warn, send torrent to CTCS failed:  %s",
          strerror(errno));
        return -1;
      }
    }
  }else if( DT_TRACKER_CONNECTING == m_status && FD_ISSET(m_sock, rfdp) ){
    int error = 0;
    socklen_t n = sizeof(error);
    (*nfds)--;
    FD_CLR(m_sock, rfdnextp);
    if( getsockopt(m_sock, SOL_SOCKET, SO_ERROR, &error, &n) < 0 )
      error = errno;
    CONSOLE.Warning(2, "warn, connect to CTCS failed:  %s", strerror(error));
    Reset(15);
    return -1;
  }else if( INVALID_SOCKET != m_sock ){
    if( FD_ISSET(m_sock, rfdp) ){
      (*nfds)--;
      FD_CLR(m_sock, rfdnextp);
      SOCKET tmp_sock = m_sock;
      int r = CheckMessage();
      if( INVALID_SOCKET == m_sock ){
        if( FD_ISSET(tmp_sock, wfdp) ){
          (*nfds)--;
          FD_CLR(tmp_sock, wfdnextp);
        }
        return r;
      }
    }
    if( FD_ISSET(m_sock, wfdp) ){
      (*nfds)--;
      FD_CLR(m_sock, wfdnextp);
      if( out_buffer.Count() && out_buffer.FlushOut(m_sock) < 0 ){
        Reset(5);
        return -1;
      }
    }
  }else{  // failsafe
    Reset(5);
    return -1;
  }
  return 0;
}
//接受数据
int CConsoleHandler::handle_input(ACE_HANDLE fd)
{
	m_ThreadLock.acquire();
	m_nIOCount++;
	m_ThreadLock.release();
	//OUR_DEBUG((LM_ERROR, "[CConsoleHandler::handle_input]ConnectID=%d,m_nIOCount=%d.\n", GetConnectID(), m_nIOCount));

	ACE_Time_Value nowait(MAX_MSG_PACKETTIMEOUT);

	m_atvInput = ACE_OS::gettimeofday();

	if(fd == ACE_INVALID_HANDLE)
	{
		m_u4CurrSize = 0;
		OUR_DEBUG((LM_ERROR, "[CConsoleHandler::handle_input]fd == ACE_INVALID_HANDLE.\n"));
		sprintf_safe(m_szError, MAX_BUFF_500, "[CConsoleHandler::handle_input]fd == ACE_INVALID_HANDLE.");

		return -1;
	}

	//判断数据包结构是否为NULL
	if(m_pPacketParse == NULL)
	{
		m_u4CurrSize = 0;
		OUR_DEBUG((LM_ERROR, "[CConsoleHandler::handle_input]m_pPacketParse == NULL.\n"));
		sprintf_safe(m_szError, MAX_BUFF_500, "[CConsoleHandler::handle_input]m_pPacketParse == NULL.");

		return -1;
	}

	//判断缓冲是否为NULL
	if(m_pCurrMessage == NULL)
	{
		m_u4CurrSize = 0;
		OUR_DEBUG((LM_ERROR, "[CConsoleHandler::handle_input]m_pCurrMessage == NULL.\n"));
		sprintf_safe(m_szError, MAX_BUFF_500, "[CConsoleHandler::handle_input]m_pCurrMessage == NULL.");

		if(m_pPacketParse->GetMessageHead() != NULL)
		{
			m_pPacketParse->GetMessageHead()->release();
		}

		if(m_pPacketParse->GetMessageBody() != NULL)
		{
			m_pPacketParse->GetMessageBody()->release();
		}

		if(m_pCurrMessage != NULL && m_pPacketParse->GetMessageBody() != m_pCurrMessage && m_pPacketParse->GetMessageBody() != m_pCurrMessage)
		{
			m_pCurrMessage->release();
			m_pCurrMessage = NULL;
		}
		App_PacketParsePool::instance()->Delete(m_pPacketParse);

		return -1;
	}

	int nCurrCount = (uint32)m_pCurrMessage->size() - m_u4CurrSize;
	//这里需要对m_u4CurrSize进行检查。
	if(nCurrCount < 0)
	{
		OUR_DEBUG((LM_ERROR, "[CConsoleHandler::handle_input][%d] nCurrCount < 0 m_u4CurrSize = %d.\n", GetConnectID(), m_u4CurrSize));
		m_u4CurrSize = 0;

		if(m_pPacketParse->GetMessageHead() != NULL)
		{
			m_pPacketParse->GetMessageHead()->release();
		}

		if(m_pPacketParse->GetMessageBody() != NULL)
		{
			m_pPacketParse->GetMessageBody()->release();
		}

		if(m_pCurrMessage != NULL && m_pPacketParse->GetMessageBody() != m_pCurrMessage && m_pPacketParse->GetMessageBody() != m_pCurrMessage)
		{
			m_pCurrMessage->release();
			m_pCurrMessage = NULL;
		}
		App_PacketParsePool::instance()->Delete(m_pPacketParse);

		return -1;
	}

	int nDataLen = this->peer().recv(m_pCurrMessage->wr_ptr(), nCurrCount, MSG_NOSIGNAL, &nowait);
	if(nDataLen <= 0)
	{
		m_u4CurrSize = 0;
		uint32 u4Error = (uint32)errno;
		OUR_DEBUG((LM_ERROR, "[CConsoleHandler::handle_input] ConnectID = %d, recv data is error nDataLen = [%d] errno = [%d].\n", GetConnectID(), nDataLen, u4Error));
		sprintf_safe(m_szError, MAX_BUFF_500, "[CConsoleHandler::handle_input] ConnectID = %d, recv data is error[%d].\n", GetConnectID(), nDataLen);

		if(m_pPacketParse->GetMessageHead() != NULL)
		{
			m_pPacketParse->GetMessageHead()->release();
		}

		if(m_pPacketParse->GetMessageBody() != NULL)
		{
			m_pPacketParse->GetMessageBody()->release();
		}

		if(m_pCurrMessage != NULL && m_pPacketParse->GetMessageBody() != m_pCurrMessage && m_pPacketParse->GetMessageBody() != m_pCurrMessage)
		{
			m_pCurrMessage->release();
			m_pCurrMessage = NULL;
		}
		App_PacketParsePool::instance()->Delete(m_pPacketParse);

		return -1;
	}

	m_u4CurrSize += nDataLen;

	m_pCurrMessage->wr_ptr(nDataLen);

	//如果没有读完,短读
	if(m_pCurrMessage->size() > m_u4CurrSize)
	{
		Close();
		return 0;
	}
	else if(m_pCurrMessage->length() == m_pPacketParse->GetPacketHeadLen() && m_pPacketParse->GetIsHead() == false)
	{
		m_pPacketParse->SetPacketHead(m_pCurrMessage->rd_ptr(), (uint32)m_pCurrMessage->length());
		uint32 u4PacketBodyLen = m_pPacketParse->GetPacketDataLen();
		m_u4CurrSize = 0;

		//如果超过了最大包长度,为非法数据
		if(u4PacketBodyLen >= MAX_MSG_PACKETLENGTH || u4PacketBodyLen <= 0)
		{
			m_u4CurrSize = 0;
			OUR_DEBUG((LM_ERROR, "[CConsoleHandler::handle_read_stream]u4PacketHeadLen(%d) more than MAX_MSG_PACKETLENGTH.", u4PacketBodyLen));
			if(m_pPacketParse->GetMessageHead() != NULL)
			{
				m_pPacketParse->GetMessageHead()->release();
			}

			if(m_pPacketParse->GetMessageBody() != NULL)
			{
				m_pPacketParse->GetMessageBody()->release();
			}

			if(m_pCurrMessage != NULL && m_pPacketParse->GetMessageBody() != m_pCurrMessage && m_pPacketParse->GetMessageBody() != m_pCurrMessage)
			{
				m_pCurrMessage->release();
				m_pCurrMessage = NULL;
			}
			App_PacketParsePool::instance()->Delete(m_pPacketParse);

			return -1;
		}
		else
		{
			m_pPacketParse->SetMessageHead(m_pCurrMessage);

			//申请头的大小对应的mb
			m_pCurrMessage = App_MessageBlockManager::instance()->Create(m_pPacketParse->GetPacketDataLen());
			if(m_pCurrMessage == NULL)
			{
				m_u4CurrSize = 0;
				AppLogManager::instance()->WriteLog(LOG_SYSTEM_CONNECT, "Close Connection from [%s:%d] RecvSize = %d, RecvCount = %d, SendSize = %d, SendCount = %d.",m_addrRemote.get_host_addr(), m_addrRemote.get_port_number(), m_u4AllRecvSize, m_u4AllRecvCount, m_u4AllSendSize, m_u4AllSendCount);
				OUR_DEBUG((LM_ERROR, "[CConnectHandle::RecvClinetPacket] pmb new is NULL.\n"));

				if(m_pPacketParse->GetMessageHead() != NULL)
				{
					m_pPacketParse->GetMessageHead()->release();
				}

				if(m_pPacketParse->GetMessageBody() != NULL)
				{
					m_pPacketParse->GetMessageBody()->release();
				}

				if(m_pCurrMessage != NULL && m_pPacketParse->GetMessageBody() != m_pCurrMessage && m_pPacketParse->GetMessageBody() != m_pCurrMessage)
				{
					m_pCurrMessage->release();
					m_pCurrMessage = NULL;
				}
				App_PacketParsePool::instance()->Delete(m_pPacketParse);

				return -1;
			}
			Close();
		}
	}
	else
	{
		//接受完整数据完成,开始分析完整数据包
		m_pPacketParse->SetPacketData(m_pCurrMessage->rd_ptr(), (uint32)m_pCurrMessage->length());
		m_pPacketParse->SetMessageBody(m_pCurrMessage);

		CheckMessage();

		m_u4CurrSize = 0;

		//申请新的包
		m_pPacketParse = App_PacketParsePool::instance()->Create();
		if(NULL == m_pPacketParse)
		{
			OUR_DEBUG((LM_DEBUG,"[%t|CConnectHandle::open] Open(%d) m_pPacketParse new error.\n", GetConnectID()));
			return -1;
		}

		//申请头的大小对应的mb
		m_pCurrMessage = App_MessageBlockManager::instance()->Create(m_pPacketParse->GetPacketHeadLen());
		if(m_pCurrMessage == NULL)
		{
			AppLogManager::instance()->WriteLog(LOG_SYSTEM_CONNECT, "Close Connection from [%s:%d] RecvSize = %d, RecvCount = %d, SendSize = %d, SendCount = %d.",m_addrRemote.get_host_addr(), m_addrRemote.get_port_number(), m_u4AllRecvSize, m_u4AllRecvCount, m_u4AllSendSize, m_u4AllSendCount);
			OUR_DEBUG((LM_ERROR, "[CConnectHandle::RecvClinetPacket] pmb new is NULL.\n"));

			return -1;
		}

		Close();
	}

	return 0;
}
Exemple #13
0
	void OnChat(Player* player, uint32 /*type*/, uint32 lang, std::string& msg, Channel* channel)
	{
		CheckMessage(LEXICS_CUTTER_CHANNEL, player, msg, lang, NULL, NULL, NULL, channel);
	}
Exemple #14
0
 void OnChat(Player* player, uint32 /*type*/, uint32 lang, std::string& msg) override
 {
     CheckMessage(player, msg, lang, NULL, NULL, NULL, NULL);
 }
Exemple #15
0
	void OnChat(Player* player, uint32 /*type*/, uint32 lang, std::string& msg, Player* receiver)
	{
		CheckMessage(LEXICS_CUTTER_WHISPER, player, msg, lang, receiver, NULL, NULL, NULL);
	}
 void OnChat(Player* player, uint32 /*type*/, uint32 lang, std::string& msg, Guild* guild)
 {
         CheckMessage(player, msg, lang, NULL, NULL, guild, NULL);
 }
//*****************************************************************************
// Read Actisense formatted NMEA2000 message from stream
// Actisense Format:
// <10><02><93><length (1)><priority (1)><PGN (3)><destination (1)><source (1)><time (4)><len (1)><data (len)><CRC (1)><10><03>
// or
// <10><02><94><length (1)><priority (1)><PGN (3)><destination (1)><len (1)><data (len)><CRC (1)><10><03>
bool tActisenseReader::GetMessageFromStream(tN2kMsg &N2kMsg) {
  bool result=false;

  if (ReadStream==0)
    return false;

  int NewByte;
  while ((NewByte = ReadStream->read()) != -1 && !result) {
//        Serial.println((char)NewByte,HEX);
      if (MsgIsComing) {
        if (EscapeReceived) {
          switch (NewByte) {
            case Escape: // Escaped Escape
              EscapeReceived=false;
              if (!AddByteToBuffer(NewByte)) ClearBuffer();
              break;
            case EndOfText: // Message ready
              switch (MsgBuf[0]) {
                case MsgTypeN2kData:
                case MsgTypeN2kRequest:
                  result=CheckMessage(N2kMsg);
                  break;
                default:
                  result=false;
              }
              ClearBuffer();
              break;
            case StartOfText: // Start new message
              ClearBuffer();
              StartOfTextReceived=true;
              break;
            default: // Error
              ClearBuffer();
          }
        } else {
          if (NewByte==Escape) {
            EscapeReceived=true;
          } else {
            if (!AddByteToBuffer(NewByte)) ClearBuffer();
          }
        }
      } else {
        switch (NewByte) {
          case StartOfText:
            StartOfTextReceived=false;
            if (EscapeReceived) {
              ClearBuffer();
              StartOfTextReceived=true;
            }
            break;
          default:
            if (StartOfTextReceived) {
              StartOfTextReceived=false;
              MsgIsComing=true;
              AddByteToBuffer(NewByte);
            }
        }
        EscapeReceived=(NewByte==Escape);
      }
  }

  return result;
}
void CProConsoleHandle::handle_read_stream(const ACE_Asynch_Read_Stream::Result &result)
{
	ACE_Message_Block& mb = result.message_block();
	uint32 u4PacketLen = (uint32)result.bytes_transferred();
	int nTran = (int)result.bytes_transferred();

	if(!result.success() || result.bytes_transferred() == 0)
	{
		//链接断开
		if(m_pPacketParse->GetMessageHead() != NULL)
		{
			App_MessageBlockManager::instance()->Close(m_pPacketParse->GetMessageHead());
		}

		if(m_pPacketParse->GetMessageBody() != NULL)
		{
			App_MessageBlockManager::instance()->Close(m_pPacketParse->GetMessageBody());
		}

		if(&mb != m_pPacketParse->GetMessageHead() && &mb != m_pPacketParse->GetMessageBody())
		{
			//OUR_DEBUG((LM_DEBUG,"[CProConsoleHandle::handle_read_stream] Message_block release.\n"));
			App_MessageBlockManager::instance()->Close(&mb);
		}
		SAFE_DELETE(m_pPacketParse);

		OUR_DEBUG((LM_DEBUG,"[%tCConnectHandler::handle_read_stream]Connectid=[%d] error(%d)...\n", GetConnectID(), errno));
		//AppLogManager::instance()->WriteLog(LOG_SYSTEM_CONNECT, "Close Connection from [%s:%d] RecvSize = %d, RecvCount = %d, SendSize = %d, SendCount = %d.",m_addrRemote.get_host_addr(), m_addrRemote.get_port_number(), m_u4AllRecvSize, m_u4AllRecvCount, m_u4AllSendSize, m_u4AllSendCount);
		//因为是要关闭连接,所以要多关闭一次IO,对应Open设置的1的初始值

		Close(2);

		return;
	}

	m_atvInput = ACE_OS::gettimeofday();

	if(result.bytes_transferred() < result.bytes_to_read())
	{
		//短读,继续读
		int nRead = (int)result.bytes_to_read() - (int)result.bytes_transferred();
		if(-1 == m_Reader.read(mb, nRead))
		{
			if(m_pPacketParse->GetMessageHead() != NULL)
			{
				App_MessageBlockManager::instance()->Close(m_pPacketParse->GetMessageHead());
			}

			if(m_pPacketParse->GetMessageBody() != NULL)
			{
				App_MessageBlockManager::instance()->Close(m_pPacketParse->GetMessageBody());
			}

			if(&mb != m_pPacketParse->GetMessageHead() && &mb != m_pPacketParse->GetMessageBody())
			{
				App_MessageBlockManager::instance()->Close(&mb);
			}
			SAFE_DELETE(m_pPacketParse);

			OUR_DEBUG((LM_ERROR, "[CConnectHandler::handle_read_stream]Read Shoter error(%d).", errno));
			//AppLogManager::instance()->WriteLog(LOG_SYSTEM_CONNECT, "Close Connection from [%s:%d] RecvSize = %d, RecvCount = %d, SendSize = %d, SendCount = %d.",m_addrRemote.get_host_addr(), m_addrRemote.get_port_number(), m_u4AllRecvSize, m_u4AllRecvCount, m_u4AllSendSize, m_u4AllSendCount);
			//因为是要关闭连接,所以要多关闭一次IO,对应Open设置的1的初始值

			Close(2);
			return;
		}

	}
	else if(mb.length() == m_pPacketParse->GetPacketHeadLen() && m_pPacketParse->GetIsHead() == false)
	{
		//判断头的合法性
		m_pPacketParse->SetPacketHead(GetConnectID(), &mb, App_MessageBlockManager::instance());
		uint32 u4PacketBodyLen = m_pPacketParse->GetPacketBodyLen();

		//如果超过了最大包长度,为非法数据
		if(u4PacketBodyLen >= MAX_MSG_PACKETLENGTH || u4PacketBodyLen <= 0)
		{
			OUR_DEBUG((LM_ERROR, "[CConnectHandler::handle_read_stream]u4PacketHeadLen(%d) more than MAX_MSG_PACKETLENGTH.", u4PacketBodyLen));

			if(m_pPacketParse->GetMessageHead() != NULL)
			{
				App_MessageBlockManager::instance()->Close(m_pPacketParse->GetMessageHead());
			}

			if(m_pPacketParse->GetMessageBody() != NULL)
			{
				App_MessageBlockManager::instance()->Close(m_pPacketParse->GetMessageBody());
			}

			if(&mb != m_pPacketParse->GetMessageHead() && &mb != m_pPacketParse->GetMessageBody())
			{
				App_MessageBlockManager::instance()->Close(&mb);
			}
			SAFE_DELETE(m_pPacketParse);

			Close(2);
			return;
		}
		else
		{
			Close();
			RecvClinetPacket(u4PacketBodyLen);
		}
	}
	else
	{
		//接受完整数据完成,开始分析完整数据包
		m_pPacketParse->SetPacketBody(GetConnectID(), &mb, App_MessageBlockManager::instance());

		CheckMessage();

		m_pPacketParse = new CConsolePacketParse();

		Close();

		//接受下一个数据包
		RecvClinetPacket(m_pPacketParse->GetPacketHeadLen());
	}

	return;
}
 void OnChat(Player* player, uint32 /*type*/, uint32 lang, std::string& msg, Channel* channel)
 {
         CheckMessage(player, msg, lang, NULL, NULL, NULL, channel);
 }
Exemple #20
0
	void OnChat(Player* player, uint32 /*type*/, uint32 lang, std::string& msg)
	{
		CheckMessage(LEXICS_CUTTER_CHAT, player, msg, lang, NULL, NULL, NULL, NULL);
	}