12.3.103 user_read()

Synopsis

     spio_t_error_code
     user_read(
       void *user_data,
       void *buf,
       size_t *pbuf_size,
       spio_t_bits read_options
       );

This is the prototype for one of the methods of user defined streams. It is used when SICStus need to obtain more data from the user defined stream.

Arguments

user_data
The same value as was passed to SP_create_stream().
buf
Points to a buffer allocated by the caller.
pbuf_size
Points to the size of the buffer. The buffer is always large enough to hold at least one byte (for binary streams) or one character (for text streams). When this function returns successfully, *pbuf_size should be set to the number of bytes stored in the buffer, which should always be positive for successful return.

Note that buffer size is measured in bytes also for text streams.

read_options
The following bits can be set:
SPIO_DEVICE_READ_OPTION_BINARY
This is always specified if the device was created as a binary device. The buffer should be filled with up to *pbuf_size bytes.
SPIO_DEVICE_READ_OPTION_TEXT
This is always specified if the device was created as a text device. The buffer should be filled with wide characters, i.e. spio_t_wchar. Note that *buf_size is size in bytes, not in characters.
SPIO_DEVICE_READ_OPTION_NONBLOCKING
If this is set then the function should return quickly, either with some data read or with a SPIO_E_WOULD_BLOCK code.

If your user_read will never block, you can ignore this value.

You should return SPIO_E_NOT_SUPPORTED if user_read cannot support non-blocking read.

Return Value

On success, *pbuf_size should be assigned and SPIO_S_NOERR or some other success code returned.

On failure, return a SPIO error code. Error codes with special meaning for user_read:

SPIO_E_END_OF_FILE
Return this when there are no more data to read.
SPIO_E_WOULD_BLOCK
SPIO_DEVICE_READ_OPTION_NONBLOCKING was set but the operation would block.
SPIO_E_NOT_SUPPORTED
Some unsupported option, e.g. SPIO_DEVICE_READ_OPTION_NONBLOCKING, was passed.

Other error codes may also be returned.

Description

Should fill buf with up to *buf_size bytes of data. Data should be either bytes, for a binary device, or spio_t_wchar (32 bit) wide characters, for a text device.

See Also

cpg-ref-SP_create_stream. Defining a New Stream.


Send feedback on this subject.