## bonobo-stream-client

bonobo-stream-client — Simplified client wrapper functions for the Stream interface

## Synopsis

    void                bonobo_stream_client_write          (const Bonobo_Stream stream,
                                                             const void *buffer,
                                                             const size_t size,
                                                             CORBA_Environment *ev);
    guint8 *            bonobo_stream_client_read           (const Bonobo_Stream stream,
                                                             const size_t size,
                                                             CORBA_long *length_read,
                                                             CORBA_Environment *ev);
    void                bonobo_stream_client_write_string   (const Bonobo_Stream stream,
                                                             const char *str,
                                                             const gboolean terminate,
                                                             CORBA_Environment *ev);
    void                bonobo_stream_client_printf         (const Bonobo_Stream stream,
                                                             const gboolean terminate,
                                                             CORBA_Environment *ev,
                                                             const char *fmt,
                                                             ...);
    CORBA_long          bonobo_stream_client_read_string    (const Bonobo_Stream stream,
                                                             char **str,
                                                             CORBA_Environment *ev);
    CORBA_long          bonobo_stream_client_get_length     (const Bonobo_Stream stream,
                                                             CORBA_Environment *ev);

## Description

These interfaces are designed to make the stream interface slightly easier to use from client code. This is done 2 ways, first by make the exception environments optiional, and secondly by providing slightly nicer semantics.

Example 24. Writing some simple data to a stream

    1

    bonobo_stream_client_printf (stream, TRUE, ev, "Hello World: %d", 5);

It is well worth using the bonobo_stream_client_write function for any potentialy large writes, since this blocks the data into sensible chunks. This is important, otherwise a single transfer is attempted that will cause hassles in the CORBA stubs. [ NB. ORBit tries to alloca a huge chunk of memory and SEGVs ].

## Details

### bonobo_stream_client_write ()

    void                bonobo_stream_client_write          (const Bonobo_Stream stream,
                                                             const void *buffer,
                                                             const size_t size,
                                                             CORBA_Environment *ev);

This is a helper routine to write `size` bytes from `buffer` to the `stream`. It will continue to write bytes until a fatal error occurs. It works around serious problems in ORBit's handling of sequences, and makes for nicer, saner protocol usage for transfering huge chunks of data.

`stream` : | A CORBA Object reference to a Bonobo_Stream
`buffer` : | the buffer to write
`size` : | number of bytes to write
`ev` : | a CORBA environment to return status information.

### bonobo_stream_client_read ()

    guint8 *            bonobo_stream_client_read           (const Bonobo_Stream stream,
                                                             const size_t size,
                                                             CORBA_long *length_read,
                                                             CORBA_Environment *ev);

This is a helper routine to read `size` bytes from the `stream` into a freshly g_ allocated buffer which is returned. Whilst this routine may seem pointless; it reads the stream in small chunks avoiding possibly massive alloca's inside ORBit's stub/skel code.

`stream` : | A CORBA Object reference to a Bonobo_Stream
`size` : | number of bytes to read or -1 for whole stream.
`length_read` : | if non NULL will be set to the length read
`ev` : | a CORBA environment to return status information.
Returns : | NULL on any sort of failure & 0 size read.

### bonobo_stream_client_write_string ()

    void                bonobo_stream_client_write_string   (const Bonobo_Stream stream,
                                                             const char *str,
                                                             const gboolean terminate,
                                                             CORBA_Environment *ev);

This is a helper routine to write the string in `str` to `stream`. If `terminate` is TRUE, a NULL character will be written out at the end of the string. This function will not return until the entire string has been written out, unless an exception is raised. See also `bonobo_stream_client_write()`. Continues writing until finished or a fatal exception occurs.

`stream` : | A CORBA object reference to a Bonobo_Stream.
`str` : | A string.
`terminate` : | Whether or not to write the \0 at the end of the string.
`ev` : | A pointer to a CORBA_Environment

### bonobo_stream_client_printf ()

    void                bonobo_stream_client_printf         (const Bonobo_Stream stream,
                                                             const gboolean terminate,
                                                             CORBA_Environment *ev,
                                                             const char *fmt,
                                                             ...);

Processes `fmt` and the arguments which follow it to produce a string. Writes this string out to `stream`. This function will not return until the entire string is written out, unless an exception is raised. See also `bonobo_stream_client_write_string()` and `bonobo_stream_client_write()`.

`stream` : | A CORBA object reference to a Bonobo_Stream.
`terminate` : | Whether or not to null-terminate the string when it is written out to the stream.
`ev` : | A CORBA_Environment pointer.
`fmt` : | The printf format string.
`...` : | format arguments

### bonobo_stream_client_read_string ()

    CORBA_long          bonobo_stream_client_read_string    (const Bonobo_Stream stream,
                                                             char **str,
                                                             CORBA_Environment *ev);

Reads a NULL-terminated string from `stream` and stores it in a newly-allocated string in `str`.

`stream` : | The Bonobo_Stream from which the string will be read.
`str` : | The string pointer in which the string will be stored.
`ev` : | A pointer to a CORBA_Environment.
Returns : | The number of bytes read, or -1 if an error occurs. If an exception occurs, `ev` will contain the exception.

### bonobo_stream_client_get_length ()

    CORBA_long          bonobo_stream_client_get_length     (const Bonobo_Stream stream,
                                                             CORBA_Environment *ev);

Does the grunt work to get the length of a stream, returns -1 if the length is not available. Returns -1 on exception.

`stream` : | The stream.
`ev` : | Exception environment
Returns : | Length or -1

## See Also

BonoboStream