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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 2002:a24:5755:: with SMTP id u82mr5346115ita.16.1549524211057; Wed, 06 Feb 2019 23:23:31 -0800 (PST) X-Received: by 2002:a9d:654f:: with SMTP id q15mr113901otl.6.1549524210822; Wed, 06 Feb 2019 23:23:30 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!k10no104381itk.0!news-out.google.com!v71ni121ita.0!nntp.google.com!q69no104358itb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 6 Feb 2019 23:23:30 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=176.11.89.253; posting-account=uulyKwoAAAA86DO0ODu--rZtbje8Sytn NNTP-Posting-Host: 176.11.89.253 References: <47f17695-f9a5-4024-b2da-3f13209dc4fd@googlegroups.com> <818f5ff4-f18d-42b8-950d-9b597c012aa4@googlegroups.com> <62406dfb-54c9-4db3-b461-0ad72d4a782c@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Ada x Datagram Sockets From: Egil H H Injection-Date: Thu, 07 Feb 2019 07:23:31 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader01.eternal-september.org comp.lang.ada:55453 Date: 2019-02-06T23:23:30-08:00 List-Id: On Thursday, February 7, 2019 at 7:41:28 AM UTC+1, Rego, P. wrote: > On Thursday, February 7, 2019 at 4:00:11 AM UTC-2, Egil H H wrote: > > > > On Wednesday, February 6, 2019 at 6:10:37 PM UTC-5, Rego, P. wrote: > > >=20 > > > Just the string "test". I also confirmed that the MQL container (ucha= r data[]) has really the size 5. > > >=20 > >=20 > > Right, Ada strings are not zero-terminated, and the size of the string = needs=20 > > to come from somewhere, which is why String'Input will interpret the fi= rst x bits (probably 32, but may depend on your platform) as the length. So= in this > > case, "test" becomes a big number and 'Input will most likely try to al= locate > > just under 2GB on your stack (and probably at least twice, in order to= copy > > the result into your string). > A C++ uchar in Windows machine is usually 1 byte, so assuming that both u= se the same signature, both messages (from C++ and from Ada) should be of s= ame size, right?=20 >=20 The *message* may be of the same size, but that doesn't matter, as long as it's interpreted differently in C++ vs Ada. C++ apparently puts an extra character in your message (you said "test" was length 5...) Ada interprets your string (presumably the first 4 bytes, which is usually the size of Positive/Integer) as a very big number. > >=20 > > Don't use Ada stream attributes to communicate with other languages. > >=20 > > And, as some will tell you, don't use them at all, especially for array= s, as > > each array element may end up being transferred as a single data packet= , destroying performance. >=20 > This is quite controversial, in this case. I'd usually agree with you, ho= wever the use of Ada stream is not by choice. The whole GNAT Ada package us= es Ada streams, and actually the above code was entirely extracted from the= comments from g-sockets.ads with minimum modification. I don't think it wo= uld be wise to re-implement Ada Sockets pkg to be more efficient. How is it controversial? The example works fine when the server and client are both written in Ada, as they would then agree on the protocol. But when dealing with cross-language communication, you're better off using Send_Socket/Receive_Socket directly. No need to re-implement --=20 ~egilhh