Ejemplo n.º 1
0
bool CMessageService::SaveThreadInfoData()
{
    //这里进行线程自检
    ACE_Time_Value tvNow(ACE_OS::gettimeofday());
    ACE_Date_Time dt(m_ThreadInfo.m_tvUpdateTime);

    //开始查看线程是否超时
    //OUR_DEBUG((LM_INFO, "[CMessageService::SaveThreadInfoData]ID=%d,m_u4State=%d,m_u2ThreadTimeOut=%d,cost=%d.\n", m_ThreadInfo.m_u4ThreadID, m_ThreadInfo.m_u4State, m_u2ThreadTimeOut, tvNow.sec() - m_ThreadInfo.m_tvUpdateTime.sec()));
    if(m_ThreadInfo.m_u4State == THREAD_RUNBEGIN && tvNow.sec() - m_ThreadInfo.m_tvUpdateTime.sec() > m_u2ThreadTimeOut)
    {
        AppLogManager::instance()->WriteLog(LOG_SYSTEM_WORKTHREAD, "[CMessageService::handle_timeout] pThreadInfo = [%d] State = [%d] Time = [%04d-%02d-%02d %02d:%02d:%02d] PacketCount = [%d] LastCommand = [0x%x] PacketTime = [%d] TimeOut > %d[%d] CurrPacketCount = [%d] QueueCount = [%d] BuffPacketUsed = [%d] BuffPacketFree = [%d].",
                                            m_ThreadInfo.m_u4ThreadID,
                                            m_ThreadInfo.m_u4State,
                                            dt.year(), dt.month(), dt.day(), dt.hour(), dt.minute(), dt.second(),
                                            m_ThreadInfo.m_u4RecvPacketCount,
                                            m_ThreadInfo.m_u2CommandID,
                                            m_ThreadInfo.m_u2PacketTime,
                                            m_u2ThreadTimeOut,
                                            tvNow.sec() - m_ThreadInfo.m_tvUpdateTime.sec(),
                                            m_ThreadInfo.m_u4CurrPacketCount,
                                            (int)msg_queue()->message_count(),
                                            App_BuffPacketManager::instance()->GetBuffPacketUsedCount(),
                                            App_BuffPacketManager::instance()->GetBuffPacketFreeCount());

        //发现阻塞线程,需要重启相应的线程
        AppLogManager::instance()->WriteLog(LOG_SYSTEM_WORKTHREAD, "[CMessageService::handle_timeout] ThreadID = [%d] Thread is reset.", m_u4ThreadID);
        return false;
    }
    else
    {
        AppLogManager::instance()->WriteLog(LOG_SYSTEM_WORKTHREAD, "[CMessageService::handle_timeout] pThreadInfo = [%d] State = [%d] Time = [%04d-%02d-%02d %02d:%02d:%02d] PacketCount = [%d] LastCommand = [0x%x] PacketTime = [%d] CurrPacketCount = [%d] QueueCount = [%d] BuffPacketUsed = [%d] BuffPacketFree = [%d].",
                                            m_ThreadInfo.m_u4ThreadID,
                                            m_ThreadInfo.m_u4State,
                                            dt.year(), dt.month(), dt.day(), dt.hour(), dt.minute(), dt.second(),
                                            m_ThreadInfo.m_u4RecvPacketCount,
                                            m_ThreadInfo.m_u2CommandID,
                                            m_ThreadInfo.m_u2PacketTime,
                                            m_ThreadInfo.m_u4CurrPacketCount,
                                            (int)msg_queue()->message_count(),
                                            App_BuffPacketManager::instance()->GetBuffPacketUsedCount(),
                                            App_BuffPacketManager::instance()->GetBuffPacketFreeCount());

        m_ThreadInfo.m_u4CurrPacketCount = 0;
        return true;
    }

    return true;
}
Ejemplo n.º 2
0
bool RealmSocket::send(const char *buf, size_t len)
{
    if (buf == NULL || len == 0)
        return true;

    ACE_Data_Block db(
            len,
            ACE_Message_Block::MB_DATA,
            (const char*)buf,
            0,
            0,
            ACE_Message_Block::DONT_DELETE,
            0);

    ACE_Message_Block message_block(
            &db,
            ACE_Message_Block::DONT_DELETE,
            0);

    message_block.wr_ptr(len);

    if (msg_queue()->is_empty())
    {
        // Try to send it directly.
        ssize_t n = noblk_send(message_block);

        if (n < 0)
            return false;
        else if (n == len)
            return true;

        // fall down
        message_block.rd_ptr((size_t)n);
    }

    ACE_Message_Block *mb = message_block.clone();

    if (msg_queue()->enqueue_tail(mb, (ACE_Time_Value *) &ACE_Time_Value::zero) == -1)
    {
        mb->release();
        return false;
    }

    if (reactor()->schedule_wakeup(this, ACE_Event_Handler::WRITE_MASK) == -1)
        return false;

    return true;
}
Ejemplo n.º 3
0
bool CMessageService::PutMessage(CMessage* pMessage)
{

    ACE_Message_Block* mb = pMessage->GetQueueMessage();

    if(NULL != mb)
    {
        //判断队列是否是已经最大
        int nQueueCount = (int)msg_queue()->message_count();

        if(nQueueCount >= (int)m_u4MaxQueue)
        {
            OUR_DEBUG((LM_ERROR,"[CMessageService::PutMessage] Queue is Full nQueueCount = [%d].\n", nQueueCount));
            return false;
        }

        ACE_Time_Value xtime = ACE_OS::gettimeofday() + ACE_Time_Value(0, m_u4WorkQueuePutTime);

        if(this->putq(mb, &xtime) == -1)
        {
            OUR_DEBUG((LM_ERROR,"[CMessageService::PutMessage] Queue putq  error nQueueCount = [%d] errno = [%d].\n", nQueueCount, errno));
            return false;
        }
    }
    else
    {
        OUR_DEBUG((LM_ERROR,"[CMessageService::PutMessage] mb new error.\n"));
        return false;
    }

    return true;
}
Ejemplo n.º 4
0
RealmSocket::~RealmSocket(void)
{
    if (msg_queue())
        msg_queue()->close();

    if (input_buffer_.length() != 0)
        input_buffer_.release();

    // delete RealmSocketObject must never be called from our code.
    closing_ = true;

    if (session_)
        delete session_;

    peer().close();
}
Ejemplo n.º 5
0
int modAOS_OCF_Insert::svc() {
	svcStart_();

	AOS_Transfer_Frame* frame = 0;

	while ( continueService() ) {
		ndSafeRelease(frame);

		std::pair<NetworkData*, int> queueTop = getData_();

		if ( msg_queue()->deactivated() ) break;

		if ( queueTop.second < 0 ) {
			MOD_ERROR("getData_() call failed.");
			continue;
		}
		else if ( ! queueTop.first ) {
			MOD_ERROR("getData_() returned with null data.");
			continue;
		}

		if ( (frame = dynamic_cast<AOS_Transfer_Frame*>(queueTop.first)) ) {
			MOD_DEBUG("Received %d byte AOS_Transfer_Frame to add a Secondary Header to.", frame->getUnitLength());

			// Test expected values.
			if (static_cast<int>(frame->getUnitLength()) != getFrameSize()) {
				MOD_WARNING("AOS Transfer Frame bad length: received %d octets, needed %d.",
					frame->getUnitLength(), getFrameSize());
				incBadLengthCount();
				if ( getDropBadFrames()) continue;
			}
			else incValidFrameCount();

			_receivedFrameUnitCount += 1;
			_receivedFrameOctetCount += frame->getUnitLength();

			_insertWaitingReport(frame);

			if ( links_[PrimaryOutputLink] ) {
				MOD_DEBUG("Sending %d octets.", frame->getUnitLength());

				links_[PrimaryOutputLink]->send(frame);
				frame = 0; // important
			}
			else {
				MOD_NOTICE("No output target defined yet, dropping data.");
			}
			frame = 0;
		}
		else {
			MOD_INFO("Received %d octets of unrecognized data! Dropping.", queueTop.first->getUnitLength());
			ndSafeRelease(queueTop.first);
			queueTop.first = 0;
			continue;
		}
	}

	return svcEnd_();

}
Ejemplo n.º 6
0
int
run_main (int, ACE_TCHAR *[])
{
  ACE_START_TEST (ACE_TEXT ("Priority_Buffer_Test"));

#if defined (ACE_HAS_THREADS)
  // Message queue.
  ACE_Message_Queue<ACE_MT_SYNCH> msg_queue (max_queue);

  if (ACE_Thread_Manager::instance ()->spawn
      (ACE_THR_FUNC (producer),
       (void *) &msg_queue,
       THR_NEW_LWP | THR_DETACHED) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%p\n"),
                       ACE_TEXT ("spawn")),
                      1);

  // Wait for producer and consumer threads to exit.
  ACE_Thread_Manager::instance ()->wait ();
