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

Re: [libvirt] [PATCH 05/11] Add a generic internal API for handling any FD based stream



On Wed, Nov 03, 2010 at 10:38:33AM -0600, Eric Blake wrote:
> On 11/03/2010 07:23 AM, Daniel P. Berrange wrote:
> >>   I was wondering about reusing saferead/write but they have a different
> >> semantic on blocking,
> > 
> > Yep,  saferead/write cannot be used on any FD with O_NONBLOCK
> > set, because they'll just spin in a 100% CPU loop whenever
> > EAGAIN occurs, until they get nbytes worth of data.
> 
> Is it worth teaching saferead/write to use fcntl() to determine if an fd
> is O_NONBLOCK?  And if so, should it outright reject an O_NONBLOCK fd
> (to help us diagnose bugs) or be documented as allowing an EAGAIN
> failure on non-blocking fds?

The API design doesn't lend itself to this, because it would result in
a horribly inefficient way of reading data

  fcntl(fd)
  read(fd, buf, 1024);
  fcntl(fd)
  read(fd, buf, 1024);
  fcntl(fd)
  read(fd, buf, 1024);
  fcntl(fd)
  read(fd, buf, 1024);
  fcntl(fd)
  read(fd, buf, 1024);
  fcntl(fd)
  read(fd, buf, 1024);
  fcntl(fd)
  read(fd, buf, 1024);
  ...

Daniel
-- 
|: Red Hat, Engineering, London    -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :|
|: http://autobuild.org        -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|


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