comp.lang.ada
 help / color / mirror / Atom feed
* Finding the end of a stream from a socket
@ 2017-10-21  2:05 Andrew Shvets
  2017-10-21  8:44 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 11+ messages in thread
From: Andrew Shvets @ 2017-10-21  2:05 UTC (permalink / raw)


Hello,

I've been recently trying to make a small TCP server (a toy.)  I have a channel that reads Characters and was trying to find the end of the stream.  Reading the documentation, I came across the following in g-socket.ads:


type Stream_Access is access all Ada.Streams.Root_Stream_Type'Class; 
--  Same interface as Ada.Streams.Stream_IO


I was trying to have a way to find out when the last Character was read from the stream.  I could catch the Ada.IO_Exceptions.End_Error exception, but I'm wondering if there is a better way.


Channel       : GNAT.Sockets.Stream_Access;

....

while not Ada.Streams.Stream_IO.End_Of_File(Channel) loop
  Character'Read(Channel, Received_Char);
  Ada.Text_IO.Put(Received_Char);
end loop;





Many thank yous in advance for your help!


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Finding the end of a stream from a socket
  2017-10-21  2:05 Finding the end of a stream from a socket Andrew Shvets
@ 2017-10-21  8:44 ` Dmitry A. Kazakov
  2017-10-21 13:45   ` Andrew Shvets
  2017-10-21 17:34   ` Andrew Shvets
  0 siblings, 2 replies; 11+ messages in thread
From: Dmitry A. Kazakov @ 2017-10-21  8:44 UTC (permalink / raw)


On 2017-10-21 04:05, Andrew Shvets wrote:

> I've been recently trying to make a small TCP server (a toy.) I have
> a channel that reads Characters and was trying to find the end of
> the stream. Reading the documentation, I came across the following
> in  g-socket.ads:
> 
> type Stream_Access is access all Ada.Streams.Root_Stream_Type'Class;
> --  Same interface as Ada.Streams.Stream_IO
> 
> I was trying to have a way to find out when the last Character was 
> read from the stream. I could catch the Ada.IO_Exceptions.End_Error 
> exception, but I'm wondering if there is a better way.

End_Error is the best possible way, when applied. GNAT socket streams do 
not raise End_Error, AFAIK.

> while not Ada.Streams.Stream_IO.End_Of_File(Channel) loop
>    Character'Read(Channel, Received_Char);
>    Ada.Text_IO.Put(Received_Char);
> end loop;

This is a bad idea even when if it can work. In the case of sockets 
there is no file end. When the connection is closed by the peer the 
stream will stop both returning data and blocking. I suppose that will 
cause Constraint_Error in Character'Read.

In practice there is a higher level protocol on top of the socket 
stream, so that it is always known how many octets to read next.

Regarding your case, try this:

    Buffer : Stream_Element_Array (1..Buffer_Size);
    Last   : Stream_Element_Offset;
begin
    loop
       Receive_Socket (Socket, Buffer, Last);
       exit when Last < Buffer'First; -- Connection is closed by the peer
       for Octet in Buffer'First..Last loop -- Dump octets as-is
          Put (Character'Val (Buffer (Octet)));
       end loop;
    end loop;

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Finding the end of a stream from a socket
  2017-10-21  8:44 ` Dmitry A. Kazakov