#else
  ACE_ERROR ((LM_INFO,
              ACE_TEXT ("threads not supported on this platform\n")));
#endif /* ACE_HAS_THREADS */
  ACE_END_TEST;
  return 0;
}
Ejemplo n.º 7
0
/**
        \brief Called from ACEReactor when there are events in our queue()
*/
int AuthLink::handle_output( ACE_HANDLE /*= ACE_INVALID_HANDLE*/ )
{
    SEGSEvent *ev;
    ACE_Time_Value nowait (ACE_OS::gettimeofday ());
    while (-1 != getq(ev, &nowait))
    {
        if(ev->type()==SEGS_EventTypes::evFinish)
        {
            ACE_DEBUG ((LM_DEBUG,ACE_TEXT ("(%P|%t) Error sent, closing connection\n")));
            return -1;
        }
        if(ev->type()==evContinue) // we have asked ourselves to send leftovers
        {
            assert(m_unsent_bytes_storage.GetReadableDataSize() > 0); // be sure we have some
        }
        else
        {
            size_t start_offset=m_unsent_bytes_storage.GetReadableDataSize();
            encode_buffer(static_cast<AuthLinkEvent *>(ev),start_offset);
        }
        if(!send_buffer()) // trying to send the contents of the buffer
        {
            ev->release(); // we have failed somehow
            break;
        }
        ev->release();
    }
    if (msg_queue()->is_empty ()) // we don't want to be woken up
        reactor()->cancel_wakeup(this, ACE_Event_Handler::WRITE_MASK);
    else // unless there is something to send still
        reactor()->schedule_wakeup(this, ACE_Event_Handler::WRITE_MASK);
    return 0;
}
Ejemplo n.º 8
0
int modAOS_B_PDU_Add::svc() {
	svcStart_();

	if ( ! _bpduLength) {
		if ( getMTU() > 0 ) {
			_bpduLength = getMTU();
			_mtuIsManual = true;
		}
		else if (links_[PrimaryOutputLink] ) {
			MOD_INFO("B_PDU length is unset, asking output target %s for MRU.", links_[PrimaryOutputLink]->getTarget()->getName().c_str());
			_bpduLength = links_[PrimaryOutputLink]->getTarget()->getMRU();
			_mtuIsManual = false;
		}
	}

	if (_bpduLength > 0) {
		rebuildIdleUnitTemplate_();

		while ( continueService() ) {
			std::pair<NetworkData*, int> queueTop = getData_();

			// Check every 11th unit for a new MTU
			if ( ! _mtuIsManual && getReceivedUnitCount() % 11 == 0 && links_[PrimaryOutputLink] ) {
				_bpduLength = links_[PrimaryOutputLink]->getTarget()->getMRU();
			}

			if ( msg_queue()->deactivated() ) break;

			if ( queueTop.second < 0 ) {
				MOD_ERROR("getData_() call failed.");
				continue;
			}
			else if ( ! queueTop.first ) {
				MOD_ERROR("getData_() returned with null data.");
				continue;
			}

			MOD_DEBUG("Received %d bytes to convert into AOS B_PDUs.", queueTop.first->getUnitLength());

			AOS_Bitstream_PDU* bpdu_list = _process_data(queueTop.first);
			// Deletion of received data is performed in _process_data.

			if ( ! getSendImmediately() ) {
				while (bpdu_list) {
					AOS_Bitstream_PDU* cur = bpdu_list;
					_send(cur);

					bpdu_list = (AOS_Bitstream_PDU*) bpdu_list->getNextPart();
				}
			}
			MOD_DEBUG("Finished processing incoming packets.");
		}
	}
	else {
		MOD_ERROR("No MTU obtainable, exiting service loop (pausing).");
	}

	return svcEnd_();
}
Ejemplo n.º 9
0
int modTM_FSH_Extract::svc() {
	svcStart_();

	TM_Transfer_Frame* frame = 0;

	while ( continueService() ) {
		ndSafeRelease(frame);

		std::pair<NetworkData*, int> queueTop = getData_();

		if ( msg_queue()->deactivated() ) break;

		if ( queueTop.second < 0 ) {
			MOD_ERROR("getData_() call failed.");
			continue;
		}
		else if ( ! queueTop.first ) {
			MOD_ERROR("getData_() returned with null data.");
			continue;
		}

		frame = dynamic_cast<TM_Transfer_Frame*>(queueTop.first);

		if ( !frame ) {
			MOD_ERROR("Received %d-octet buffer in %s wrapper (not TM_Transfer_Frame)! Must discard.",
				queueTop.first->getUnitLength(), queueTop.first->typeStr().c_str());
			ndSafeRelease(queueTop.first);
			continue;
		}

		queueTop.first = 0;

		MOD_DEBUG("Received %d-octet frame.", frame->getUnitLength());
		frame->setSecondaryHeaderLen(getFSHSize());

		// Test expected values.
		if (frame->getUnitLength() != getFrameSizeU()) {
			MOD_WARNING("TM Transfer Frame bad length: received %d octets, needed %d.", frame->getUnitLength(), getFrameSize());
			incBadLengthCount();
			if ( getDropBadFrames() ) continue;
		}
		else { incValidFrameCount(); }

		_extractAndSendFSH(frame);

		if ( links_[PrimaryOutputLink] ) {
			MOD_DEBUG("Sending a %d-octet TM Transfer Frame.", frame->getUnitLength());
			links_[PrimaryOutputLink]->send(frame);
			frame = 0; // important
		}
		else {
			MOD_ERROR("No output target defined, dropping frame.");
		}

		MOD_DEBUG("Finished processing incoming frame.");
	}

	return svcEnd_();
}
Ejemplo n.º 10
0
int AC_Output_Handler::handle_input (ACE_HANDLE h) {
  peer ().close ();
  reactor ()->remove_handler
    (h, ACE_Event_Handler::READ_MASK
        | ACE_Event_Handler::DONT_CALL);
  msg_queue ()->pulse ();
  return 0;
}
Ejemplo n.º 11
0
int CLogManager::Close()
{
    if(m_blRun)
    {
        if (false == this->CloseMsgQueue())
        {
            OUR_DEBUG((LM_ERROR, "[CLogManager::Close] CloseMsgQueue is false.\n"));
        }
    }
    else
    {
        msg_queue()->deactivate();
        msg_queue()->flush();
    }

    return 0;
}
Ejemplo n.º 12
0
int PoolSocket::SendPacket (const WorldPacket& pct)
{
    ACE_GUARD_RETURN (LockType, Guard, m_OutBufferLock, -1);

    if (closing_)
        return -1;

    // Dump outgoing packet.
    if (sPacketLog->CanLogPacket())
        sPacketLog->LogPacket(pct, SERVER_TO_CLIENT);

    Flexi::ServerPktHeader header(pct.size()+2, pct.GetOpcode());
    m_Crypt.EncryptSend ((uint8*)header.header, header.getHeaderLength());

    if (m_OutBuffer->space() >= pct.size()+ header.getHeaderLength() && msg_queue()->is_empty())
    {
        // Put the packet on the buffer.
        if (m_OutBuffer->copy((char*) header.header, header.getHeaderLength()) == -1)
            ACE_ASSERT (false);

        if (!pct.empty())
            if (m_OutBuffer->copy((char*) pct.contents(), pct.size()) == -1)
                ACE_ASSERT (false);
    }
    else
    {
        // Enqueue the packet.
        ACE_Message_Block* mb;

        ACE_NEW_RETURN(mb, ACE_Message_Block(pct.size() + header.getHeaderLength()), -1);

        mb->copy((char*) header.header, header.getHeaderLength());

        if (!pct.empty())
            mb->copy((const char*)pct.contents(), pct.size());

        if (msg_queue()->enqueue_tail(mb,(ACE_Time_Value*)&ACE_Time_Value::zero) == -1)
        {
            sLog->outError("NodeSocket::SendPacket enqueue_tail failed");
            mb->release();
            return -1;
        }
    }

    return 0;
}
Ejemplo n.º 13
0
int modTM_MC_Mux::svc() {
	svcStart_();

	TM_Transfer_Frame* frame = 0;

	while ( continueService() ) {
		ndSafeRelease(frame);

		std::pair<NetworkData*, int> queueTop = getData_();

		if ( msg_queue()->deactivated() ) break;

		if ( queueTop.second < 0 ) {
			MOD_ERROR("getData_() call failed.");
			continue;
		}
		else if ( ! queueTop.first ) {
			MOD_ERROR("getData_() returned with null data.");
			continue;
		}

		frame = dynamic_cast<TM_Transfer_Frame*>(queueTop.first);

		if ( !frame ) {
			MOD_ERROR("Received %d-octet buffer in %s wrapper (not TM_Transfer_Frame)! Must discard.",
				queueTop.first->getUnitLength(), queueTop.first->typeStr().c_str());
			ndSafeRelease(queueTop.first);
			continue;
		}

		MOD_DEBUG("Received %d-octet frame to multiplex.", frame->getTotalUnitLength());

		// Test expected values.
		if (static_cast<int>(frame->getTotalUnitLength()) != getFrameSize()) {
			MOD_WARNING("TM Transfer Frame bad length: received %d octets, needed %d.", frame->getTotalUnitLength(), getFrameSize());
			incBadLengthCount();
			if ( getDropBadFrames() ) continue;
		}
		else {
			incValidFrameCount();
		}

		addErrorControlIfPossible(frame);

		if ( links_[PrimaryOutputLink] ) {
			MOD_DEBUG("Sending %d octets.", frame->getTotalUnitLength());

			links_[PrimaryOutputLink]->send(frame);
			frame = 0; // important
		}
		else {
			MOD_NOTICE("No output target defined yet, dropping data.");
		}
	}

	return svcEnd_();

}
Ejemplo n.º 14
0
void
TAO_Notify_ThreadPool_Task::init (const NotifyExt::ThreadPoolParams& tp_params,
                                  const TAO_Notify_AdminProperties::Ptr& admin_properties)
{
  ACE_ASSERT (this->timer_.get() == 0);

  TAO_Notify_Timer_Queue* timer = 0;
  ACE_NEW_THROW_EX (timer,
                    TAO_Notify_Timer_Queue (),
                    CORBA::NO_MEMORY ());
  this->timer_.reset (timer);

  TAO_Notify_Buffering_Strategy* buffering_strategy = 0;
  ACE_NEW_THROW_EX (buffering_strategy,
                    TAO_Notify_Buffering_Strategy (*msg_queue (), admin_properties),
                    CORBA::NO_MEMORY ());
  this->buffering_strategy_.reset (buffering_strategy);

  long flags = THR_NEW_LWP | THR_DETACHED;
  CORBA::ORB_var orb =
    TAO_Notify_PROPERTIES::instance()->orb ();

  flags |=
    orb->orb_core ()->orb_params ()->thread_creation_flags ();

  // Guards the thread for auto-deletion; paired with close.
  // This is done in the originating thread before the spawn to
  // avoid any race conditions.
  for ( CORBA::ULong i = 0; i < tp_params.static_threads; ++i )
    {
      this->_incr_refcnt();
    }

  // Become an active object.
  if (this->ACE_Task <ACE_NULL_SYNCH>::activate (flags,
                                                 tp_params.static_threads,
                                                 0,
                                                 ACE_THR_PRI_OTHER_DEF) == -1)
    {
      // Undo the ref counts on error
      for ( CORBA::ULong i = 0; i < tp_params.static_threads; ++i )
        {
          this->_decr_refcnt();
        }

      if (ACE_OS::last_error () == EPERM)
        ORBSVCS_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Insufficient privilege.\n")));
      else if (ACE_OS::last_error () == EAGAIN)
        {
          ORBSVCS_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("(%P|%t) task activation at priority %d failed %p\n"),
                      tp_params.default_priority, "activate"));
          throw CORBA::NO_RESOURCES ();
        }

      throw CORBA::BAD_PARAM ();
    }
}
Ejemplo n.º 15
0
int modAOS_OCF_Extract::svc() {
	svcStart_();

	AOS_Transfer_Frame* frame = 0;

	while ( continueService() ) {
		ndSafeRelease(frame);
		std::pair<NetworkData*, int> queueTop = getData_();

		if ( msg_queue()->deactivated() ) break;

		if ( queueTop.second < 0 ) {
			MOD_ERROR("getData_() call failed.");
			continue;
		}
		else if ( ! queueTop.first ) {
			MOD_ERROR("getData_() returned with null data.");
			continue;
		}

		frame = dynamic_cast<AOS_Transfer_Frame*>(queueTop.first);

		if ( ! frame ) {
			MOD_INFO("Received %d octets of non-AOS data! Dropping.", queueTop.first->getUnitLength());
			ndSafeRelease(queueTop.first);
			continue;
		}

		queueTop.first = 0;

		MOD_DEBUG("Received %d-octet frame.", frame->getUnitLength());
		frame->useOperationalControl(true);

		// Test expected values.
		if (frame->getUnitLength() != getFrameSizeU()) {
			MOD_WARNING("AOS Transfer Frame bad length: received %d octets, needed %d.", frame->getUnitLength(), getFrameSize());
			incBadLengthCount();
			if ( getDropBadFrames() ) continue;
		}
		else incValidFrameCount();

		_extractAndSendOCF(frame);

		if ( links_[PrimaryOutputLink] ) {
			MOD_DEBUG("Sending a %d-octet AOS Transfer Frame.", frame->getUnitLength());
			links_[PrimaryOutputLink]->send(frame);
			frame = 0; // important
		}
		else {
			MOD_ERROR("No output target defined, dropping frame.");
		}

		MOD_DEBUG("Finished processing incoming frame.");
	}

	return svcEnd_();
}
Ejemplo n.º 16
0
int AC_Output_Handler::put (ACE_Message_Block *mb,
                            ACE_Time_Value *timeout) {
  int retval;
  while ((retval = putq (mb, timeout)) == -1) {
    if (msg_queue ()->state () != ACE_Message_Queue_Base::PULSED)
      break;
  }
  return retval;
}
Ejemplo n.º 17
0
int RealmSocket::handle_output(ACE_HANDLE)
{
    if (closing_)
        return -1;

    ACE_Message_Block* mb = 0;

    if (msg_queue()->is_empty())
    {
        reactor()->cancel_wakeup(this, ACE_Event_Handler::WRITE_MASK);
        return 0;
    }

    if (msg_queue()->dequeue_head(mb, (ACE_Time_Value *)(&ACE_Time_Value::zero)) == -1)
        return -1;

    ssize_t n = noblk_send(*mb);

    if (n < 0)
    {
        mb->release();
        return -1;
    }
    else if (size_t(n) == mb->length())
    {
        mb->release();
        return 1;
    }
    else
    {
        mb->rd_ptr(n);

        if (msg_queue()->enqueue_head(mb, (ACE_Time_Value *) &ACE_Time_Value::zero) == -1)
        {
            mb->release();
            return -1;
        }

        return 0;
    }

    ACE_NOTREACHED(return -1);
}
Ejemplo n.º 18
0
        void Debuger::handle_timer()
        {
            Message msg_pop;
            msg_pop.level = MSGLEVEL;
            msg_pop.type = MSGTYPEDEBUG;
            if (msg_queue().pop(msg_pop)) {
                check_debug_mode();

                Message msg_push;
                msg_push.level = MSGLEVEL;
                msg_push.type = MSGTYPEDEBUG;
                msg_push.receiver = msg_pop.sender;
                msg_queue().push(msg_push);

                LOG_DEBUG("[handle_timer] msg: data = " << msg_pop.data 
                    << ", sender = " << msg_pop.sender
                    << ", receiver = " << msg_pop.receiver 
                    << ", level = " << msg_pop.level);
            }
        }
