Example #1
0
bool NetResMgr::AsyncTcpAccept(TcpHandle handle, const TcpSocketPtr& socket, std::unique_ptr<tcp::AcceptBuffer> buffer) {
  auto accept_socket = std::make_unique<tcp::Socket>();
  if (!accept_socket) {
    LOG(kError, "AsyncTcpAccept failed: can not new tcp socket.");
    return false;
  }
  if (!accept_socket->Create()) {
    return false;
  }
  if (!buffer) {
    buffer = std::make_unique<tcp::AcceptBuffer>();
    if (!buffer) {
      LOG(kError, "AsyncTcpAccept failed: can not new accept buffer.");
      return false;
    }
  }
  auto async_sock = accept_socket->socket();
  buffer->Reset();
  buffer->set_handle(handle);
  buffer->set_accept_socket(std::move(accept_socket));
  if (!socket->AsyncAccept(async_sock, buffer->buffer(), buffer->buffer_size(), buffer->ovlp())) {
    return false;
  }
  buffer.release();
  return true;
}
Example #2
0
bool NetResMgr::AsyncTcpRecv(TcpHandle handle, const TcpSocketPtr& socket, std::unique_ptr<tcp::RecvBuffer> buffer) {
  if (!buffer) {
    buffer = std::make_unique<tcp::RecvBuffer>();
    if (!buffer) {
      LOG(kError, "AsyncTcpRecv failed: can not new recv buffer.");
      return false;
    }
  }
  buffer->Reset();
  buffer->set_handle(handle);
  if (!socket->AsyncRecv(buffer->buffer(), buffer->buffer_size(), buffer->ovlp())) {
    return false;
  }
  buffer.release();
  return true;
}
Example #3
0
SPELUNKBOT_API double Update(double botSelector, double botXPos, double botYPos)
{
	if (!bot)
	{
		CreateBot(botSelector);
	}
	else
	{
		// Use Update to select a bot to run
		bot->Reset();
		bot->UpdateBotPosition(botXPos, botYPos);
		bot->Update();
	}

	return 1;
}
//--------------------------------------------------------------------------------------
// Called every time the application receives a message
//--------------------------------------------------------------------------------------
LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
    PAINTSTRUCT ps;
    HDC hdc;

    switch( message )
    {
        case WM_PAINT:
            hdc = BeginPaint( hWnd, &ps );
            EndPaint( hWnd, &ps );
            break;

        case WM_DESTROY:
            PostQuitMessage( 0 );
            break;

#ifdef DXTK_AUDIO

        case WM_CREATE:
            if ( !g_hNewAudio )
            {
                // Ask for notification of new audio devices
                DEV_BROADCAST_DEVICEINTERFACE filter = {0};
                filter.dbcc_size = sizeof( filter );
                filter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
                filter.dbcc_classguid = KSCATEGORY_AUDIO;

                g_hNewAudio = RegisterDeviceNotification( hWnd, &filter, DEVICE_NOTIFY_WINDOW_HANDLE );
            }
            break;

        case WM_CLOSE:
            if ( g_hNewAudio )
            {
                UnregisterDeviceNotification( g_hNewAudio );
                g_hNewAudio = nullptr;
            }
            DestroyWindow( hWnd );
            break;

        case WM_DEVICECHANGE:
            switch( wParam )
            {
            case DBT_DEVICEARRIVAL:
                {
                    auto pDev = reinterpret_cast<PDEV_BROADCAST_HDR>( lParam );
                    if( pDev )
                    {
                        if ( pDev->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE )
                        {
                            auto pInter = reinterpret_cast<const PDEV_BROADCAST_DEVICEINTERFACE>( pDev );
                            if ( pInter->dbcc_classguid == KSCATEGORY_AUDIO )
                            {
#ifdef _DEBUG
                                OutputDebugStringA( "INFO: New audio device detected: " );
                                OutputDebugString( pInter->dbcc_name );
                                OutputDebugStringA( "\n" );
#endif
                                // Setup timer to see if we need to try audio in a second
                                SetTimer( g_hWnd, 1, 1000, nullptr );
                            }
                        }
                    }
                }
                break;

            case DBT_DEVICEREMOVECOMPLETE:
                {
                    auto pDev = reinterpret_cast<PDEV_BROADCAST_HDR>( lParam );
                    if( pDev )
                    {
                        if ( pDev->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE )
                        {
                            auto pInter = reinterpret_cast<const PDEV_BROADCAST_DEVICEINTERFACE>( pDev );
                            if ( pInter->dbcc_classguid == KSCATEGORY_AUDIO )
                            {
                                // Setup timer to  see if we need to retry audio in a second
                                SetTimer( g_hWnd, 2, 1000, nullptr );
                            }
                        }
                    }
                }
                break;
            }
            return 0;

        case WM_TIMER:
            if ( wParam == 1 )
            {
                if ( !g_audEngine->IsAudioDevicePresent() )
                {
                    PostMessage( g_hWnd, WM_USER, 0, 0 );
                }
            }
            else if ( wParam == 2 )
            {
                if ( g_audEngine->IsCriticalError() )
                {
                    PostMessage( g_hWnd, WM_USER, 0, 0 );
                }
            }
            break;

        case WM_USER:
            if ( g_audEngine->IsCriticalError() || !g_audEngine->IsAudioDevicePresent() )
            {
                if ( g_audEngine->Reset() )
                {
                    // Reset worked, so restart looping sounds
                    g_effect1->Play( true );
                }
            }
            break;

#endif // DXTK_AUDIO

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

    return 0;
}
Example #5
0
unsigned int CancelSynchronousIoWrapper(void* Thread)
{
    unsigned int Result = Global->ifn->CancelSynchronousIo(Thread);
    CancelIoInProgress->Reset();
    return Result;
}