@ 2017-10-21 13:45   ` Andrew Shvets
  2017-10-21 18:11     ` Dennis Lee Bieber
  2017-10-21 17:34   ` Andrew Shvets
  1 sibling, 1 reply; 11+ messages in thread
From: Andrew Shvets @ 2017-10-21 13:45 UTC (permalink / raw)


On Saturday, October 21, 2017 at 4:44:42 AM UTC-4, Dmitry A. Kazakov wrote:
> On 2017-10-21 04:05, Andrew Shvets wrote:
> 
> > I've been recently trying to make a small TCP server (a toy.) I have
> > a channel that reads Characters and was trying to find the end of
> > the stream. Reading the documentation, I came across the following
> > in  g-socket.ads:
> > 
> > type Stream_Access is access all Ada.Streams.Root_Stream_Type'Class;
> > --  Same interface as Ada.Streams.Stream_IO
> > 
> > I was trying to have a way to find out when the last Character was 
> > read from the stream. I could catch the Ada.IO_Exceptions.End_Error 
> > exception, but I'm wondering if there is a better way.
> 
> End_Error is the best possible way, when applied. GNAT socket streams do 
> not raise End_Error, AFAIK.
> 
> > while not Ada.Streams.Stream_IO.End_Of_File(Channel) loop
> >    Character'Read(Channel, Received_Char);
> >    Ada.Text_IO.Put(Received_Char);
> > end loop;
> 
> This is a bad idea even when if it can work. In the case of sockets 
> there is no file end. When the connection is closed by the peer the 
> stream will stop both returning data and blocking. I suppose that will 
> cause Constraint_Error in Character'Read.
> 
> In practice there is a higher level protocol on top of the socket 
> stream, so that it is always known how many octets to read next.
> 
> Regarding your case, try this:
> 
>     Buffer : Stream_Element_Array (1..Buffer_Size);
>     Last   : Stream_Element_Offset;
> begin
>     loop
>        Receive_Socket (Socket, Buffer, Last);
>        exit when Last < Buffer'First; -- Connection is closed by the peer
>        for Octet in Buffer'First..Last loop -- Dump octets as-is
>           Put (Character'Val (Buffer (Octet)));
>        end loop;
>     end loop;
> 
> -- 
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de

Thanks for your reply.  I did what you recommended.


  loop
    begin
      GNAT.Sockets.Receive_Socket(Receiver, Buffer, Last);

      -- the connection was reset by peer.
      exit when Last < Buffer'First;

      for Octet in Buffer'First .. Last loop
        Ada.Text_IO.Put(Character'Val(Buffer(Octet)));
      end loop;
    exception
      when Ada.IO_Exceptions.End_Error =>
        Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error, " ERROR: Issue encountered while receiving data from user.");
    end;
  end loop;


I get the following error when I make the Receive_Socket procedure call:

raised GNAT.SOCKETS.SOCKET_ERROR : [107] Transport endpoint is not connected


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Finding the end of a stream from a socket
  2017-10-21  8:44 ` Dmitry A. Kazakov
  2017-10-21 13:45   ` Andrew Shvets
@ 2017-10-21 17:34   ` Andrew Shvets
  2017-10-21 19:18     ` Andrew Shvets
  1 sibling, 1 reply; 11+ messages in thread
From: Andrew Shvets @ 2017-10-21 17:34 UTC (permalink / raw)


On Saturday, October 21, 2017 at 4:44:42 AM UTC-4, Dmitry A. Kazakov wrote:
> On 2017-10-21 04:05, Andrew Shvets wrote:
> 
> > I've been recently trying to make a small TCP server (a toy.) I have
> > a channel that reads Characters and was trying to find the end of
> > the stream. Reading the documentation, I came across the following
> > in  g-socket.ads:
> > 
> > type Stream_Access is access all Ada.Streams.Root_Stream_Type'Class;
> > --  Same interface as Ada.Streams.Stream_IO
> > 
> > I was trying to have a way to find out when the last Character was 
> > read from the stream. I could catch the Ada.IO_Exceptions.End_Error 
> > exception, but I'm wondering if there is a better way.
> 
> End_Error is the best possible way, when applied. GNAT socket streams do 
> not raise End_Error, AFAIK.
> 
> > while not Ada.Streams.Stream_IO.End_Of_File(Channel) loop
> >    Character'Read(Channel, Received_Char);
> >    Ada.Text_IO.Put(Received_Char);
> > end loop;
> 
> This is a bad idea even when if it can work. In the case of sockets 
> there is no file end. When the connection is closed by the peer the 
> stream will stop both returning data and blocking. I suppose that will 
> cause Constraint_Error in Character'Read.
> 
> In practice there is a higher level protocol on top of the socket 
> stream, so that it is always known how many octets to read next.
> 
> Regarding your case, try this:
> 
>     Buffer : Stream_Element_Array (1..Buffer_Size);
>     Last   : Stream_Element_Offset;
> begin
>     loop
>        Receive_Socket (Socket, Buffer, Last);
>        exit when Last < Buffer'First; -- Connection is closed by the peer
>        for Octet in Buffer'First..Last loop -- Dump octets as-is
>           Put (Character'Val (Buffer (Octet)));
>        end loop;
>     end loop;
> 
> -- 
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de

Hi Dmitry,

This is my entire code.
https://gist.github.com/anonymous/b7c3a5bdcd8c78453a643b6785573131


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Finding the end of a stream from a socket
  2017-10-21 13:45   ` Andrew Shvets