Ejemplo n.º 19
0
int CSenceManager::open(void* args)
{
	if(args != NULL)
	{
		OUR_DEBUG((LM_INFO, "[CMessageService::open]args is not NULL.\n"));
	}

	m_blRun = true;
	msg_queue()->high_water_mark(WATER_MASK);
	msg_queue()->low_water_mark(WATER_MASK);

	if(activate(THR_NEW_LWP | THR_JOINABLE | THR_INHERIT_SCHED | THR_SUSPENDED, 1) == -1)
	{
		OUR_DEBUG((LM_ERROR, "[CMessageService::open] activate error ThreadCount = [%d].", 1));
		m_blRun = false;
		return -1;
	}

	resume();

	return 0;
}
Ejemplo n.º 20
0
int
ACE_TMAIN (int, ACE_TCHAR *[])
{
  // Message queue.
  ACE_Message_Queue<ACE_MT_SYNCH> msg_queue (max_queue);

  if (thr_mgr.spawn (ACE_THR_FUNC (producer), (void *) &msg_queue,
                         THR_NEW_LWP | THR_DETACHED) == -1)
    ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "spawn"), 1);

  // Wait for producer and consumer threads to exit.
  thr_mgr.wait ();
  return 0;
}
Ejemplo n.º 21
0
int CMessageService::open(void* args)
{
    if(args != NULL)
    {
        OUR_DEBUG((LM_INFO,"[CMessageService::open]args is not NULL.\n"));
    }

    m_blRun = true;
    msg_queue()->high_water_mark(m_u4HighMask);
    msg_queue()->low_water_mark(m_u4LowMask);

    OUR_DEBUG((LM_INFO,"[CMessageService::open] m_u4HighMask = [%d] m_u4LowMask = [%d]\n", m_u4HighMask, m_u4LowMask));

    if(activate(THR_NEW_LWP | THR_JOINABLE | THR_INHERIT_SCHED | THR_SUSPENDED, MAX_MSG_THREADCOUNT) == -1)
    {
        OUR_DEBUG((LM_ERROR, "[CMessageService::open] activate error ThreadCount = [%d].", MAX_MSG_THREADCOUNT));
        m_blRun = false;
        return -1;
    }

    resume();

    return 0;
}
Ejemplo n.º 22
0
int WorldSocket::Update (void)
{
    if (closing_)
        return -1;

    if (m_OutActive || (m_OutBuffer->length() == 0 && msg_queue()->is_empty()))
        return 0;

    int ret;
    do
        ret = handle_output (get_handle());
    while (ret > 0);

    return ret;
}
Ejemplo n.º 23
0
 //内部调用
 void Debuger::check_debug_mode()
 {
     if (debug_mode_) {
         if (*debug_mode_ == 1) {
             if (!debug_log_stream_) {
                 debug_log_stream_ = new MsgQueueStream(msg_queue());
             }
             out_streamed_ = true;
             framework::logger::add_stream(*debug_log_stream_);
             LOG_INFO("[check_debug_mode] enter debug mode");
         } else  if (*debug_mode_ == 0 && debug_log_stream_) {
             LOG_INFO("[check_debug_mode] leave debug mode");
             out_streamed_ = false;
             framework::logger::del_stream(*debug_log_stream_);
         }
     }
 }
