comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Problems with Ada.Streams.Read (blocking)
Date: Fri, 8 Aug 2008 20:51:01 +0200
Date: 2008-08-08T20:51:02+02:00	[thread overview]
Message-ID: <150pczbbk7gb2$.1ashrop4xh1b.dlg@40tude.net> (raw)
In-Reply-To: g7i1kc$ujv$1@aioe.org

On Fri, 08 Aug 2008 20:00:44 +0200, Dennis Hoppe wrote:

> Actually, some invocation of Ada.Streams.Read (Channel.all, Buffer, 
> Index) should lead to
> 
>    Index < Buffer'Last
> 
> if the end of the stream is reached.

You never reach the end of a TCP/IP stream unless the client closes the
socket, which is usually indicates an error.

The point is that you should never care about the stream end.

> I am now able to read line per line sent by the ftp server, but if
> I only once invoke my read method to often, the whole program hangs up
> due to the blocking behavior of Ada.Stream.Read.

No, it does because you incorrectly implement the protocol. Typically, you
send a request to the server and it answers with a chain of records. The
number and the content of the records is determined by the protocol. So you
can always know what to expect. Pseudo-code looks like

   -- Processing a request
   send request
   loop
      read one record
      interpret the content of
      exit when no records should follow
   end loop
   -- Ready to issue another request
   ...

You have mentioned FTP. There is a clear definition of how a FTP server
response ends:

"The client can identify the last line of the response as follows: it
begins with three ASCII digits and a space; previous lines do not. The
three digits form a code. Codes between 100 and 199 indicate marks; codes
between 200 and 399 indicate acceptance; codes between 400 and 599 indicate
rejection."
  --  http://cr.yp.to/ftp/request.html

If you correctly implement the protocol your application will never block
unless the server is not busy. And you have to read out all response
otherwise the server will be block. So both parties know the states of each
other.

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



  reply	other threads:[~2008-08-08 18:51 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 [this message]
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
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