@ 2017-10-21 18:11     ` Dennis Lee Bieber
  2017-10-21 19:19       ` Dmitry A. Kazakov
  0 siblings, 1 reply; 11+ messages in thread
From: Dennis Lee Bieber @ 2017-10-21 18:11 UTC (permalink / raw)


On Sat, 21 Oct 2017 06:45:22 -0700 (PDT), Andrew Shvets
<andrew.shvets@gmail.com> declaimed the following:


>
>
>  loop
>    begin
>      GNAT.Sockets.Receive_Socket(Receiver, Buffer, Last);
>
>      -- the connection was reset by peer.
>      exit when Last < Buffer'First;
>
>      for Octet in Buffer'First .. Last loop
>        Ada.Text_IO.Put(Character'Val(Buffer(Octet)));
>      end loop;
>    exception
>      when Ada.IO_Exceptions.End_Error =>
>        Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error, " ERROR: Issue encountered while receiving data from user.");
>    end;
>  end loop;
>
>
>I get the following error when I make the Receive_Socket procedure call:
>
>raised GNAT.SOCKETS.SOCKET_ERROR : [107] Transport endpoint is not connected


>  GNAT.Sockets.Bind_Socket(Receiver, (GNAT.Sockets.Family_Inet, GNAT.Sockets.Inet_Addr("127.0.0.1"), 50000));
>  GNAT.Sockets.Listen_Socket(Receiver);
>
	From those statements I'm guessing you are trying to set this program
up as a server, and have some other program which will connect to send data
to this one.


>  Ada.Text_IO.Put_Line(" !! TCP Server started !!");
>
>  loop
>    Ada.Text_IO.Put_Line(" FOO 1");
>    GNAT.Sockets.Connect_Socket(Receiver,  Client_Addr);

	But here you are saying /this/ program is going to connect to a server
at (undefined) Client_Addr.

	I suspect you really need to be using g.s.Accept_Socket() instead.

-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Finding the end of a stream from a socket
  2017-10-21 17:34   ` Andrew Shvets
@ 2017-10-21 19:18     ` Andrew Shvets
  0 siblings, 0 replies; 11+ messages in thread
From: Andrew Shvets @ 2017-10-21 19:18 UTC (permalink / raw)


