delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2003/06/01/01:07:32

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
From: Dave Johnson <dave-cygwin-mailing-list-on-2003-06-01 AT centerclick DOT org>
MIME-Version: 1.0
Message-ID: <16089.35333.701156.506551@wellington.i202.centerclick.org>
Date: Sun, 1 Jun 2003 01:07:17 -0400
To: cygwin AT cygwin DOT com
Subject: O_NONBLOCK has no effect on stdout

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019