Server-Side Pipe Implementation

The server application performs pipe transfer by calling the server stub's pull or push routine in a loop. Normal termination of the loop occurs when a zero-sized chunk of data is passed.

//file: server.c (fragment)
uc_server.c
#define PIPE_TRANSFER_SIZE    100 /* Transfer 100 pipe elements at one time */
 
void InPipe(LONG_PIPE     long_pipe )
{
    long   local_pipe_buf[PIPE_TRANSFER_SIZE];
    ulong   actual_transfer_count = PIPE_TRANSFER_SIZE;
 
    while(actual_transfer_count > 0) /* Loop to get all 
                                        the pipe data elements */
    {
        long_pipe.pull(    long_pipe.state,
                            local_pipe_buf,
                            PIPE_TRANSFER_SIZE,
                            &actual_transfer_count);
        /* process the elements */
    } // end while
    return;
} //end InPipe
 
void OutPipe(LONG_PIPE *long_pipe )
{
 long   *long_pipe_data;
 ulong   index = 0;
 ulong   elts_to_send = PIPE_TRANSFER_SIZE;
 
/* Allocate memory for the data to be passed back in the pipe */
 long_pipe_data = (long *)malloc( sizeof(long) * PIPE_SIZE );
    
 while(elts_to_send >0) /* Loop to send pipe data elements */
 {
  if (index >= PIPE_SIZE)
     elts_to_send = 0;
  else
    {
     if ( (index + PIPE_TRANSFER_SIZE) > PIPE_SIZE )
          elts_to_send = PIPE_SIZE - index;
     else
          elts_to_send = PIPE_TRANSFER_SIZE;
    }
                    
  long_pipe->push( long_pipe->state,
                   &(long_pipe_data[index]),
                   elts_to_send ); 
  index += elts_to_send;
 
  } //end while
 
 free((void *)long_pipe_data);
 
 return;
}

See Also

pipe, /Oi