comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Howto read line from a stream
Date: Sun, 31 May 2009 13:34:27 +0200
Date: 2009-05-31T13:34:28+02:00	[thread overview]
Message-ID: <eowbd5dz12if$.162w78yx0gq5r.dlg@40tude.net> (raw)
In-Reply-To: 83317a97-dae5-4c84-a1ac-88a87833cf3f@q14g2000vbn.googlegroups.com

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



  parent reply	other threads:[~2009-05-31 11:34 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-31 10:41 Howto read line from a stream Tomek Walkuski
2009-05-31 11:29 ` Tomek Wałkuski
2009-05-31 12:02   ` Dmitry A. Kazakov
2009-05-31 12:56     ` Tomek Wałkuski
2009-05-31 14:30       ` Tomek Wałkuski
2009-05-31 15:13       ` Dmitry A. Kazakov
2009-06-01 23:30         ` Randy Brukardt
2009-06-02  7:30           ` Dmitry A. Kazakov
2009-06-02  9:36             ` Georg Bauhaus
2009-06-02 10:24               ` Dmitry A. Kazakov
2009-06-02 21:15             ` Randy Brukardt
2009-06-01  6:34     ` Pascal Obry
2009-06-01  0:05   ` Jeffrey R. Carter
2009-06-03 15:49     ` Tomek Wałkuski
2009-06-03 18:04       ` Jeffrey R. Carter
2009-06-03 21:41         ` Maciej Sobczak
2009-06-04  8:56           ` Jean-Pierre Rosen
2009-06-04  9:05             ` Ludovic Brenta
2009-06-04 13:05             ` Maciej Sobczak
2009-06-04 14:16               ` Jean-Pierre Rosen
2009-06-04 19:48                 ` Ludovic Brenta
2009-06-04 14:24               ` Dmitry A. Kazakov
2009-06-03 19:07       ` sjw
2009-06-03 19:26         ` Dmitry A. Kazakov
2009-06-03 19:43           ` Georg Bauhaus
2009-06-03 20:11             ` Dmitry A. Kazakov
2009-06-03 22:09               ` Georg Bauhaus
2009-06-04  8:19                 ` Dmitry A. Kazakov
2009-06-04  9:41                   ` Georg Bauhaus
2009-06-04 10:23                     ` Dmitry A. Kazakov
2009-06-04 12:14                       ` Georg Bauhaus
2009-06-04 14:54                         ` Dmitry A. Kazakov
2009-06-04 16:33                           ` Georg Bauhaus
2009-06-05  9:57                             ` Dmitry A. Kazakov
2009-06-04 14:16         ` andrew
2009-06-01 19:12   ` björn lundin
2009-05-31 11:34 ` Dmitry A. Kazakov [this message]
2009-05-31 15:38   ` sjw
2009-05-31 16:07     ` Dmitry A. Kazakov
2009-05-31 20:39       ` Niklas Holsti
2009-05-31 22:00       ` sjw
2009-06-01  8:35         ` Dmitry A. Kazakov
2009-06-01 23:34     ` Randy Brukardt
2009-06-02  2:27 ` anon
replies disabled

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