OSF DCE Application Development Guide--Core Components

Topics in RPC Application Development
One of the pipe support routines that the client must provide is an alloc routine, which
allocates a buffer for each chunk of pipe data. Given that pipes are intended to process
data asynchronously, consuming it as it arrives, the alloc routine should not just blindly
allocate a new buffer each time it is called, since the net effect would be to allocate
space for the whole stream. A reasonable approach is either to declare a buffer statically
or allocate it on the first call (per thread), and thereafter simply return the same buffer.
The following code example shows the form an alloc routine takes in client application
code.
#define CLIENT_BUFFER_SIZE 2048
idl_byte client_buffer[CLIENT_BUFFER_SIZE];
void client_alloc (state, bsize, buf, bcount)
rpc_ss_pipe_state_t state;
unsigned int bsize;
byte **buf;
unsigned int *bcount;
{
*buf = client_buffer;
*bcount = CLIENT_BUFFER_SIZE;
}
16.4.1 InputPipes
In the following example, a client sends the contents of a file to a server as a set of
chunks allocated from the same static buffer. The chunks are processed (in this case
simply printed) as they arrive.
The declaration in the interface definition is as follows:
typedef pipe char test_pipe_t;
void pipe_test1(
[in] handle_t handle,
[in] test_pipe_t test_pipe,
[out] error_status_t *status
);
Note that the pipe is declared as a typedef, resulting in an IDL-generated C typedef for
test_pipe_t, which is a structure containing pointers to the pipe support routines and a
pipe state field. The server manager and client code then implement the pipe in a
complementary fashion.
For an [in] pipe, the server manager code consists of a cycle of calls to the test_pipe.pull
routine (a server stub routine) which terminates when a zero-length chunk is received:
void
pipe_test1(
124245 Tandem Computers Incorporated 16 25