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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c58b7bd180ea81b2 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder2-2.proxad.net!news.osn.de!diablo2.news.osn.de!news.belwue.de!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Problems with Ada.Streams.Read (blocking) Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: Date: Fri, 8 Aug 2008 15:56:27 +0200 Message-ID: <1c7gwe0hi3ew5$.1c9zms1qkzjel.dlg@40tude.net> NNTP-Posting-Date: 08 Aug 2008 15:56:27 CEST NNTP-Posting-Host: 53735d8d.newsspool2.arcor-online.net X-Trace: DXC==\0]n1BXN0`>jlK2>IgHGdA9EHlD;3Ycb4Fo<]lROoRa4nDHegD_]Re16>Vgg1DG[dDNcfSJ;bb[eFCTGGVUmh?dLK[5LiR>kgb^9k1RVh8?_b X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:1549 Date: 2008-08-08T15:56:27+02:00 List-Id: On Fri, 08 Aug 2008 15:24:43 +0200, Dennis Hoppe wrote: > This approach works very well, but some ftp commands send a messages > over several lines. I do not know in advance, how many lines I should > read in. Subsequently, Ada.Streams.Read has to be called in a loop, > which will eventually block, again. > > How can I query the stream, if new elements are ready to read? You have to implement the application layer protocol above the stream. Stream is a flow of stream elements, nothing more. If you have a record-oriented layer above it, that segments the stream into records, then you define a procedure to receive one record according to the definition of. For instance, a sequence of stream elements until CR/LF: procedure Read_Record ( Channel : in out Socket_Type; Buffer : in out Stream_Element_Array; Last : out Stream_Element_Offset ) is -- Reads the stream until CR/LF filling Buffer. Last is the index of -- of the last element of the packet. It is Buffer'First - 1 when -- the record body is empty. Index : Stream_Element_Offset; Has_CR : Boolean := False; begin while Index in Buffer'Range loop Read (Channel, Buffer (Index)); if Has_CR and then Storage_Element'Pos (Buffer (Index) = Character'Pos (LF) then Last := Index - 2; return; else Has_CR := Storage_Element'Pos (Buffer (Index) = Character'Pos (CR); end if; end loop; raise Data_Overrun_Error; -- Too large packet end Read_Record; > How can I query the stream, if new elements are ready to read? You need not, because record-oriented protocols let you know either the record size in advance or else provide a way to determine the record end. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de