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=-2.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Thread: 103376,f69eb259f3ed2afb X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news2.google.com!proxad.net!freenix!enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: Duncan Sands Newsgroups: comp.lang.ada Subject: Re: Using GNAT.Sockets Date: Wed, 13 Apr 2005 17:43:44 +0200 Organization: Cuivre, Argent, Or Message-ID: References: <1113404846.310840.322920@z14g2000cwz.googlegroups.com> NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Trace: melchior.cuivre.fr.eu.org 1113407030 66358 212.85.156.195 (13 Apr 2005 15:43:50 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Wed, 13 Apr 2005 15:43:50 +0000 (UTC) Cc: comp.lang.ada@ada-france.org To: markwork66@yahoo.com Return-Path: In-Reply-To: <1113404846.310840.322920@z14g2000cwz.googlegroups.com> X-Mailer: Evolution 2.2.1.1 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Gateway to the comp.lang.ada Usenet newsgroup" List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: g2news1.google.com comp.lang.ada:10426 Date: 2005-04-13T17:43:44+02:00 Hi markwork66, On Wed, 2005-04-13 at 08:07 -0700, markwork66@yahoo.com wrote: > We are just converting to GNAT and I am used to the traditional TCP > send/receive using an address and byte count to send/receive data. I've > used the Receive_Socket command in GNAT.Sockets and I am having trouble > receiving all the bytes. The "Last" parameter is not always equal to > the size of the message I'm sending and I don't see a way to call back > into the procedure to receive the rest of the bytes. there are two things you might be talking about here: (1) Item'Length is less then the size of your message, Last is equal to Item'Last. (2) Last is less than Item'Last, and less than the length of your message (or rather: Last - Item'First + 1 < your message length). In case (1), the operating system has transferred as much into your buffer Item as your buffer can hold. That's the way it should be. To get the rest of the data, call Receive_Socket again. Case (2) happens for Receive_Socket because it happens for the standard C socket routine recv. Receive_Socket is quite low level - it is just a wrapper around recv. recv can return less than the length of your message because either (A) the entire message has not yet arrived on your computer, or your buffer is longer than the socket buffer, (B) the OS feels like it, or (C) an error occurred. You've got to expect (A) - finite speed and finite buffers is a fact of life. As for (B), I'm not being facetious - the OS is allowed to return a "short read" even if it has more data. This is also the case with files by the way: even if you read less than the length of a file, the OS is allowed to nonetheless return less than you asked for. This is rare. As for (C), I guess that's not the problem here. I'm guessing that you would like a higher-level routine that automagically takes care of short reads for you. For that you can use the stream routines. > Further, we have many different sized messages and, from my little > playing with GNAT sockets, it seemed the "Item" parameter is the only > way to specify the number of bytes you want to receive. So, does that > mean I would have to declare an array of bytes (the "Item" parameter) > for all of my messages and the then do an unchecked conversion or a > copy_bytes routine to get the data into my Ada message data type? Probably here too you want the stream stuff. Ciao, Duncan.