comp.lang.ada
 help / color / mirror / Atom feed
From: Dennis Hoppe <dennis.hoppe@hoppinet.de>
Subject: Re: Problems with Ada.Streams.Read (blocking)
Date: Fri, 08 Aug 2008 20:08:43 +0200
Date: 2008-08-08T20:08:43+02:00	[thread overview]
Message-ID: <g7i23c$hs$1@aioe.org> (raw)
In-Reply-To: 103f4912-d96b-4c11-b9b2-d7a6d6ffcff3@i24g2000prf.googlegroups.com

Hi Adam,


Adam Beneschan wrote:
> I'm not familiar with GNAT.Sockets, but looking at the spec it appears
> that there are a couple routines that might help: Control_Socket which
> lets you specify non-blocking I/O, and Check_Selector which I think
> can be used to query whether data is available, if you give it a
> Timeout of zero.  Anyway, I haven't tried anything and I have no idea
> whether it's appropriate for your problem, but it seems like it might
> help.  If not, my apologies.
> 
>                                   -- Adam


I tried to implement your idea:

with Ada.Text_IO;
with Ada.Streams; use Ada.Streams;
with GNAT.Sockets; use GNAT.Sockets;
use type Ada.Streams.Stream_Element_Count;

procedure Test is
    Client: Socket_Type;
    Address: Sock_Addr_Type;
    Channel: Stream_Access;
    Data   : Ada.Streams.Stream_Element_Array (1 .. 256);
    Offset : Ada.Streams.Stream_Element_Count := 1;
    Request : Request_Type;

begin
    Initialize;
    Create_Socket(Client);
    Address.Addr := Inet_Addr("127.0.0.1");
    Address.Port := 21;
    Connect_Socket (Client, Address);

    Request := (Name => Non_Blocking_IO, Enabled => True);
    Control_Socket (Client, Request);  -- make socket I/O non-blocking
    Channel := Stream (Client);

    declare
       Message : String (1 .. 256);
    begin
       String'Read (Channel, Message);
       Ada.Text_IO.Put_Line (Message);
    end;
end Test;


The code blocks now in line

   Control_Socket (Client, Request);  -- make socket I/O non-blocking

The application crashes with: Segmentation fault. *shrugging*

Maybe Create_Selector is the way to go...


Best regards,
   Dennis




  reply	other threads:[~2008-08-08 18:08 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-08 13:24 Problems with Ada.Streams.Read (blocking) Dennis Hoppe
2008-08-08 13:56 ` Dmitry A. Kazakov
2008-08-08 18:00   ` Dennis Hoppe
2008-08-08 18:51     ` Dmitry A. Kazakov
2008-08-08 19:37       ` Dennis Hoppe
2008-08-08 21:25       ` Maciej Sobczak
2008-08-09  7:30         ` Dmitry A. Kazakov
2008-08-08 14:48 ` Adam Beneschan
2008-08-08 18:08   ` Dennis Hoppe [this message]
2008-08-09  3:04 ` anon
2008-08-22 22:13 ` Paweł 'Nivertius' Płazieński
replies disabled

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