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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,deffccd74319c23d X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!newsfeed.stueberl.de!newsfeed.vmunix.org!peer-uk.news.demon.net!kibo.news.demon.net!news.demon.co.uk!demon!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Sending Variable Length Messages with GNAT.Sockets Date: Mon, 09 May 2005 20:16:18 +0100 Organization: Pushface Message-ID: References: <1115633512.107824.259680@g14g2000cwa.googlegroups.com> <427f3dfa$0$28058$ba620e4c@news.skynet.be> <1115637556.074009.113830@o13g2000cwo.googlegroups.com> <1115650283.330746.109740@f14g2000cwb.googlegroups.com> NNTP-Posting-Host: pogner.demon.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: news.demon.co.uk 1115666177 10672 62.49.19.209 (9 May 2005 19:16:17 GMT) X-Complaints-To: abuse@demon.net NNTP-Posting-Date: Mon, 9 May 2005 19:16:17 +0000 (UTC) Cancel-Lock: sha1:02Eb0pQ/AFrpxwMkvVR5vtl7anQ= User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (darwin) Xref: g2news1.google.com comp.lang.ada:10981 Date: 2005-05-09T20:16:18+01:00 List-Id: "markp" writes: > I still have a fundamental problem. I am working on legacy code in > which data is defined in records (or arrays of records) which are sent > in variable lengths. We use address, byte count to send the exact > number of bytes. Using Streams, it seems they type has to be of > Stream_element_Array. The only way I can see to send/receive these > "variable" messages is to first read our message header which contains > the number of bytes in the message. Then, create a Stream_Element_Array > of the exact size for the next read. Then, do an unchecked conversion > or a copy bytes routine to get the data into my data type for > processing. Does this sound correct? Sounds pretty good to me; though the compiler is going to complain about the unchecked conversion if your data type isn't the size specified in the header? Assuming you have type my_array_type is array (Natural range <>) of your record type, try something like read the number of bytes; compute the number of array elements; handle the error if it doesn't match exactly; declare Readable : my_array_type (1 .. number_of_array_elements); begin my_array_type'Read (str, Readable); return Readable; -- or something related end; > Lastly, using the 'Read function on streams, am I guaranteed to block > until I receive all bytes? I believe so (unless the other end closes, or you have a non-blocking socket, in which case I'd expect End_Error).