在服务器上实现输出管道

若要开始从服务器接收数据,客户端会调用服务器的远程过程之一。 此过程必须重复调用服务器的存根中的推送过程。 MIDL 编译器使用应用程序的 IDL 文件自动生成服务器的推送过程。

远程服务器例程在调用推送过程之前,必须使用数据填充输出管道的缓冲区。 每次服务器程序在其存根中调用推送过程时,推送过程都会封送数据并将其传输到客户端。 循环一直持续到服务器发送长度为零的缓冲区。

以下示例来自 Windows SDK 附带的示例中包含的 Pipedemo 程序。 它演示了一个使用管道将数据从服务器推送到客户端的远程服务器过程。

void OutPipe(LONG_PIPE *outputPipe )
{
    long *outputPipeData;
    ulong index = 0;
    ulong elementsToSend = PIPE_TRANSFER_SIZE;
 
    /* Allocate memory for the data to be passed back in the pipe */
    outputPipeData = (long *)malloc( sizeof(long) * PIPE_SIZE );
    
    while(elementsToSend >0) /* Loop to send pipe data elements */
    {
        if (index >= PIPE_SIZE)
            elementsToSend = 0;
        else
        {
            if ( (index + PIPE_TRANSFER_SIZE) > PIPE_SIZE )
                elementsToSend = PIPE_SIZE - index;
            else
                elementsToSend = PIPE_TRANSFER_SIZE;
        }
                    
        outputPipe->push( outputPipe->state,
                          &(outputPipeData[index]),
                          elementsToSend ); 
        index += elementsToSend;
 
    } //end while
 
    free((void *)outputPipeData);
 
}

/Oi