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,19b0bf5b6906d2e7 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!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: Using GNAT.Sockets with Streams and Byte Swapping Date: Thu, 26 May 2005 07:00:08 +0100 Organization: Pushface Message-ID: References: <1117014486.871500.288200@g44g2000cwa.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 1117087213 22049 62.49.19.209 (26 May 2005 06:00:13 GMT) X-Complaints-To: abuse@demon.net NNTP-Posting-Date: Thu, 26 May 2005 06:00:13 +0000 (UTC) Cancel-Lock: sha1:I5uDpWP2NBo7NWpr4V2aNYj590s= User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (darwin) Xref: g2news1.google.com comp.lang.ada:11157 Date: 2005-05-26T07:00:08+01:00 List-Id: "markp" writes: > I am having a problem using GNAT.socket with streams. I can create a > stream easily and send data as follows: > > Msg_Type'Write( > My_Stream_Access, > Msg); > > This will work fine of both machines are the same "endian". However, if > I need to swap bytes on the variable Msg before I send, I get garbled > data on the other end. > > Is there a problem with swapping bytes before the call to 'Write? Not as far as I know. Though it's a much better idea to swap bytes _in_ 'Write (and 'Read). You can write your own 'Read, 'Write attribute subprograms. Or, you can rebuild the runtime on both sides using an XDR version of System.Stream_Attributes (s-stratt.adb). In recent (supported) GNATs and in GCC 3.4, 4.0 this has been supplied in s-strxdr.adb (so copy s-strxdr.adb to s-stratt.adb and rebuild -- see Makefile.adalib in your .../adalib directory under the GCC runtime, though Some Assembly Will [probably] Be Required). If you are on a PowerPC the only difference between doing this and doing nothing on the PPC (running natively big-endian -- who does otherwise?) is that natively Wide_Character is 2 bytes, while the XDR form is 4 bytes. There is a problem with s-strxdr.adb, it raises the wrong exception (an internal Data_Error rather than the standed End_Error, ISTR). What we ended up doing was using the native PPC s-stratt.adb and writing our own on the x86 side to match what the PPC was doing (easier to argue the acceptability of a vendor-supplied runtime, and our delivery platform is the PPC!)