bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: read -t loses data


From: Bob Proulx
Subject: Re: read -t loses data
Date: Sat, 30 Jul 2005 10:11:23 -0600
User-agent: Mutt/1.5.9i

bcboy@thecraftstudio.com wrote:
>     If "read -t" times out without fulfilling a request, any pending data is 
> lost.
> Via strace it's apparent that the problem is that when the user requests a 
> line of
> data, bash read is actually calling read() with a buffer size of one. So bash 
> is 
> holding the data. It's not in the OS file buffer. Then when the timeout 
> occurs,
> bash does not return the read data to the user, or associate it with the file 
> descriptor.

As I read the documentation for bash I see the following:

              -t timeout
                     Cause read to time out and return failure if a
                     complete line of input is not read within timeout
                     seconds.

Therefore if a "complete line of input" has not yet been received when
a timeout occurs it does not matter if data is pending or not.  The
read will return failure.

I believe in the case of a timeout that the current behavior is the
correct thing to do.  The error handling model is simple.  Returning
partial data upon timeout would require a much more complicated error
handling strategy to be implemented by the shell script and all shell
scripts would need to pay that implementation penalty.

Bob




reply via email to

[Prev in Thread] Current Thread [Next in Thread]