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()
int
user_write()
int
user_flush_output()
int
user_close()
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.