margarit
asked on
C- Read data from PIPE
Hello,
I am using the following code to read from 2 PIPEs:
PIPE, PIPE_HTTP_REFERER.
I have the following problem:
When the function runs and there is no data in PIPE, the program stucks in read() function until it reads data from PIPE.
Should I add O_NONBLOCK option? If yes, how?
THANKS
Margarit
I am using the following code to read from 2 PIPEs:
PIPE, PIPE_HTTP_REFERER.
I have the following problem:
When the function runs and there is no data in PIPE, the program stucks in read() function until it reads data from PIPE.
Should I add O_NONBLOCK option? If yes, how?
THANKS
Margarit
int main(int argn, char * argv[])
{
int PIPE, PIPE_HTTP_REFERER;
char PIPE_buffer[500];
char PIPE_HTTP_buffer[500];
int PIPE_size=0, PIPE_HTTP_size=0;
PIPE = open("../web/cgi-bin/PIPE",O_RDWR);
PIPE_HTTP_REFERER = open("../web/cgi-bin/PIPE_HTTP_REFERER",O_RDWR);
if(PIPE == 0)
{
printf("\n ERROR open file PIPE\n");
}
if(PIPE_HTTP_REFERER == 0)
{
printf("\n ERROR open file PIPE_HTTP_REFERER \n");
}
while(1)
{
PIPE_size=read(PIPE,PIPE_buffer,500);
PIPE_HTTP_size=read(PIPE_HTTP_REFERER,PIPE_HTTP_buffer,500);
printf("\n size of PIPE buffer = %i ", PIPE_size);
printf("\n size of PIPE HTTP buffer = %i ", PIPE_HTTP_size);
if(PIPE_size > 0)
{
printf("\n PIPE buffer = %s",PIPE_buffer);
}
if (PIPE_HTTP_size > 0)
{
printf("PIPE HTTP buffer = %s",PIPE_HTTP_buffer);
}
}
}
You need select: http://linux.die.net/man/3/fd_set
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hello,
THANKS for the fast reply. I did the following:
PIPE = open("../web/cgi-bin/PIPE" ,O_RDWR | O_NONBLOCK);
And it seems to work OK. Is it the correct way?
And I put attantion for another problem:
When I put data to PIPE using: echo aaaa>PIPE. I succeed reading data using my function. But If I send data using "submit" option on my form I dont succed to read data using my function (if I use cat > PIPE, I do see my data). What can be a reason?
THANKS
THANKS for the fast reply. I did the following:
PIPE = open("../web/cgi-bin/PIPE"
And it seems to work OK. Is it the correct way?
And I put attantion for another problem:
When I put data to PIPE using: echo aaaa>PIPE. I succeed reading data using my function. But If I send data using "submit" option on my form I dont succed to read data using my function (if I use cat > PIPE, I do see my data). What can be a reason?
THANKS
>> And it seems to work OK. Is it the correct way?
Assuming your system supports O_NONBLOCK correctly (ie. is POSIX compliant), that's perfectly ok.
Do check the man page for open to get a better understanding of what's involved with using O_NONBLOCK.
>> But If I send data using "submit" option on my form
What kind of form . What does the submit do ? In any case, this is probably better posted as a separate question in the appropriate zones, to be sure that the right experts have a look at it.
Assuming your system supports O_NONBLOCK correctly (ie. is POSIX compliant), that's perfectly ok.
Do check the man page for open to get a better understanding of what's involved with using O_NONBLOCK.
>> But If I send data using "submit" option on my form
What kind of form . What does the submit do ? In any case, this is probably better posted as a separate question in the appropriate zones, to be sure that the right experts have a look at it.