Plasma GitLab Archive
Projects Blog Knowledge

Module Netstream


module Netstream: sig .. end
A netstream is an input channel that is read block by block. The fragment of the channel currently loaded into memory is called the current window of the netstream. The window can be thought as look-ahead buffer.

Picture:

 0                pos_in        pos_in + window_length            EOF
 +------------------+-------------------+--------------------------+
                    ====================
                     The current window
 

You can use a netstream like an in_obj_channel, and read characters and strings from the stream. The bytes come first from the look-ahead buffer, and if there are not enough bytes, they are loaded from the underlying channel. After every read operation it is tried to enlarge the window such that it contains at least one block.

If you want that the window becomes larger, you can call want (to enlarge the window to a certain size) or want_another_block (to load just another block from the underlying channel). Note that this affects only the current window and not the future size of the window.

Note Buffer_underrun: netstreams can cope with underruns of underlying channels. An underrun happens when it is not possible to ensure the minimum window size. However, it is possible that the window size sinks under the minimum, but the Buffer_underrun is deferred until the next call of an input method. Furthermore, there is a problem in the skip method which may only be partially executed, i.e. the method skips some bytes and then raises Buffer_underrun.


class type in_obj_stream = object .. end
An in_obj_stream extends in_obj_channel by look-ahead methods
class input_stream : ?len:int -> ?block_size:int -> Netchannels.in_obj_channel -> in_obj_stream
Make an in_obj_stream on top of an in_obj_channel.
class sub_stream : ?len:int -> ?delimiter:string -> in_obj_stream -> in_obj_stream
A sub stream is the part of the whole stream from the current position to an arbitrary other position that is determined by len and delimiter.
val print_in_obj_stream : Format.formatter -> in_obj_stream -> unit
A top-loop printer for streams
This web site is published by Informatikbüro Gerd Stolpmann
Powered by Caml