[Top][All Lists]

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

Re: non-blocking I/O

From: Paolo Bonzini
Subject: Re: non-blocking I/O
Date: Thu, 31 Mar 2011 08:44:36 +0200
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.7

On 03/30/2011 07:46 PM, Eric Blake wrote:
I'm not sure whether block and character
special devices can usefully be set non-blocking

I believe at least /dev/random supports it:

#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
int main()
  char buf[256];
  int fd = open ("/dev/random", O_RDONLY | O_NONBLOCK);
  if (fd == -1) {
    perror ("/dev/random");
    exit (1);
  alarm (5);
  while (read (fd, buf, 256) != -1 || errno != EAGAIN)
  puts ("works");
  exit (0);


reply via email to

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