On Saturday, October 21, 2017 at 1:34:15 PM UTC-4, Andrew Shvets wrote:
> On Saturday, October 21, 2017 at 4:44:42 AM UTC-4, Dmitry A. Kazakov wrote:
> > On 2017-10-21 04:05, Andrew Shvets wrote:
> > 
> > > I've been recently trying to make a small TCP server (a toy.) I have
> > > a channel that reads Characters and was trying to find the end of
> > > the stream. Reading the documentation, I came across the following
> > > in  g-socket.ads:
> > > 
> > > type Stream_Access is access all Ada.Streams.Root_Stream_Type'Class;
> > > --  Same interface as Ada.Streams.Stream_IO
> > > 
> > > I was trying to have a way to find out when the last Character was 
> > > read from the stream. I could catch the Ada.IO_Exceptions.End_Error 
> > > exception, but I'm wondering if there is a better way.
> > 
> > End_Error is the best possible way, when applied. GNAT socket streams do 
> > not raise End_Error, AFAIK.
> > 
> > > while not Ada.Streams.Stream_IO.End_Of_File(Channel) loop
> > >    Character'Read(Channel, Received_Char);
> > >    Ada.Text_IO.Put(Received_Char);
> > > end loop;
> > 
> > This is a bad idea even when if it can work. In the case of sockets 
> > there is no file end. When the connection is closed by the peer the 
> > stream will stop both returning data and blocking. I suppose that will 
> > cause Constraint_Error in Character'Read.
> > 
> > In practice there is a higher level protocol on top of the socket 
> > stream, so that it is always known how many octets to read next.
> > 
> > Regarding your case, try this:
> > 
> >     Buffer : Stream_Element_Array (1..Buffer_Size);
> >     Last   : Stream_Element_Offset;
> > begin
> >     loop
> >        Receive_Socket (Socket, Buffer, Last);
> >        exit when Last < Buffer'First; -- Connection is closed by the peer
> >        for Octet in Buffer'First..Last loop -- Dump octets as-is
> >           Put (Character'Val (Buffer (Octet)));
> >        end loop;
> >     end loop;
> > 
> > -- 
> > Regards,
> > Dmitry A. Kazakov
> > http://www.dmitry-kazakov.de
> 
> Hi Dmitry,
> 
> This is my entire code.
> https://gist.github.com/anonymous/b7c3a5bdcd8c78453a643b6785573131

On this line:
GNAT.Sockets.Connect_Socket(Receiver,  Client_Addr);


I get the following exception:
!! TCP Server started !!
FOO 1

raised GNAT.SOCKETS.SOCKET_ERROR :[10022] Unknown system error


Weird, I thought, then I uncommented the Connect_Socket procedure call, since the socket is already being used to listen, it should be "connected".  When I did this, I got this error:

https://gist.github.com/anonymous/b79594f71309df87fc8fcc44bd6a28ee

What gets me, what is trying to connect from 0.0.0.0:0?  I have never seen or heard of this address being used.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Finding the end of a stream from a socket
  2017-10-21 18:11     ` Dennis Lee Bieber
@ 2017-10-21 19:19       ` Dmitry A. Kazakov
  2017-10-21 19:46         ` Andrew Shvets
  2017-10-22 12:26         ` Andrew Shvets
  0 siblings, 2 replies; 11+ messages in thread
From: Dmitry A. Kazakov @ 2017-10-21 19:19 UTC (permalink / raw)


On 2017-10-21 20:11, Dennis Lee Bieber wrote:
> On Sat, 21 Oct 2017 06:45:22 -0700 (PDT), Andrew Shvets
> <andrew.shvets@gmail.com> declaimed the following:
> 
>>   GNAT.Sockets.Bind_Socket(Receiver, (GNAT.Sockets.Family_Inet, GNAT.Sockets.Inet_Addr("127.0.0.1"), 50000));
>>   GNAT.Sockets.Listen_Socket(Receiver);
>>
> 	From those statements I'm guessing you are trying to set this program
> up as a server, and have some other program which will connect to send data
> to this one.
> 
>>   Ada.Text_IO.Put_Line(" !! TCP Server started !!");
>>
>>   loop
>>     Ada.Text_IO.Put_Line(" FOO 1");
>>     GNAT.Sockets.Connect_Socket(Receiver,  Client_Addr);
> 
> 	But here you are saying /this/ program is going to connect to a server
> at (undefined) Client_Addr.
> 
> 	I suspect you really need to be using g.s.Accept_Socket() instead.

Also note that Accept_Socket will return another socket. This one you 
should use for communication.

A typical scenario for blocking sockets:

    loop -- Connection listening
       Accept_Socket -- Get communication socket
       Start a new session task with the communication socket
    end loop;

The session task deals with the connection using the socket returned by 
Accept_Socket. Once the session is complete it closes that socket and 
terminates.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Finding the end of a stream from a socket
  2017-10-21 19:19       ` Dmitry A. Kazakov
@ 2017-10-21 19:46         ` Andrew Shvets
  2017-10-22 12:26         ` Andrew Shvets
  1 sibling, 0 replies; 11+ messages in thread
From: Andrew Shvets @ 2017-10-21 19:46 UTC (permalink / raw)


On Saturday, October 21, 2017 at 3:19:36 PM UTC-4, Dmitry A. Kazakov wrote:
> On 2017-10-21 20:11, Dennis Lee Bieber wrote:
> > On Sat, 21 Oct 2017 06:45:22 -0700 (PDT), Andrew Shvets
> > <and.....@gmail.com> declaimed the following:
> > 
> >>   GNAT.Sockets.Bind_Socket(Receiver, (GNAT.Sockets.Family_Inet, GNAT.Sockets.Inet_Addr("127.0.0.1"), 50000));
> >>   GNAT.Sockets.Listen_Socket(Receiver);
> >>
> > 	From those statements I'm guessing you are trying to set this program
> > up as a server, and have some other program which will connect to send data
> > to this one.
> > 
> >>   Ada.Text_IO.Put_Line(" !! TCP Server started !!");
> >>
> >>   loop
> >>     Ada.Text_IO.Put_Line(" FOO 1");
> >>     GNAT.Sockets.Connect_Socket(Receiver,  Client_Addr);
> > 
> > 	But here you are saying /this/ program is going to connect to a server
> > at (undefined) Client_Addr.
> > 
> > 	I suspect you really need to be using g.s.Accept_Socket() instead.
> 
> Also note that Accept_Socket will return another socket. This one you 
> should use for communication.
> 
> A typical scenario for blocking sockets:
> 
>     loop -- Connection listening
>        Accept_Socket -- Get communication socket
>        Start a new session task with the communication socket
>     end loop;
> 
> The session task deals with the connection using the socket returned by 
> Accept_Socket. Once the session is complete it closes that socket and 
> terminates.
> 
> -- 
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de


Weird, I can't see Dennis' reply in this thread, but I see it in Dmitry's reply.


Anyway, thank you both for your help.  With your help, I figured out what my problem is and my example is working now.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Finding the end of a stream from a socket
  2017-10-21 19:19       ` Dmitry A. Kazakov
  2017-10-21 19:46         ` Andrew Shvets
@ 2017-10-22 12:26         ` Andrew Shvets
  2017-10-22 12:28           ` Andrew Shvets
  2017-10-22 13:28           ` Dmitry A. Kazakov
  1 sibling, 2 replies; 11+ messages in thread
From: Andrew Shvets @ 2017-10-22 12:26 UTC (permalink / raw)


On Saturday, October 21, 2017 at 3:19:36 PM UTC-4, Dmitry A. Kazakov wrote:
> On 2017-10-21 20:11, Dennis Lee Bieber wrote:
> > On Sat, 21 Oct 2017 06:45:22 -0700 (PDT), Andrew Shvets
> > <andr.....@gmail.com> declaimed the following:
> > 
> >>   GNAT.Sockets.Bind_Socket(Receiver, (GNAT.Sockets.Family_Inet, GNAT.Sockets.Inet_Addr("127.0.0.1"), 50000));
> >>   GNAT.Sockets.Listen_Socket(Receiver);
> >>
> > 	From those statements I'm guessing you are trying to set this program
> > up as a server, and have some other program which will connect to send data
> > to this one.
> > 
> >>   Ada.Text_IO.Put_Line(" !! TCP Server started !!");
> >>
> >>   loop
> >>     Ada.Text_IO.Put_Line(" FOO 1");
> >>     GNAT.Sockets.Connect_Socket(Receiver,  Client_Addr);
> > 
> > 	But here you are saying /this/ program is going to connect to a server
> > at (undefined) Client_Addr.
> > 
> > 	I suspect you really need to be using g.s.Accept_Socket() instead.
> 
> Also note that Accept_Socket will return another socket. This one you 
> should use for communication.
> 
> A typical scenario for blocking sockets:
> 
>     loop -- Connection listening
>        Accept_Socket -- Get communication socket
>        Start a new session task with the communication socket
>     end loop;
> 
> The session task deals with the connection using the socket returned by 
> Accept_Socket. Once the session is complete it closes that socket and 
> terminates.
> 
> -- 
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de

One more question.  How do I convert a string to a Stream_Element?


This is what I have:

  Out_String : constant String := "I like cake!";
  Out_Data : Ada.Streams.Stream_Element_Array(1 .. 12);
begin
...
  for elem in 1 .. Out_Data'Length loop
    Out_Data(Ada.Streams.Stream_Element_Offset(elem)) :=
      Ada.Streams.Stream_Element(Character'Val(Out_String(elem)));
  end loop;


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Finding the end of a stream from a socket
  2017-10-22 12:26         ` Andrew Shvets
@ 2017-10-22 12:28           ` Andrew Shvets
  2017-10-22 13:28           ` Dmitry A. Kazakov
  1 sibling, 0 replies; 11+ messages in thread
From: Andrew Shvets @ 2017-10-22 12:28 UTC (permalink / raw)


On Sunday, October 22, 2017 at 8:26:54 AM UTC-4, Andrew Shvets wrote:
> On Saturday, October 21, 2017 at 3:19:36 PM UTC-4, Dmitry A. Kazakov wrote:
> > On 2017-10-21 20:11, Dennis Lee Bieber wrote:
> > > On Sat, 21 Oct 2017 06:45:22 -0700 (PDT), Andrew Shvets
> > > <andr.....@gmail.com> declaimed the following:
> > > 
> > >>   GNAT.Sockets.Bind_Socket(Receiver, (GNAT.Sockets.Family_Inet, GNAT.Sockets.Inet_Addr("127.0.0.1"), 50000));
> > >>   GNAT.Sockets.Listen_Socket(Receiver);
> > >>
> > > 	From those statements I'm guessing you are trying to set this program
> > > up as a server, and have some other program which will connect to send data
> > > to this one.
> > > 
> > >>   Ada.Text_IO.Put_Line(" !! TCP Server started !!");
> > >>
> > >>   loop
> > >>     Ada.Text_IO.Put_Line(" FOO 1");
> > >>     GNAT.Sockets.Connect_Socket(Receiver,  Client_Addr);
> > > 
> > > 	But here you are saying /this/ program is going to connect to a server
> > > at (undefined) Client_Addr.
> > > 
> > > 	I suspect you really need to be using g.s.Accept_Socket() instead.
> > 
> > Also note that Accept_Socket will return another socket. This one you 
> > should use for communication.
> > 
> > A typical scenario for blocking sockets:
> > 
> >     loop -- Connection listening
> >        Accept_Socket -- Get communication socket
> >        Start a new session task with the communication socket
> >     end loop;
> > 
> > The session task deals with the connection using the socket returned by 
> > Accept_Socket. Once the session is complete it closes that socket and 
> > terminates.
> > 
> > -- 
> > Regards,
> > Dmitry A. Kazakov
> > http://www.dmitry-kazakov.de
> 
> One more question.  How do I convert a string to a Stream_Element?
> 
> 
> This is what I have:
> 
>   Out_String : constant String := "I like cake!";
>   Out_Data : Ada.Streams.Stream_Element_Array(1 .. 12);
> begin
> ...
>   for elem in 1 .. Out_Data'Length loop
>     Out_Data(Ada.Streams.Stream_Element_Offset(elem)) :=
>       Ada.Streams.Stream_Element(Character'Val(Out_String(elem)));
>   end loop;

I want to write this out to a receiver?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Finding the end of a stream from a socket
  2017-10-22 12:26         ` Andrew Shvets
  2017-10-22 12:28           ` Andrew Shvets
@ 2017-10-22 13:28           ` Dmitry A. Kazakov
  1 sibling, 0 replies; 11+ messages in thread
From: Dmitry A. Kazakov @ 2017-10-22 13:28 UTC (permalink / raw)


On 2017-10-22 14:26, Andrew Shvets wrote:

> One more question.  How do I convert a string to a Stream_Element?
> 
> This is what I have:
> 
>    Out_String : constant String := "I like cake!";
>    Out_Data : Ada.Streams.Stream_Element_Array(1 .. 12);
> begin
> ...
>    for elem in 1 .. Out_Data'Length loop
>      Out_Data(Ada.Streams.Stream_Element_Offset(elem)) :=
>        Ada.Streams.Stream_Element(Character'Val(Out_String(elem)));
>    end loop;

    Out_String : constant String := ...;
    Out_Data   : constant Stream_Element_Array (1..Out_String'Length);
begin
    for Octet in Out_Data'Range loop
       Out_Data (Octet) :=
          Character'Pos (Out_String (Integer(Octet-1)+Out_String'First));
    end loop;


-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2017-10-22 13:28 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-21  2:05 Finding the end of a stream from a socket Andrew Shvets
2017-10-21  8:44 ` Dmitry A. Kazakov
2017-10-21 13:45   ` Andrew Shvets
2017-10-21 18:11     ` Dennis Lee Bieber
2017-10-21 19:19       ` Dmitry A. Kazakov
2017-10-21 19:46         ` Andrew Shvets
2017-10-22 12:26         ` Andrew Shvets
2017-10-22 12:28           ` Andrew Shvets
2017-10-22 13:28           ` Dmitry A. Kazakov
2017-10-21 17:34   ` Andrew Shvets
2017-10-21 19:18     ` Andrew Shvets

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