//============================================================
TBool FNetMessageConsole::ProcessConnectionAll(FNetMessageConnection* pConnection){
   TBool result = EFalse;
   while(ProcessConnection(pConnection)){
      result = ETrue;
   }
   return result;
}
void ezPipeChannel_win::InternalConnect()
{
  if (m_PipeHandle == INVALID_HANDLE_VALUE)
    return;
  if (m_Connected)
    return;
#if EZ_ENABLED(EZ_COMPILE_FOR_DEBUG)
  if (m_ThreadId == 0)
    m_ThreadId = ezThreadUtils::GetCurrentThreadID();
#endif

  if (m_Mode == Mode::Server)
  {
    ProcessConnection();
  }
  else
  {
    m_Connected = true;
  }

  if (!m_InputState.IsPending)
  {
    OnIOCompleted(&m_InputState.Context, 0, 0);
  }

  if (m_Connected)
  {
    ProcessOutgoingMessages(0);
  }

  m_Events.Broadcast(ezIpcChannelEvent(m_Mode == Mode::Client ? ezIpcChannelEvent::ConnectedToServer : ezIpcChannelEvent::ConnectedToClient, this));
  return;
}
void ezPipeChannel_win::OnIOCompleted(IOContext* pContext, DWORD uiBytesTransfered, DWORD uiError)
{
  EZ_ASSERT_DEBUG(m_ThreadId == ezThreadUtils::GetCurrentThreadID(), "Function must be called from worker thread!");
  bool bRes = true;
  if (pContext == &m_InputState.Context)
  {
    if (!m_Connected)
    {
      if (!ProcessConnection())
        return;

      bool bHasOutput = false;
      {
        EZ_LOCK(m_OutputQueueMutex);
        bHasOutput = !m_OutputQueue.IsEmpty();
      }

      if (bHasOutput && m_OutputState.IsPending == 0)
        ProcessOutgoingMessages(0);
      if (m_InputState.IsPending)
        return;
    }
    bRes = ProcessIncomingMessages(uiBytesTransfered);
  }
  else
  {
    EZ_ASSERT_DEBUG(pContext == &m_OutputState.Context, "");
    bRes = ProcessOutgoingMessages(uiBytesTransfered);
  }
  if (!bRes && m_PipeHandle != INVALID_HANDLE_VALUE)
  {
    InternalDisconnect();
  }
}
Exemple #4
0
bool Channel::Connect() {
  //DLOG_IF(WARNING, thread_check_.get()) << "Connect called more than once";

  //if (!thread_check_.get())
  //  thread_check_.reset(new base::ThreadChecker());

  if (pipe_ == INVALID_HANDLE_VALUE)
    return false;

  thread_->RegisterIOHandler(pipe_, this);

  // Check to see if there is a client connected to our pipe...
  if (waiting_connect_)
    ProcessConnection();

  if (!input_state_.is_pending) {
    // Complete setup asynchronously. By not setting input_state_.is_pending
    // to true, we indicate to OnIOCompleted that this is the special
    // initialization signal.
	  thread_->PostTask(
        std::bind(&Channel::OnIOCompleted,
                   this,
                   &input_state_.context,
                   0,
                   0));
  }

  if (!waiting_connect_)
    ProcessOutgoingMessages(NULL, 0);
  return true;
}
//============================================================
TBool FNetMessageConsole::Process(){
   if(!_pConnections->IsEmpty()){
      TListIteratorC<FNetMessageConnection*> iterator = _pConnections->IteratorC();
      while(iterator.Next()){
         ProcessConnection(*iterator);
      }
   }
   return ETrue;
}
Exemple #6
0
void ServerProc(void)
{
	NTSTATUS st;
	OBJECT_ATTRIBUTES obj;
	UNICODE_STRING usPortName;
	PORT_MESSAGE pmMsg;
	DWORD  dwThreaId;

	RtlInitUnicodeString( &usPortName , SERVERNAME_W);
	InitializeObjectAttributes( &obj ,
								&usPortName,
								0,
								0,
								NULL);
	st = NtCreatePort ( &hConnectPort,
						&obj,
						MAX_DATA_SIZE,
						MAX_MESSAGE_SIZE,
						0);
	if (!NT_SUCCESS(st))
	{
		printf("failed to create port 0x%08X \n",st);
		return ;
	}

	RtlZeroMemory(&pmMsg,sizeof(pmMsg));
	while(1)
	{
		BOOLEAN bConnected;
		CONNECTION_INFO cnInfo;
		
		Sleep (100);
		bConnected = FALSE;
		memset ( &cnInfo , 0 , sizeof(CONNECTION_INFO));

		st = NtListenPort ( hConnectPort , &pmMsg);
		if (!NT_SUCCESS(st) || pmMsg.MessageType!=LPC_CONNECTION_REQUEST)
				continue;
		
		bConnected = ProcessConnection ( &pmMsg , &cnInfo);
		if(!bConnected)
			continue;
		CreateThread ( NULL,
					   0,
					   (LPTHREAD_START_ROUTINE)ProcessMsg ,
					   (LPVOID)&cnInfo,
					   0,
					   &dwThreaId);
		//wait until the new thread copied the param that passed by this function
		WaitForSingleObject ( hNotifyEvent , INFINITE);
	}
}
Exemple #7
0
void CServerBrowser::StartConnection ( void )
{
	// Are we already connected to a server?
	if( pCore->GetNetworkModule() && pCore->GetNetworkModule()->IsConnected() )
	{
		// Disconnect from the server
		pCore->GetNetworkModule()->Disconnect();

		// Stop multiplayer
		pCore->StopMultiplayer ();

		// Set the connection state
		SetConnectionState( CONNECTION_STATE_CONNECTING );

		// Start multiplayer
		pCore->StartMultiplayer ();

		// Connect!
		ProcessConnection ();
	}

	// Is the game not yet loaded?
	if( !pCore->IsGameLoaded() )
	{
		// Set the connection state
		SetConnectionState( CONNECTION_STATE_WAITING_FOR_GAME );

		// Show the message box
		SetMessageBox ( "Connecting", "Waiting for game to load..." );
	}
	else
	{
		// Move to the next step
		m_connectionState = CONNECTION_STATE_CONNECTING;

		// Connect!
		ProcessConnection ();
	}
}
Exemple #8
0
void main( int argc, char *argv[] )
{
    APIRET      rc;
    HFILE       h;
    unsigned long       actiontaken;
    unsigned long       sent;
    char        done;

    if( argc > 1 && (argv[1][0] == 'q' || argv[1][0] == 'Q') ) {
        rc = DosOpen( PREFIX DEFAULT_NAME, &h, &actiontaken, 0ul,
                        0, 0x01, 0x41, 0ul );
        if( rc == 0 ) {
            done = LNK_SHUTDOWN;
            DosWrite( h, &done, sizeof( done ), &sent );
            DosClose( h );
        }
        exit( 0 );
    }
    CmdProc = getenv( "COMSPEC" );
    if( CmdProc == NULL ) {
        fprintf( stderr, "Unable to find command processor\n" );
        exit( 1 );
    }
    //NYI: need to accept name for link pipe
    rc = DosCreateNPipe( PREFIX DEFAULT_NAME, &LnkHdl,
        NP_NOINHERIT | NP_NOWRITEBEHIND | NP_ACCESS_DUPLEX,
        NP_WAIT | NP_READMODE_MESSAGE | NP_TYPE_MESSAGE | 1,
        MAX_TRANS, MAX_TRANS, 0 );
    if( rc != 0 ) {
        fprintf( stderr, "Unable to create link pipe\n" );
        exit( 1 );
    }
    sprintf( RedirName, PREFIX "%d", getpid() );
    rc = DosCreateNPipe( RedirName, &RedirHdl,
        NP_NOINHERIT | NP_WRITEBEHIND | NP_ACCESS_INBOUND,
        NP_WAIT | NP_READMODE_BYTE | NP_TYPE_BYTE | 1,
        MAX_TRANS, MAX_TRANS, 0 );
    if( rc != 0 ) {
        fprintf( stderr, "Unable to create redirection pipe\n" );
        exit( 1 );
    }
    DosSetFHState( LnkHdl, OPEN_FLAGS_NOINHERIT );
    DosSetFHState( RedirHdl, OPEN_FLAGS_NOINHERIT );
    for( ;; ) {
        rc = DosConnectNPipe( LnkHdl );
        if( rc == 0 ) {
            ProcessConnection();
            DosDisConnectNPipe( LnkHdl );
        }
    }
}
Exemple #9
0
void Channel::OnIOCompleted(
    Thread::IOContext* context,
    DWORD bytes_transfered,
    DWORD error) {
  bool ok = true;
  //assert(thread_check_->CalledOnValidThread());
  if (context == &input_state_.context) {
    if (waiting_connect_) {
      if (!ProcessConnection())
        return;
      // We may have some messages queued up to send...
      if (!output_queue_.empty() && !output_state_.is_pending)
        ProcessOutgoingMessages(NULL, 0);
      if (input_state_.is_pending)
        return;
      // else, fall-through and look for incoming messages...
    }

    // We don't support recursion through OnMessageReceived yet!
	assert(!processing_incoming_);
	processing_incoming_ = true;

    // Process the new data.
    if (input_state_.is_pending) {
      // This is the normal case for everything except the initialization step.
      input_state_.is_pending = false;
      if (!bytes_transfered)
        ok = false;
      else if (pipe_ != INVALID_HANDLE_VALUE)
        ok = AsyncReadComplete(bytes_transfered);
    } else {
      assert(!bytes_transfered);
    }

    // Request more data.
    if (ok)
      ok = ProcessIncomingMessages();

	processing_incoming_ = false;
  } else {
	  assert(context == &output_state_.context);
    ok = ProcessOutgoingMessages(context, bytes_transfered);
  }
  if (!ok && INVALID_HANDLE_VALUE != pipe_) {
    // We don't want to re-enter Close().
    Close();
    listener()->OnChannelError();
  }
}
Exemple #10
0
void main( int argc, char *argv[] )
{
    SECURITY_ATTRIBUTES attr;

    argc=argc;argv=argv;
#if 0
    if( argc > 1 && (argv[1][0] == 'q' || argv[1][0] == 'Q') ) {
        h = CreateFile( PREFIX DEFAULT_NAME, GENERIC_WRITE, 0,
                NULL, OPEN_EXISTING, 0, NULL );
        if( h != INVALID_HANDLE_VALUE ) {
            done = LNK_SHUTDOWN;
            WriteFile( h, &done, sizeof( done ), &sent, NULL );
            CloseHandle( h );
        }
        exit( 0 );
    }
#endif
    SemReadUp = CreateSemaphore( NULL, 0, 1, READUP_NAME );
    SemReadDone = CreateSemaphore( NULL, 0, 1, READDONE_NAME );
    SemWritten = CreateSemaphore( NULL, 0, 1, WRITTEN_NAME );
    MemHdl = CreateFileMapping( INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 1024, SHARED_MEM_NAME  );
    SharedMem = MapViewOfFile( MemHdl, FILE_MAP_WRITE, 0, 0, 0 );
    CmdProc = getenv( "ComSpec" );
    if( CmdProc == NULL ) {
        fprintf( stderr, "Unable to find command processor\n" );
        exit( 1 );
    }
    SetConsoleCtrlHandler( NULL, FALSE );
    SetConsoleCtrlHandler( Ignore, TRUE );
    //NYI: need to accept name for link pipe
    attr.nLength = sizeof( attr );
    attr.lpSecurityDescriptor = NULL;
    attr.bInheritHandle = TRUE;
    NulHdl = CreateFile( "NUL", GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, &attr, OPEN_EXISTING, 0, NULL );
    if( NulHdl == INVALID_HANDLE_VALUE ) {
        fprintf( stderr, "Unable to open NUL device\n" );
        exit( 1 );
    }
    EnumWindows( HideWindows , 0 );

    Say(( "LNK_UP\n" ));
    for( ;; ) {
        ProcessConnection();
    }
}
Exemple #11
0
void CServerBrowser::Pulse( void )
{
	// Pulse the current server list
	if ( m_pServerList [ GetCurrentServerBrowserType () ] )
		m_pServerList [ GetCurrentServerBrowserType () ]->Pulse ();

	// Pulse the connection state
	if( m_connectionState == CONNECTION_STATE_WAITING_FOR_GAME )
	{
		// Is the game loaded now?
		if( pCore->IsGameLoaded() )
		{
			// Move to the next step
			m_connectionState = CONNECTION_STATE_CONNECTING;

			// Connect!
			ProcessConnection();
		}
	}
	else if( m_connectionState == CONNECTION_STATE_FAILED )
	{
		// Has 3 seconds passed?
		if( (SharedUtility::GetTime() - m_ulFailedTime) >= 3000 )
		{
			// Hide the message box
			m_pMessageBox->SetVisible ( false );

			// Show the main menu
			pCore->GetGUI()->GetMainMenu()->SetVisible( true );

			// Reset the connection state
			SetConnectionState( CONNECTION_STATE_NONE );

			// Reset the failed time
			m_ulFailedTime = 0;
		}
	}
}