BOOL CNetPTCPConnection::Connect(const CIPAddress& Address ,DWORD TimeOut)
{
	if(GetServer()==NULL)
		return FALSE;

	if(m_Socket.GetState()==CNetSocket::SS_UNINITED)
	{
		if(!Create())
			return FALSE;
	}

	m_pEpollEventRouter->Init(this);

	if(TimeOut==NO_CONNECTION_TIME_OUT)
	{
		if(m_Socket.Connect(Address))
		{
			StartWork();
			return TRUE;
		}
	}
	else
	{
		if(m_Socket.ConnectNoBlocking(Address,TimeOut))
		{
			return TRUE;
		}
	}
	return FALSE;
}
Exemplo n.º 2
0
int CNetConnection::Update(int ProcessPacketLimit)
{

	int PacketCount=0;
	//处理Connect
	if(m_Socket.GetState()==CNetSocket::SS_CONNECTING)
	{
		m_Socket.Connected();
		if(m_Socket.GetState()==CNetSocket::SS_CONNECTED)
		{			
			StartWork();				
		}
		if(m_Socket.GetState()==CNetSocket::SS_UNUSED)
		{
			OnConnection(FALSE);			
		}
	}
	else
	{
		CEpollEventObject * pEpollEventObject;
		while(m_RecvQueue.PopFront(pEpollEventObject))
		{				
			OnRecvData(*(pEpollEventObject->GetDataBuff()));
			GetServer()->DeleteEventObject(pEpollEventObject);
			PacketCount++;
			if(PacketCount>=ProcessPacketLimit)
				break;
		}			
	}

	//处理关闭
	if(m_WantClose)
	{
		if(m_UseSafeDisconnect)
		{
			if(m_SendQueue.GetObjectCount()<=0)
			{
				Disconnect();		
			}			
		}
		else
		{
			Disconnect();
		}
	}
	return PacketCount;
}
Exemplo n.º 3
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {

    switch (message) {
        case WM_CREATE:
            Init();
            break;

        case WM_COMMAND:
            switch(LOWORD(wParam)) {
                case IDM_FILE_EXIT:
                    PostMessage(hWnd, WM_CLOSE, 0, 0);
                    break;

                case IDM_WORK:
                    StartWork();
                    break;

                case IDM_REST:
                    break;
            }
        break;

        case WM_PAINT:
            Paint();
        break;

        case WM_CLOSE:
            DestroyWindow(hWnd);
            break;

        case WM_DESTROY:
            Done();
            PostQuitMessage(0);
            break;

        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
            break;
    }

    return 0;
}
int CNetPTCPConnection::Update(int ProcessPacketLimit)
{

	int PacketCount=0;
	//处理Connect
	if(m_Socket.GetState()==CNetSocket::SS_CONNECTING)
	{
		m_Socket.Connected();
		if(m_Socket.GetState()==CNetSocket::SS_CONNECTED)
		{
			StartWork();
		}
		if(m_Socket.GetState()==CNetSocket::SS_UNUSED)
		{
			OnConnection(FALSE);
		}
	}

	return PacketCount;
}
Exemplo n.º 5
0
int CGtserviceModule::Run(int nShowCmd )
{
	CMessageLoop theLoop;
	AddMessageLoop(&theLoop);

	CMainDlg dlgMain;
	if(dlgMain.Create(NULL) == NULL)
	{
		ATLTRACE(_T("Main dialog creation failed!\n"));
		return 0;
	}
	m_pdlgMain = &dlgMain;
	dlgMain.ShowWindow(nShowCmd);

	
	StartWork();
	
	int nRet = theLoop.Run();
	_Module.RemoveMessageLoop();
	return nRet;
}
Exemplo n.º 6
0
void
CallbackManager::Update(Subject *subj)
{
    // If callback work is not yet allowed then return.
    if(!workAllowed)
        return;

    // Push some work onto the queue if there is a handler for the
    // subject that updated.
    threading->MUTEX_LOCK();
    SubjectCallbackDataMap::iterator it = callbacks.find(subj);
    if(it != callbacks.end())
    {
        if(it->second.handler != 0)
        {
            // Execute a callback to see if the work should be added to the 
            // work queue. This lets us not add work unless we know that we
            // will process it later in Python.
            bool addwork = true;
            if(it->second.addwork != 0)
                addwork = (*it->second.addwork)(subj, it->second.addwork_data);

            // Create a work item that identifies the callback to be
            // performed as well as the data that we should pass to
            // the callback that does that work.
            if(addwork)
            {
                WorkItem w;
                w.key = (AttributeSubject *)subj;
                w.data = ((AttributeSubject *)subj)->NewInstance(true);
                work.push_back(w);
            }
        }
    }
    bool hasWork = work.size() > 0;
    threading->MUTEX_UNLOCK();

    if(hasWork)
        StartWork();
}
Exemplo n.º 7
0
//------------------------------------------------------------------------
void CWorkOnTarget::Update(float frameTime, uint32 frameId)
{
	FUNCTION_PROFILER(GetISystem(), PROFILE_GAME);

	if(!m_firing)
		return;

	bool requireUpdate=false;

	CActor *pActor=m_pWeapon->GetOwnerActor();

	if(m_delayTimer>0.0f)
	{
		m_working = false;
		m_lastTargetId = 0;
		m_delayTimer -= frameTime;

		if(m_delayTimer<=0.0f)
		{
			m_delayTimer=0.0f;

			if(m_pWeapon->IsClient())
			{
				m_pWeapon->PlayAction(m_workactions.prefire.c_str());

				if(m_soundId!=INVALID_SOUNDID)
				{
					if(ISound *pSound=m_pWeapon->GetISound(m_soundId))
					{
						pSound->GetInterfaceDeprecated()->SetLoopMode(true);
						pSound->SetPaused(false);
					}
				}
			}
		}
	}

	if(!m_effectId && m_delayTimer<=0.0f && m_pWeapon->IsClient())
	{
		int slot = m_pWeapon->GetStats().fp ?  eIGS_FirstPerson :  eIGS_ThirdPerson;
		int id = m_pWeapon->GetStats().fp ? 0 : 1;

		CSingle::SEffectParams &effect=m_workparams.working_effect;

		if(!effect.effect[id].empty())
			m_effectId = m_pWeapon->AttachEffect(slot, 0, true, effect.effect[id].c_str(), effect.helper[id].c_str());
	}

	if(m_delayTimer<=0.0f && m_pWeapon->IsServer())
	{
		bool keepWorking=false;

		if(IEntity	*pEntity=CanWork())
		{
			if(pEntity->GetId() == m_lastTargetId)
				keepWorking=WorkOnTarget(pEntity, frameTime);
			else
			{
				if(IEntity *pLast=gEnv->pEntitySystem->GetEntity(m_lastTargetId))
					StopWork();

				StartWork(pEntity);
				keepWorking=true;
			}
		}

		if(!keepWorking)
		{
			StopWork();

			if(m_pWeapon->IsServer())
			{
				m_pWeapon->NetSetIsFiring(false);
				m_pWeapon->NetStopFire();
			}
		}
	}

	if(requireUpdate)
		m_pWeapon->RequireUpdate(eIUS_FireMode);
}