Re: newbie question about fork/pipe/stdin/stdout
- From: vladimir.plotnikov@xxxxxxxxx
- Date: Mon, 29 Oct 2007 09:20:42 -0000
hello agin,
Thank you for replies ;-)
I changed my code to next:
.....
fcntl(pipeStdout[0], F_SETFD, fcntl(pipeStdout[0], F_GETFD) |
O_NONBLOCK);
fcntl(pipeStdin[1], F_SETFD, fcntl(pipeStdin[1], F_GETFD) |
O_NONBLOCK);
....
stream = fdopen (pipeStdin[1], "w");
streamIn = fdopen (pipeStdout[0], "r");
DEBUG ("output start");
for (unsigned int i = 0; i<msg.size();
i++) {
while(select(pipeStdout[0]+1,
&rfds, NULL, NULL, &tv)) {
DEBUG ("add input");
if (fread(&c,1,
1,streamIn)==1)
out = out+ c;
}
if(select(pipeStdin[1]+1,
NULL, &wfds, NULL, &tv)) {
if (!fputc(msg[i],stream))
{DEBUG("output failed"); break; }
DEBUG(i);
} else {
DEBUG ("send data
problem"); i--;
}
}
DEBUG("output end");
2nd "select" catch for "send data problem" when child cannot receive
more data.
In this time child should send me data back. but 1st "select" never
return value other than zero.
Where I wrong again?
Sorry for stupid questions, I never working with select/pipes before.
.
- Follow-Ups:
- Re: newbie question about fork/pipe/stdin/stdout
- From: Alex Fraser
- Re: newbie question about fork/pipe/stdin/stdout
- References:
- Re: newbie question about fork/pipe/stdin/stdout
- From: Alex Fraser
- Re: newbie question about fork/pipe/stdin/stdout
- From: vladimir . plotnikov
- Re: newbie question about fork/pipe/stdin/stdout
- From: David Schwartz
- Re: newbie question about fork/pipe/stdin/stdout
- Prev by Date: Re: Removing all files inside a directory in Linux using an API call from a C Code
- Next by Date: Re: Removing all files inside a directory in Linux using an API call from a C Code
- Previous by thread: Re: newbie question about fork/pipe/stdin/stdout
- Next by thread: Re: newbie question about fork/pipe/stdin/stdout
- Index(es):