Previous: Initializing the library, Up: Generalities


5.3 How to communicate with the peer

What would be an IPC library without the ability to read and write data? Not very useful. Libassuan has high level functions to take care of of the more boring stuff but eventually data needs to be written and read.

The basic read and write functions are:

— Function: assuan_error_t assuan_read_line (assuan_context_t ctx, char **line, size_t *linelen)

Read the next line from the client or server and store a pointer to the buffer holding that line at the address line. The valid length of the lines is stored at the address of linelen. This buffer is valid until the next read operation on the same context ctx. You may modify the context of this buffer. The buffer is invalid (i.e. must not be used) if an error is returned. This function returns 0 on success or an error code.

— Function: assuan_error_t assuan_write_line (assuan_context_t ctx, const char *line)

Write the string line to the other end. This string needs to be a proper formatted Assuan protocol line and should not include a linefeed. Sending linefeed or Nul characters is not possible and not allowed by the assuan protocol. This function shall not be used for sending data (D) lines. This function returns 0 on success or an error code.

To actually send bulk data lines a specialized function is available:

— Function: assuan_error_t assuan_send_data (assuan_context_t ctx, const void *buffer, size_t length)

This function is used by a server or a client to send length bytes of bulk data in buffer to the other end. The data will be escaped as required by the Assuan protocol and may get buffered until a line is full. To force sending the data out buffer may be passed as NULL and length be 0.

When used by a client this flush operation does also send the terminating END command to terminate the response on an “INQUIRE” response. Note that the function assuan_transact takes care of sending this END itself.

This function returns 0 on success or an error code.