From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-65-14.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-0.9 required=3.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 Path: eternal-september.org!reader01.eternal-september.org!aioe.org!sVKkdTGubB6QhuTA1Vyf1Q.user.46.165.242.75.POSTED!not-for-mail From: Mark Gardner Newsgroups: comp.lang.ada Subject: Re: Sockets, Streams, and Element_Arrays: Much confusion Date: Sat, 31 Dec 2022 21:36:40 +0200 Organization: Aioe.org NNTP Server Message-ID: <6183be57-2796-0ab7-739f-a5b557083ee6@gmail.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: gioia.aioe.org; logging-data="47698"; posting-host="sVKkdTGubB6QhuTA1Vyf1Q.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org"; User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Content-Language: en-GB X-Notice: Filtered by postfilter v. 0.9.2 Xref: reader01.eternal-september.org comp.lang.ada:64754 List-Id: On 31/12/2022 19:39, Simon Wright wrote: > [...] > > The approach we adopted was to create a 'memory stream', which is a > chunk of memory that you can treat as a stream (see for example > ColdFrame.Memory_Streams at [1]). With Ada2022, you should be able to > use Ada.Streams.Storage.Bounded[2]. > Wait, so if I know what shape my data is, and use a memory_stream (like the one in the Big Online Book of Linux Ada Programming chapter 11 [1]), I'm fine using Stream, in conjunction with Get_Address? That's wonderful. Not at all frustrated that I just wasted approximately three working days looking for a solution to a problem that didn't exist. > Message'Write the record into the memory stream; > transmit the written contents as one datagram. I'm guessing with Memory_Stream'Write(Socket_Stream, Buffer);? > > To read, create a memory stream large enough for the message you expect; > read a datagram into the memory stream; > Message'Read (Stream => the_memory_stream, Item => a_message); Does this second buffer need to be added? If the datagram arrives (UDP), shouldn't GNAT.Sockets.Stream() be able to handle it? > > You can use gnatbind's switch -xdr to "Use the target-independent XDR > protocol for stream oriented attributes instead of the default > implementation which is based on direct binary representations and is > therefore target-and endianness-dependent". Oh fun, I didn't think of that aspect. Thanks! Would I have to pass it as a command line flag, or would there be some kind of pragma I could use? Thanks for the help so far, and happy new year! [1] http://www.pegasoft.ca/resources/boblap/11.html#11.12