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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c58b7bd180ea81b2 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!club-internet.fr!feedme-small.clubint.net!aioe.org!not-for-mail From: Dennis Hoppe Newsgroups: comp.lang.ada Subject: Re: Problems with Ada.Streams.Read (blocking) Date: Fri, 08 Aug 2008 20:08:43 +0200 Organization: Aioe.org NNTP Server Message-ID: References: <103f4912-d96b-4c11-b9b2-d7a6d6ffcff3@i24g2000prf.googlegroups.com> NNTP-Posting-Host: U0vjPcDXCVFh7Khkeo3Jnw.user.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Thunderbird 2.0.0.16 (Macintosh/20080707) Xref: g2news1.google.com comp.lang.ada:1562 Date: 2008-08-08T20:08:43+02:00 List-Id: 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