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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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!news1.google.com!news.glorb.com!wn14feed!worldnet.att.net!bgtnsc05-news.ops.worldnet.att.net.POSTED!53ab2750!not-for-mail Newsgroups: comp.lang.ada From: anon@anon.org (anon) Subject: Re: Problems with Ada.Streams.Read (blocking) Reply-To: no to spamers (No@email.given.org) References: X-Newsreader: IBM NewsReader/2 2.0 Message-ID: Date: Sat, 09 Aug 2008 03:04:39 GMT NNTP-Posting-Host: 12.64.90.159 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc05-news.ops.worldnet.att.net 1218251079 12.64.90.159 (Sat, 09 Aug 2008 03:04:39 GMT) NNTP-Posting-Date: Sat, 09 Aug 2008 03:04:39 GMT Organization: AT&T Worldnet Xref: g2news1.google.com comp.lang.ada:1574 Date: 2008-08-09T03:04:39+00:00 List-Id: Check the source files for the "Ada Terminal Emulator - version 2.3" http://members.optusnet.com.au/~rosshigson/terminal.htm#_Source_Distribution_1 Binaries and Source can be found there. Since, both TELNET and FTP protocols are related you should be able to find out how they goyt around the blocking concept. Or they may even created a query routine that you might be able to adopt for your program. Note: In the emulator the package uses it own Sockets packages which is just a renamed version of the GNAT.Sockets packages. In , Dennis Hoppe writes: >Hi, > >I've written a minimal example to access an ftp server (like FileZilla). >First, let's have a look at the code snippet: > >-- START >with Ada.Text_IO; >with 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 .. 1); > Offset : Ada.Streams.Stream_Element_Count; > >begin > Initialize; > Create_Socket(Client); > Address.Addr := Inet_Addr("127.0.0.1"); > Address.Port := 21; > Connect_Socket (Client,Address); > Channel := Stream(Client); > > loop -- reads in the welcome message > Ada.Streams.Read (Channel.all, Data(1..1), Offset); > exit when Offset = 0; > -- alternative: exit when Offset /= Data'Last > for I in 1 .. Offset loop > Ada.Text_IO.Put (Character'Val (Data (I))); > end loop; > end loop; >end Test; >-- END > >The problem is, that Ada.Streams.Read is blocking, if the end of the >stream is reached. I found many examples, that outline, that the >variable Offset will be 0, if no further elements are on the stream. >But this seems not to be the case, unfortunately. > >For a ftp server/client situation, each command is terminate by , >so I enhanced the exit condition to: > >loop > Ada.Streams.Read (Channel.all, Data(1..2), Offset); > exit when (Character'Val (Data(1)) = ASCII.CR and Character'Val >(Data(2)) = ASCII.LF); > -- code omitted >end loop; > >Of course, the Stream_Element_Array is enhanced to (1..2). > >This approach works very well, but some ftp commands send a messages >over several lines. I do not know in advance, how many lines I should >read in. Subsequently, Ada.Streams.Read has to be called in a loop, >which will eventually block, again. > >How can I query the stream, if new elements are ready to read? > >Many thanks in advance, > Dennis