Up: Defining a New Stream   [Contents][Index]


6.6.2.1 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.

user_read()

Should fill a buffer with data available from the stream. See cpg-ref-user_read.

user_write()

Should write data from a buffer to the stream. See cpg-ref-user_write.

user_flush_output()

Should flush the (output) stream.

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.