comp.lang.ada
 help / color / mirror / Atom feed
* Re: Implementing a stream
  1998-12-15  0:00 Implementing a stream dennison
@ 1998-12-15  0:00 ` Tucker Taft
  1998-12-15  0:00 ` David C. Hoos
  1 sibling, 0 replies; 3+ messages in thread
From: Tucker Taft @ 1998-12-15  0:00 UTC (permalink / raw)


dennison@telepath.com wrote:

: I'm looking at implementing a stream class, but I don't think I quite
: understand the expected interface. I know I have to implement the following
: subprogram:

:            procedure Read(
:              Stream : in out Root_Stream_Type;
:              Item   : out Stream_Element_Array;
:              Last   : out Stream_Element_Offset);

: But how is it called by default (iaw: from default 'Read and 'Input
: routines)? For instance, if my read returns with Last < Item'length, does
: read get repeatedly called until Item'length items have been read? 

In general, if Last /= Item'Last, then you will get an exception
raised by the default 'Read or 'Input implementation.  I doubt that
it would loop (I agree RM95 is a bit hazy in this section, but it is
numbered 13.13, remember ;-).

: ... Would
: returning Last =0 result in a fast busy-loop? 

No, it will almost certainly result in an exception being raised.

: ... If so, I'd think the preferred
: method in this instance would be for Read to raise an exception or to block
: until there is more data.

Yes, your Read should only return with Last < Item'Last if you have
reached end-of-stream (see 13.13.1(8)).

: --
: T.E.D.

--
-Tucker Taft   stt@averstar.com   http://www.averstar.com/~stt/
Technical Director, Intermetrics, Inc.  Burlington, MA  USA
An AverStar Company (www.averstar.com)




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Implementing a stream
  1998-12-15  0:00 Implementing a stream dennison
  1998-12-15  0:00 ` Tucker Taft
@ 1998-12-15  0:00 ` David C. Hoos
  1 sibling, 0 replies; 3+ messages in thread
From: David C. Hoos @ 1998-12-15  0:00 UTC (permalink / raw)



dennison@telepath.com wrote in message <7563nn$evn$1@nnrp1.dejanews.com>...
>I'm looking at implementing a stream class, but I don't think I quite
>understand the expected interface. I know I have to implement the following
>subprogram:
>
>           procedure Read(
>             Stream : in out Root_Stream_Type;
>             Item   : out Stream_Element_Array;
>             Last   : out Stream_Element_Offset);
>
What you implement is a subprogram shere the Stream Paramter is derived ftom
Root_Streams_Type.  The 'Read and 'Input calls dispatch on the type of the
Stream
paramter.
>
>But how is it called by default (iaw: from default 'Read and 'Input
>routines)? For instance, if my read returns with Last < Item'length, does
>read get repeatedly called until Item'length items have been read? Would
>returning Last =0 result in a fast busy-loop? If so, I'd think the
preferred
>method in this instance would be for Read to raise an exception or to block
>until there is more data.
>
This depends on the source of the stream.  For example, a memory stream
would not
block, but a socket might.  My thought is that if reading a socke, for
example,
one might well have Read block until Item is filled.  But, what do you do
when you
get EOF on the socket?  This is where you want to have Read return with Last
< Item'Last.

For an example of a stream which reads and/or writes to a region of process
memory
specified by address, see the file at my FTP site
ftp://ftp.ada95.com/tagged_types.tgz

David C. Hoos, Sr.







^ permalink raw reply	[flat|nested] 3+ messages in thread

* Implementing a stream
@ 1998-12-15  0:00 dennison
  1998-12-15  0:00 ` Tucker Taft
  1998-12-15  0:00 ` David C. Hoos
  0 siblings, 2 replies; 3+ messages in thread
From: dennison @ 1998-12-15  0:00 UTC (permalink / raw)


I'm looking at implementing a stream class, but I don't think I quite
understand the expected interface. I know I have to implement the following
subprogram:

           procedure Read(
             Stream : in out Root_Stream_Type;
             Item   : out Stream_Element_Array;
             Last   : out Stream_Element_Offset);


But how is it called by default (iaw: from default 'Read and 'Input
routines)? For instance, if my read returns with Last < Item'length, does
read get repeatedly called until Item'length items have been read? Would
returning Last =0 result in a fast busy-loop? If so, I'd think the preferred
method in this instance would be for Read to raise an exception or to block
until there is more data.

--
T.E.D.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1998-12-15  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-12-15  0:00 Implementing a stream dennison
1998-12-15  0:00 ` Tucker Taft
1998-12-15  0:00 ` David C. Hoos

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox