Example #1
0
    Win32NamedPipeServerTransport::SessionStatePtr 
    Win32NamedPipeServerTransport::createSessionState()
    {
        const std::size_t       MaxPipeInstances    = PIPE_UNLIMITED_INSTANCES;
        const DWORD             OutBufferSize       = 4096;
        const DWORD             InBufferSize        = 4096;
        const DWORD             DefaultTimeoutMs    = 0;

        HANDLE hPipe = CreateNamedPipe( 
            mPipeName.c_str(),
            PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
            PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT,
            MaxPipeInstances,
            OutBufferSize,
            InBufferSize,
            DefaultTimeoutMs,
            mpSec);

        DWORD dwErr = GetLastError();

        RCF_VERIFY(hPipe != INVALID_HANDLE_VALUE, Exception(_RcfError_Pipe(), dwErr));

        mpIocp->AssociateDevice(hPipe, 0);
        
        SessionStatePtr sessionStatePtr(new SessionState(*this, hPipe));

        sessionStatePtr->mWeakThisPtr = sessionStatePtr;

        return sessionStatePtr;
    }
 void Win32NamedPipeImpersonator::impersonate()
 {
     HANDLE hPipe = mPipeSession.mSocketPtr->native();
     BOOL ok = ImpersonateNamedPipeClient(hPipe);
     DWORD dwErr = GetLastError();
     RCF_VERIFY(ok, RCF::Exception(_RcfError_Pipe(), dwErr));
 }
    Win32NamedPipeNetworkSession::Win32NamedPipeNetworkSession(
        Win32NamedPipeServerTransport & transport,
        AsioIoService & ioService) :
            AsioNetworkSession(transport, ioService)
    {
        const std::size_t       MaxPipeInstances    = PIPE_UNLIMITED_INSTANCES;
        const DWORD             OutBufferSize       = 4096;
        const DWORD             InBufferSize        = 4096;
        const DWORD             DefaultTimeoutMs    = 0;

        HANDLE hPipe = CreateNamedPipe( 
            transport.mPipeName.c_str(),
            PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
            PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT,
            MaxPipeInstances,
            OutBufferSize,
            InBufferSize,
            DefaultTimeoutMs,
            transport.mpSec);

        DWORD dwErr = GetLastError();

        RCF_VERIFY(hPipe != INVALID_HANDLE_VALUE, Exception(_RcfError_Pipe(), dwErr));

        mSocketPtr.reset( new AsioPipeHandle(ioService, hPipe) );
    }
Example #4
0
    void Win32NamedPipeImpersonator::impersonate()
    {
        Win32NamedPipeSessionState & sessionState = 
            dynamic_cast<Win32NamedPipeSessionState &>(
                RCF::getCurrentRcfSessionPtr()->getSessionState());


        BOOL ok = ImpersonateNamedPipeClient(sessionState.mhPipe);
        DWORD dwErr = GetLastError();
        RCF_VERIFY(ok, RCF::Exception(_RcfError_Pipe(), dwErr));
    }
    std::size_t Win32NamedPipeClientTransport::implRead(
        const ByteBuffer &byteBuffer,
        std::size_t bytesRequested)
    {
        // For now, can't go back to sync calls after doing an async call.
        // Limitations with Windows IOCP.
        RCF_ASSERT(!mAsyncMode);

        std::size_t bytesToRead = RCF_MIN(bytesRequested, byteBuffer.getLength());

        BOOL ok = ResetEvent(mhEvent);
        DWORD dwErr = GetLastError();
        RCF_VERIFY(ok, Exception(_RcfError_Pipe(), dwErr));

        OVERLAPPED overlapped = {0};
        overlapped.hEvent = mhEvent;

        DWORD dwRead = 0;
        DWORD dwBytesToRead = static_cast<DWORD>(bytesToRead);

        ok = ReadFile(
            mhPipe, 
            byteBuffer.getPtr(), 
            dwBytesToRead, 
            &dwRead, 
            &overlapped);
        
        dwErr = GetLastError();

        if (!ok)
        {
            RCF_VERIFY( 
                dwErr == ERROR_IO_PENDING ||
                dwErr == WSA_IO_PENDING ||
                dwErr == ERROR_MORE_DATA,
                Exception(_RcfError_ClientReadFail(), dwErr));
        }

        ClientStub & clientStub = *getTlsClientStubPtr();

        DWORD dwRet = WAIT_TIMEOUT;
        while (dwRet == WAIT_TIMEOUT)
        {
            boost::uint32_t timeoutMs = generateTimeoutMs(mEndTimeMs);
            timeoutMs = clientStub.generatePollingTimeout(timeoutMs);

            dwRet = WaitForSingleObject(overlapped.hEvent, timeoutMs);
            dwErr = GetLastError();

            RCF_VERIFY( 
                dwRet == WAIT_OBJECT_0 || dwRet == WAIT_TIMEOUT, 
                Exception(_RcfError_Pipe(), dwErr));

            RCF_VERIFY(
                generateTimeoutMs(mEndTimeMs),
                Exception(_RcfError_ClientReadTimeout()))
                (mEndTimeMs)(bytesToRead);

            if (dwRet == WAIT_TIMEOUT)
            {
                clientStub.onPollingTimeout();
            }
        }
        RCF_ASSERT_EQ(dwRet , WAIT_OBJECT_0);

        dwRead = 0;
        ok = GetOverlappedResult(mhPipe, &overlapped, &dwRead, FALSE);
        dwErr = GetLastError();
        RCF_VERIFY(ok && dwRead > 0, Exception(_RcfError_Pipe(), dwErr));

        onTimedRecvCompleted(dwRead, 0);

        return dwRead;
    }
Example #6
0
 void Win32NamedPipeImpersonator::revertToSelf() const
 {
     BOOL ok = RevertToSelf();
     DWORD dwErr = GetLastError();
     RCF_VERIFY(ok, RCF::Exception(_RcfError_Pipe(), dwErr));
 }