From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,316584e171254ed6,start X-Google-Attributes: gid103376,public From: mheaney@ni.net (Matthew Heaney) Subject: How to implement I/O using Streams Date: 1997/04/01 Message-ID: #1/1 X-Deja-AN: 230041792 Organization: Estormza Software Newsgroups: comp.lang.ada Date: 1997-04-01T00:00:00+00:00 List-Id: The package Ada.Streams.Stream_IO is example of using a stream to do (heterogeneous) file I/O. I want to do network I/O - using BSD Sockets, say - and use a streams interface to do it. How do I do this? The example in RM95 shows how a file object gives the client a pointer to a stream (through which the I/O is performed), but is silent about how the stream and file connect to each other. How does the stream know about the file? If I have a socket descriptor, how can I use a stream to do the I/O over the socket? How do I implement the Read and Write operations of my type that derives from Root_Stream? declare sd : int; -- or perhaps I'll use a higher-level abstraction The_Stream : Stream_Access; The_Data : My_Record; begin The_Stream := ; -- ??? My_Record'Write (The_Stream, The_Data); -- more or less done for me end; Does anyone know how the implement that middle line? Has anyone implemented a streams interface, ie used something other than Ada.Streams.Stream_IO or Ada.Text_IO.Text_Streams? Here's a trial attempt: type My_Stream (sd : access int) is new Root_Stream_Type with null record; procedure Read (Stream ...); -- reads from the socket descriptor discriminent procedure Write (Stream ...); -- writes to the socket descriptor discriminent Suppose I built a higher-level abstraction. Would this work: type Socket_File is limited private; type Stream_Access is access all Root_Stream_Type'Class; function Stream (File : Socket_File) return Stream_Access; ... private type My_Stream (File : access Socket_File) is new Root_Stream_Type with null record; type Socket_File is limited record sd : int; Stream : aliased My_Stream (Socket_File'Access); end record; procedure Read (Stream : in out My_Stream...); procedure Write (Stream : in out My_Stream ...); end; Well, is that the way? Is that how the language designers intended a stream to be implemented? Thank you much! Matt -------------------------------------------------------------------- Matthew Heaney Software Development Consultant (818) 985-1271