comp.lang.ada
 help / color / mirror / Atom feed
From: "Ken Garlington" <Ken.Garlington@computer.org>
Subject: Re: Get_Line vs Adasockets
Date: 2000/08/14
Date: 2000-08-14T00:00:00+00:00	[thread overview]
Message-ID: <ZXKl5.3050$ic.175523@news.flash.net> (raw)
In-Reply-To: 8n6cbc$9ge$1@news.tpi.pl

"Ultor" <ultor@hert.org> wrote in message news:8n6cbc$9ge$1@news.tpi.pl...
> Hello
>
> I'm new in ADA (code since Friday). I got a problem with Get_Line in my
> source. I tried to make it working over 2 hours and still got a problem
with
> that.
>
> When i did Get_Line like this
>
>    BUF := Get_Line(Incoming_Socket);
>
> then I had problem with CONSTRAINT_ERROR.

Assuming that you expect the client to send a string terminated with
<CR><LF>, as opposed to a fixed-length message with no specific terminator
(which are both possible with socket programming), you've probably got the
right general idea in using Get_Line. However, you've come across an
important difference between C and Ada. In C, you would do a read like this:

   read(incoming_socket, buf, sizeof(buf));

where "buf" is the buffer you've allocated, and sizeof(buf) is the maximum
size of the string you'll accept. You have to pass the size of the buffer
separately, since in C the size of an array is not intrinsically available
to the called program. To find out the length of the string that was
actually passed, you would do something like

   current_string_length = strlen(buf)

which would determine the size of the string based on where the null
terminator is located.

 The equivalent in Ada is

   Get_Line(incoming_socket, buf, current_string_length);

Here, you don't have to pass buf'size as an *input* to get_line, since
that's automatically available to Get_Line just by making buf a parameter.
On the other hand, Ada strings are not null-terminated, so you need an
*output* value that says how many characters were actually read (<= 500).
That's why you're getting the error: the third parameter of Get_Line in this
case is "Last : out Natural"... it looks like you're trying to use it as an
*in* parameter.

> procedure testsock is ...
>   BUF              : String (1..500);
     Current_String_Length : Natural;

> begin...
>   loop...
         Get_Line(Incoming_Socket, Buf, Current_String_Length);
         if BUF(1..Current_String_Length)="QUIT" ...






  parent reply	other threads:[~2000-08-14  0:00 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-08-13  0:00 Get_Line vs Adasockets Ultor
2000-08-13  0:00 ` Dale Stanbrough
2000-08-14  0:00   ` Martin Dowie
2000-08-17  0:00     ` tmoran
2000-08-21  0:00       ` Martin Dowie
2000-08-14  0:00 ` Ken Garlington [this message]
2000-08-14  0:00   ` Ultor
2000-08-14  0:00     ` Ted Dennison
2000-08-14  0:00       ` Michal Zalewski
2000-08-14  0:00         ` Ted Dennison
2000-08-21  1:44   ` David Thompson
2000-08-14  0:00 ` Anders Gidenstam
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox