O_NONBLOCK has no effect on stdout

Dave Johnson dave-cygwin-mailing-list-on-2003-06-01@centerclick.org
Sun Jun 1 05:07:00 GMT 2003


Setting stdout to non-blocking doesn't have an effect, calls to
write() and the like block the process until the blocking condition is
removed.

Note that the fcntl() returns success.


Running the below test program produces:

under cygwin:

$ ./test
Starting, sleeping 2 seconds, hit ctrl-s
test
return=6, errno=No error, time=3903ms

under linux and others:

$ ./test
Starting, sleeping 2 seconds, hit ctrl-s
return=-1, errno=Resource temporarily unavailable, time=0ms


I'm running:
CYGWIN_NT-5.0 yorktown 1.3.22(0.78/3/2) 2003-03-18 09:20 i686 unknown unknown Cygwin


test program:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <errno.h>
#include <string.h>

int main (int argc, char *argv[])
{
  struct timeval start_tv, end_tv;
  ssize_t callval;
  int callval2;
  
  printf("Starting, sleeping 2 seconds, hit ctrl-s\r\n");
  
  sleep (2);
  
  callval2 = fcntl(fileno(stdout), F_SETFL, fcntl(fileno(stdout), F_GETFL, 0) | O_NONBLOCK);
  if (callval2 < 0)
    {
      fprintf(stderr,"set nonblocking failed: %s", strerror(errno));
    }
  
  gettimeofday(&start_tv,NULL);
  
  errno=0;
  callval = write(fileno(stdout), "test\r\n", 6);
  
  gettimeofday(&end_tv,NULL);
  
  callval2 = fcntl(fileno(stdout), F_SETFL, fcntl(fileno(stdout), F_GETFL, 0) & ~O_NONBLOCK);
  if (callval2 < 0)
    {
      fprintf(stderr,"set nonblocking failed: %s", strerror(errno));
    }
  
  printf("return=%d, errno=%s, time=%ldms\n",
         callval, strerror(errno),
         ((end_tv.tv_sec - start_tv.tv_sec) * 1000) +
         ((end_tv.tv_usec/1000) - (start_tv.tv_usec/1000)));
  
  exit(0);
}



-- 
Dave
k


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list