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-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!news.glorb.com!multikabel.net!newsfeed20.multikabel.net!eweka.nl!lightspeed.eweka.nl!82.197.223.106.MISMATCH!feeder1.cambriumusenet.nl!feed.tweaknews.nl!193.141.40.65.MISMATCH!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Howto read line from a stream 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: <83317a97-dae5-4c84-a1ac-88a87833cf3f@q14g2000vbn.googlegroups.com> Date: Sun, 31 May 2009 13:34:27 +0200 Message-ID: NNTP-Posting-Date: 31 May 2009 13:34:28 CEST NNTP-Posting-Host: 9326f2bc.newsspool2.arcor-online.net X-Trace: DXC=cE0NASM7dh>nBOkdL^Lo7>A9EHlD;3Yc24Fo<]lROoR1^YC2XCjHcb9PE31VF^PL]2DNcfSJ;bb[5IRnRBaCdM>KEJLQ]Q13m;Z:VE18g37 X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:6132 Date: 2009-05-31T13:34:28+02:00 List-Id: On Sun, 31 May 2009 03:41:46 -0700 (PDT), Tomek Walkuski wrote: > I have a stream, which is defined as: > Channel : Stream_Access; > > This stream is associated with a socket. If I knew how long is input > message I could do: > Msg : String (1 .. Known_Length); > String'Read (Channel, Msg); One potential problem with using Streams as an interface to sockets is that there is nothing in the Ada standard that mandates Stream_Element to be an octet of bits, as socket I/O demands. > Is there any smart solution? If you know the size of packets you can read it as a whole. Typically protocols deploy some headers determining the length of a packet body. The header is usually read octet by octet, and the rest in bigger chunks. However, String'Read is not necessarily mapped into one single socket's read. Quite possible is that it will be split into separate Character'Read implemented by independent reads. (I assume that you are using TCP/IP rather than UDP) > Or should I read character by character > from a stream until I get CR & LF ? No. There is no any CR's or LF's in the stream unless the protocol defines them as a part of the content. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de