2012年Windows NamedPipe将读取的数据限制为64k

时间:2017-11-21 19:02:59

标签: windows named-pipes windows-server-2012

我有2个进程使用重叠的i / o通过命名管道进行通信。在Window 2012 r2上,已经观察到在文件读取端读取的数据限制为64k。如果客户端进程在Windows 7 64位上运行,即使超过64k,客户端也能够获取数据。

while( TRUE ) 
        {

            // Read from the pipe. 

            BOOL fSuccess ;
            DWORD cbRead ;
            OVERLAPPED osRx ;
            memset( &osRx, 0, sizeof( osRx ) ) ;
            osRx.hEvent = m_hRxEvent ;
            // create a new message object
            m_pMsg = new CInMsg( 64*1024 ) ; // This is the message size and can be changed via registry
            fSuccess = ReadFile(
                                  m_hPipe,                  // pipe handle              
                                  m_pMsg->GetDataPtr(),         // buffer to receive reply  
                                  m_pMsg->GetBuffLength(),  // size of buffer           
                                  &cbRead,                      // number of bytes read     
                                  &osRx                         // overlapped           
                               );
            if(!fSuccess)
            {

                dwError = GetLastError() ;

                if( ERROR_IO_PENDING == dwError )
                {

                    fSuccess = GetOverlappedResult(
                                                    m_hPipe,    // handle to pipe       
                                                    &osRx,          // OVERLAPPED structure 
                                                    &cbRead,        // bytes transferred    
                                                    INFINITE        // wait 
                                                  ) ;          
                    if(!fSuccess)
                    {
                        dwError = GetLastError() ;
                    }
                }
            }


            if( !fSuccess )
            {
                while( ERROR_MORE_DATA == dwError )
                {

                    DWORD dwBytesLeft ;

                    // find out how much left

                    PeekNamedPipe( 
                                    m_hPipe,                    
                                    NULL,                           
                                    0,  
                                    NULL,
                                    NULL,
                                    &dwBytesLeft                    
                                 ) ; 


                    if( 0 == dwBytesLeft )
                    {
                        // break out as no data left

                        fSuccess = TRUE ;

                        break ;
                    }   





                    // Use the dwBytesLeft and create a new  CInMsg (pTempTmsMsg)
                    // Copy data from old to new Object
                    //delete old message


                    OVERLAPPED osTmpRx ;
                    memset( &osTmpRx, 0, sizeof( osTmpRx ) ) ;
                    osTmpRx.hEvent = m_hRxEvent ;
                    DWORD cbTmpRead ;

                    // now do another read

                    dwError = NO_ERROR ;

                    fSuccess = ReadFile(
                                          m_hPipe,                  
                                          m_pMsg->GetAppendBuffer(),    
                                          m_pMsg->GetAppendLength(),    
                                          &cbTmpRead,                   
                                          &osTmpRx                      
                                       );

                    if(!fSuccess)
                    {

                        dwError = GetLastError() ;

                        if( ERROR_IO_PENDING == dwError )
                        {

                            fSuccess = GetOverlappedResult(
                                                            m_hPipe,    
                                                            &osTmpRx,       
                                                            &cbTmpRead,     
                                                            INFINITE        
                                                          ) ;          
                            if(!fSuccess)
                            {
                                dwError = GetLastError() ;
                            }
                        }

                    }

                    m_pMsg->SetMsgLength( m_pMsg->GetMsgLength() + cbTmpRead ) ;

                    // set message size

                    cbRead += cbTmpRead ;

                }
            }

这是客户端的主循环。 管道在消息模式下创建,并且还设置了重叠标志。 应用程序使用Visual Studio 2008编译,两个进程都是32位。

是否需要从Windows Server 2012 r2设置任何限制?在Win Server 2016上观察到相同的行为。

由于

0 个答案:

没有答案