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); } }
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 UDPGenerator::handle_read_dgram (const ACE_Asynch_Read_Dgram::Result &result) { ACE_DEBUG ((LM_DEBUG, "handle_read_dgram called\n")); ACE_DEBUG ((LM_DEBUG, "********************\n"));/*{{{*/ ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "bytes_to_read", result.bytes_to_read ())); ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "handle", result.handle ())); ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "bytes_transfered", result.bytes_transferred ())); ACE_INET_Addr peerAddr; result.remote_address (peerAddr); ACE_DEBUG ((LM_DEBUG, "%s = %s:%d\n", "peer_address", peerAddr.get_host_addr (), peerAddr.get_port_number ())); ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "flags", result.flags ())); ACE_DEBUG ((LM_DEBUG, "%s = %s\n", "act", result.act ())); ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "success", result.success ())); ACE_DEBUG ((LM_DEBUG, "%s = %s\n", "completion_key", result.completion_key ())); ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "error", result.error ())); ACE_DEBUG ((LM_DEBUG, "********************\n"));/*}}}*/ if (result.success () && result.bytes_transferred () != 0) { const ACE_Message_Block * msg = result.message_block(); ACE_InputCDR cdr (msg->cont()); ACE_CDR::Boolean byte_order; cdr >> ACE_InputCDR::to_boolean (byte_order); cdr.reset_byte_order(byte_order); ACE_CDR::ULong length; cdr >> length; ACE_InputCDR cdrpayload(msg->cont()); cdrpayload.reset_byte_order(byte_order); DataGloveData glovedata; cdrpayload >> glovedata; // loop through our message block and print out the contents/*{{{*/ //for (const ACE_Message_Block* msg = result.message_block(); msg != 0; msg = msg->cont ()) // { // use msg->length() to get the number of bytes written to the message // block. //if (msg->length() == 8) //{ // ACE_InputCDR cdr (msg); // ACE_CDR::Boolean byte_order; // cdr >> ACE_InputCDR::to_boolean (byte_order); // cdr.reset_byte_order(byte_order); // ACE_CDR::ULong length; // cdr >> length; // ACE_InputCDR cdrpayload(msg->cont()); // cdrpayload.reset_byte_order(byte_order); // DataGloveData glovedata; // cdrpayload >> glovedata; // continue; //} //else //{ // ACE_DEBUG ((LM_DEBUG, "Buf=[size=<%d>", msg->length ())); // for (u_long i = 0; i < msg->length(); ++i) // ACE_DEBUG ((LM_DEBUG, "%c", (msg->rd_ptr())[i])); // ACE_DEBUG ((LM_DEBUG, "]\n")); //}/*}}}*/ //} } ACE_DEBUG ((LM_DEBUG, "Receive completed\n")); // No need for this message block anymore. result.message_block ()->release (); readdatagram(4); // Note that we are done with the test. done++; }
void Receiver::handle_read_dgram (const ACE_Asynch_Read_Dgram::Result &result) { ACE_DEBUG ((LM_DEBUG, "handle_read_dgram called\n")); ACE_DEBUG ((LM_DEBUG, "********************\n")); ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "bytes_to_read", result.bytes_to_read ())); ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "handle", result.handle ())); ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "bytes_transfered", result.bytes_transferred ())); ACE_INET_Addr peerAddr; result.remote_address (peerAddr); ACE_DEBUG ((LM_DEBUG, "%s = %s:%d\n", "peer_address", peerAddr.get_host_addr (), peerAddr.get_port_number ())); ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "flags", result.flags ())); ACE_DEBUG ((LM_DEBUG, "%s = %s\n", "act", result.act ())); ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "success", result.success ())); ACE_DEBUG ((LM_DEBUG, "%s = %s\n", "completion_key", result.completion_key ())); ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "error", result.error ())); ACE_DEBUG ((LM_DEBUG, "********************\n")); if (result.success () && result.bytes_transferred () != 0) { // loop through our message block and print out the contents for (const ACE_Message_Block* msg = result.message_block (); msg != 0; msg = msg->cont ()) { // use msg->length () to get the number of bytes written to the message // block. ACE_DEBUG ((LM_DEBUG, "Buf=[size=<%d>", msg->length ())); for (u_long i = 0; i < msg->length (); ++i) ACE_DEBUG ((LM_DEBUG, "%c", (msg->rd_ptr ())[i])); ACE_DEBUG ((LM_DEBUG, "]\n")); } } ACE_DEBUG ((LM_DEBUG, "Receiver completed\n")); // No need for this message block anymore. result.message_block ()->release (); // Note that we are done with the test. done++; }