Low Level I/O Functions

For each new stream the appropriate low level I/O functions have to be defined. Error handling, prompt handling and character counting is handled in a layer above these functions. They all operate on a user defined private data structure specified when the stream is created.

int user_read()
Should fill a buffer with data available from the stream. See cpg-ref-user_read.
int user_write()
Should write data from a buffer to the stream. See cpg-ref-user_write.
int user_flush_output()
Should flush the (output) stream.
int user_close()
Should close the stream in the specified directions. Note that bi-directional streams can be closed one direction at a time.

Please note: A foreign resource that defines user defined streams must ensure that all its streams are closed when the foreign resource is unloaded. Failure to do this will lead to crashes when sicstus tries to close the stream using a user_close method that is no longer present.

The easiest way to ensure that all user defined streams of a particular class is closed is to use SP_fclose with the SP_FCLOSE_OPTION_USER_STREAMS. Another way is to use SP_next_stream and SP_get_stream_user_data to find all your streams and close them one by one. See cpg-ref-SP_fclose, cpg-ref-SP_next_stream and cpg-ref-SP_get_stream_user_data.

Send feedback on this subject.