Ejemplo n.º 24
0
/**
    \brief Called when we start to service a new connection, here we tell reactor to wake us when queue() is not empty.
    \return -1 if there was a problem opening a new link, getting remote's address or registering client handler
  */
int AuthLink::open (void *p)
{
    m_state=AuthLink::INITIAL;
    if (this->m_peer.get_remote_addr (m_peer_addr) == -1)
        ACE_ERROR_RETURN ((LM_ERROR,ACE_TEXT ("%p\n"),ACE_TEXT ("get_remote_addr")),-1);
    if (EventProcessor::open (p) == -1)
        return -1;
    // Register this as a READ handler, this way will be notified/waken up when new bytes are available
    if (this->reactor () && this->reactor ()->register_handler(this,ACE_Event_Handler::READ_MASK) == -1)
        ACE_ERROR_RETURN ((LM_ERROR,ACE_TEXT ("%p\n"),ACE_TEXT ("unable to register client handler")),-1);
    // m_notifier will tell reactor to wake us when new packet is ready for sending
    m_notifier.reactor(reactor());                      // notify reactor with write event,
    msg_queue()->notification_strategy (&m_notifier);   // whenever there is a new event on msg_queue() we will be notified
    //TODO: consider using sync query here.
    m_target->putq(new ConnectEvent(this,m_peer_addr)); // also, inform the AuthHandler of our existence
    return 0;
}
Ejemplo n.º 25
0
bool CSenceManager::PutMessage(uint32 u4CommandID, _CommandInfo& objCommandInfo)
{
	_QueueMessage* pQueueMessage = m_objMessagePool.Create();
	if(NULL == pQueueMessage)
	{
		OUR_DEBUG((LM_INFO,"[CSenceManager::PutMessage] m_objMessagePool not enougth!\n"));
		return false;
	}

	pQueueMessage->m_u4CommandID = u4CommandID;
	pQueueMessage->m_objData    = objCommandInfo;

	ACE_Message_Block* pmb = m_objMessageBlockPool.Create(sizeof(_QueueMessage*));
	if(NULL == pmb)
	{
		OUR_DEBUG((LM_INFO,"[CSenceManager::PutMessage] m_objMessageBlockPool not enougth!\n"));
		m_objMessagePool.Delete(pQueueMessage);
		return false;
	}

	_QueueMessage** ppMessage = (_QueueMessage **)pmb->base();
	*ppMessage = pQueueMessage;

	//判断队列是否是已经最大
	int nQueueCount = (int)msg_queue()->message_count();
	if(nQueueCount >= (int)QUEUE_COUNT)
	{
		OUR_DEBUG((LM_ERROR,"[CSenceManager::PutMessage] Queue is Full nQueueCount = [%d].\n", nQueueCount));
		m_objMessageBlockPool.Delete(pmb);
		m_objMessagePool.Delete(pQueueMessage);
		return false;
	}

	ACE_Time_Value xtime = ACE_OS::gettimeofday();
	if(this->putq(pmb, &xtime) == -1)
	{
		OUR_DEBUG((LM_ERROR,"[CSenceManager::PutMessage] Queue putq  error nQueueCount = [%d] errno = [%d].\n", nQueueCount, errno));
		m_objMessageBlockPool.Delete(pmb);
		m_objMessagePool.Delete(pQueueMessage);
		return false;
	}

	return true;
}
Ejemplo n.º 26
0
int WorldSocket::Update (void)
{
    if (closing_)
        return -1;

    if (m_OutActive)
        return 0;

    {
        ACE_GUARD_RETURN(LockType, Guard, m_OutBufferLock, 0);
        if (m_OutBuffer->length() == 0 && msg_queue()->is_empty())
            return 0;
    }

    int ret;
    do
    ret = handle_output(get_handle());
    while (ret > 0);

    return ret;
}
Ejemplo n.º 27
0
int CLogManager::PutLog(_LogBlockInfo* pLogBlockInfo)
{
    ACE_Message_Block* mb = pLogBlockInfo->GetQueueMessage();

    //如果正在重新加载
    if(m_blIsNeedReset == true)
    {
        //回收日志块
        m_objLogBlockPool.ReturnBlockInfo(pLogBlockInfo);
        return 0;
    }

    if(mb)
    {
        int msgcount = (int)msg_queue()->message_count();

        if (msgcount >= m_nQueueMax)
        {
            OUR_DEBUG((LM_INFO,"[CLogManager::PutLog] CLogManager queue is full!\n"));
            //回收日志块
            m_objLogBlockPool.ReturnBlockInfo(pLogBlockInfo);
            return -1;
        }

        ACE_Time_Value xtime = ACE_OS::gettimeofday()+ACE_Time_Value(0, MAX_MSG_PUTTIMEOUT);

        if(this->putq(mb, &xtime) == -1)
        {
            OUR_DEBUG((LM_ERROR,"[CLogManager::PutLog] CLogManager putq error(%s)!\n", pLogBlockInfo->m_pBlock));
            //回收日志块
            m_objLogBlockPool.ReturnBlockInfo(pLogBlockInfo);
            return -1;
        }

        return 0;
    }

    OUR_DEBUG((LM_ERROR,"[CLogManager::PutLog] CLogManager new ACE_Message_Block error!\n"));
    return -1;
}
Ejemplo n.º 28
0
// ./send_msg queue_name message_string
int main(int argc, char *argv[]) {
	assert(argc == 3);
	boost::interprocess::message_queue msg_queue(
		boost::interprocess::open_or_create,
		argv[1],	// queue name
		MAX_MESSAGE_NUMBER,	// max message number
		MAX_MESSAGE_SIZE * sizeof(char)	//max message size
	);
	
	msg_queue.send(argv[2], std::strlen(argv[2]), 1); // !!! send without \0
	
	/***********************/
	/*char receiveMsg[MAX_MESSAGE_SIZE];
	boost::interprocess::message_queue::size_type recv_size;
	unsigned int priority;
	msg_queue.try_receive(static_cast<void *>(receiveMsg), MAX_MESSAGE_SIZE, recv_size, priority);
	std::string receiveMsgStr(receiveMsg, recv_size);
	std::cout << "receiveMsgStr: " << receiveMsgStr << std::endl;
	std::cout << "recv_size " << recv_size << std::endl;
	std::cout << "priority " << priority << std::endl;*/
	return 0;
}
Ejemplo n.º 29
0
int WorldSocket::SendPacket(WorldPacket const& pct)
{
    ACE_GUARD_RETURN (LockType, Guard, m_OutBufferLock, -1);

    if (closing_)
        return -1;

    // Dump outgoing packet
    if (sPacketLog->CanLogPacket())
        sPacketLog->LogPacket(pct, SERVER_TO_CLIENT);

    WorldPacket data = pct;
    WorldPacket const* pkt = &data;

    // TODO : Find the compress flag
    // Empty buffer used in case packet should be compressed
    /*WorldPacket buff;
    if (m_Session && pkt->size() > 0x400)
    {
    buff.Compress(m_Session->GetCompressionStream(), pkt);
    pkt = &buff;
    }*/

    if (pkt->GetOpcode() != SMSG_MONSTER_MOVE)
        sLog->outInfo(LOG_FILTER_OPCODES, "S->C: %s", GetOpcodeNameForLogging(pkt->GetOpcode()).c_str());

    sScriptMgr->OnPacketSend(this, *pkt);
#ifdef ELUNA
    if (!sEluna->OnPacketSend(m_Session, data))
        return 0;
#endif

    ServerPktHeader header(pkt->size()+2, pkt->GetOpcode(), m_Crypt.IsInitialized());
    m_Crypt.EncryptSend ((uint8*)header.header, header.getHeaderLength());

    if (m_OutBuffer->space() >= pkt->size() + header.getHeaderLength() && msg_queue()->is_empty())
    {
        // Put the packet on the buffer.
        if (m_OutBuffer->copy((char*) header.header, header.getHeaderLength()) == -1)
            ACE_ASSERT (false);

        if (!pkt->empty())
            if (m_OutBuffer->copy((char*) pkt->contents(), pkt->size()) == -1)
                ACE_ASSERT (false);
    }
    else
    {
        // Enqueue the packet.
        ACE_Message_Block* mb;

        ACE_NEW_RETURN(mb, ACE_Message_Block(pkt->size() + header.getHeaderLength()), -1);

        mb->copy((char*) header.header, header.getHeaderLength());

        if (!pkt->empty())
            mb->copy((const char*)pkt->contents(), pkt->size());

        if (msg_queue()->enqueue_tail(mb, (ACE_Time_Value*)&ACE_Time_Value::zero) == -1)
        {
            sLog->outError(LOG_FILTER_NETWORKIO, "WorldSocket::SendPacket enqueue_tail failed");
            mb->release();
            return -1;
        }
    }

    return 0;
}
Ejemplo n.º 30
0
void Processer::Exit()
{
	loop = false;
	msg_queue()->deactivate();
	wait();
}