Mail Archives: cygwin/2002/07/26/07:25:51
------=_NextPartTM-000-86770c25-e047-4103-9d99-d48f476189db
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
i want unsubsribe from the list ...
plz can anybody help
Manav
-----Original Message-----
From: cygwin-owner AT cygwin DOT com [mailto:cygwin-owner AT cygwin DOT com] On Behalf
Of Kandziora Jan
Sent: Friday, July 26, 2002 4:47 PM
To: 'cygwin AT cygwin DOT com'
Subject: piped stdout and O_NONBLOCK
Hi all,
In short: Does it work?
I wanted a program to write its debug messages to a pipe, data flowing
into "faucet" of "netpipes" and over a network connection.
But that did not work, because faucet blocks on a connect() from the
other side and meanwhile does not read any data from the pipe. So the
first program blocks in writing its output after a while, even if the
output stream is set to O_NONBLOCK.
For testing purposes I wrote a program "blocktest":
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/select.h>
#include <unistd.h>
int main(void)
{
char buffer[4096];
fd_set input_set;
int read_bytes;
int remaining_bytes;
char *p;
int written_bytes;
if (fcntl(0,F_SETFL,O_NONBLOCK)<0)
{
perror("input stream can not be set to nonblocking
mode");
exit(EXIT_FAILURE);
}
if (fcntl(1,F_SETFL,O_NONBLOCK)<0)
{
perror("output stream can not be set to nonblocking
mode");
exit(EXIT_FAILURE);
}
FD_ZERO(&input_set);
FD_SET(0,&input_set);
for(;;)
{
// Try to read.
if ((read_bytes=read(0,&buffer,sizeof(buffer)))<0)
{
if (errno!=EAGAIN)
{
perror("read failed");
exit(EXIT_FAILURE);
}
}
else
{
// Nothing to read. Try to write.
remaining_bytes=read_bytes;
p=(char*)&buffer;
while (remaining_bytes>0)
{
if
((written_bytes=write(1,&p,remaining_bytes))<0)
{
if (errno==EAGAIN) break;
perror("write failed");
exit(EXIT_FAILURE);
}
remaining_bytes-=written_bytes;
p+=written_bytes;
}
// Write would block. Wait for new data to read.
select(1,&input_set,NULL,NULL,NULL);
}
}
}
Then I put it into a pipeline
cat /dev/zero | ./blocktest | sleep 1000
With Linux this works as expected, with a "cat" using nearly all cpu
time.
With Cygwin, "blocktest" blocks in the write call after writing 12288
bytes,
causing "cat" to block.
I tested this with Cygwin-1.3.9 and 1.3.12-2.
Did I miss something?
Jan
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
------=_NextPartTM-000-86770c25-e047-4103-9d99-d48f476189db
Content-Type: text/plain;
name="Wipro_Disclaimer.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="Wipro_Disclaimer.txt"
**************************Disclaimer************************************
Information contained in this E-MAIL being proprietary to Wipro Limited is
'privileged' and 'confidential' and intended for use only by the individual
or entity to which it is addressed. You are notified that any use, copying
or dissemination of the information contained in the E-MAIL in any manner
whatsoever is strictly prohibited.
***************************************************************************
------=_NextPartTM-000-86770c25-e047-4103-9d99-d48f476189db
Content-Type: text/plain; charset=us-ascii
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
------=_NextPartTM-000-86770c25-e047-4103-9d99-d48f476189db--
- Raw text -