示例#1
0
    void ClientStub::instantiateTransport()
    {
        CurrentClientStubSentry sentry(*this);
        if (!mTransport.get())
        {
            RCF_VERIFY(mEndpoint.get(), Exception(_RcfError_NoEndpoint()));
            mTransport.reset( mEndpoint->createClientTransport().release() );
            RCF_VERIFY(mTransport.get(), Exception(_RcfError_TransportCreation()));
        }

        if (    mAsync 
            &&  !mTransport->isAssociatedWithIoService())
        {
            RcfServer * preferred = getAsyncDispatcher();
            AsioIoService * pIoService = NULL;

            if (preferred)
            {
                ServerTransport & transport = preferred->getServerTransport();
                AsioServerTransport & asioTransport = dynamic_cast<AsioServerTransport &>(transport);
                pIoService = & asioTransport.getIoService();
            }
            else
            {
                pIoService = & getAmiThreadPool().getIoService();
            }

            mTransport->associateWithIoService(*pIoService);
        }
    }
    void PeriodicTimer::start()
    {
        mAsioTimerPtr.reset( new AsioTimer(getAmiThreadPool().getIoService()) );

        {
            Lock lock(mTcbPtr->mMutex);
            mTcbPtr->mpPeriodicTimer = this;
        }
        setTimer();
    }
    void Win32NamedPipeClientTransport::implConnectAsync(
        ClientTransportCallback &clientStub,
        unsigned int timeoutMs)
    {
        RCF_UNUSED_VARIABLE(timeoutMs);

        implClose();

        mpClientStub = &clientStub;

        HANDLE hPipe = INVALID_HANDLE_VALUE;

        hPipe = CreateFile( 
            mPipeName.c_str(),      // pipe name 
            GENERIC_READ |          // read and write access 
            GENERIC_WRITE, 
            0,                      // no sharing 
            mpSec,                  // default security attributes
            OPEN_EXISTING,          // opens existing pipe 
            FILE_FLAG_OVERLAPPED,   // non-blocking
            NULL);                  // no template file 

        DWORD dwErr = GetLastError();

        RecursiveLock lock(mOverlappedPtr->mMutex);

        mOverlappedPtr->mOpType = OverlappedAmi::Connect;

        if (hPipe != INVALID_HANDLE_VALUE)
        {
            mhPipe = hPipe;

            if (mpIoService)
            {
                mSocketPtr.reset( new AsioPipeHandle(*mpIoService, mhPipe) );
                mAsioTimerPtr.reset( new AsioDeadlineTimer(getAmiThreadPool().getIoService()) );
            }

            AsioErrorCode ec;

            //AmiIoHandler(mOverlappedPtr, ec)();

            mpIoService->post( AmiIoHandler(mOverlappedPtr, ec) );
        }
        else
        {
            AsioErrorCode ec(
                dwErr,
                ASIO_NS::error::get_system_category());

            mpIoService->post( AmiIoHandler(mOverlappedPtr, ec) );
        }
    }
 void Win32NamedPipeClientTransport::associateWithIoService(AsioIoService & ioService)
 {
     if (mSocketPtr)
     {
         RCF_ASSERT(mpIoService == & ioService);
     }
     else
     {
         if (mhPipe != INVALID_HANDLE_VALUE)
         {
             mSocketPtr.reset( new AsioPipeHandle(ioService, mhPipe) );
         }
         else
         {
             mSocketPtr.reset( new AsioPipeHandle(ioService) );
         }
         
         mAsioTimerPtr.reset( new AsioDeadlineTimer(getAmiThreadPool().getIoService()) );
         mpIoService = &ioService;
     }
 }