Reputation: 935
I am trying to implement a named PIPE IPC
method in which I am sending float
values (10) each time the sendToPipe
function is being called. Here is the sendToPipe
function -
int fd;
char *fifoPipe = "/tmp/fifoPipe";
void sendToPipe(paTestData *data){
int readCount = 10;
fd = open(fifoPipe, O_WRONLY); // Getting stuck here
// Reading 10 sample float values from a buffer from readFromCB pointer as the initial address on each call to sendToPipe function.
while(readCount > 0){
write(fd, &data->sampleValues[data->readFromCB], sizeof(SAMPLE)); // SAMPLE is of float datatype
data->readFromCB++;
readCount--;
}
close(fd);
// Some code here
}
And I have initialized the named PIPE
in my main
here :
int main(){
// Some code
mkfifo(fifoPipe, S_IWUSR | S_IRUSR);
// Other code
}
I am not getting where am I going wrong here. Any help is appreciated. Also let me know if any other information is required.
Upvotes: 2
Views: 3048
Reputation: 16213
Summing all the commented points:
FILE_EXIST
error.Upvotes: 3
Reputation: 935
Thanks to @LPs for pointing out what was going wrong. My each sample after entering the PIPE was waiting to be read. I however wanted an implementation in which my reader thread could read all the 10 samples in one go. Here is my implementation. -
void pipeData(paTestData *data){
SAMPLE *tempBuff = (SAMPLE*)malloc(sizeof(SAMPLE)*FRAME_SIZE);
int readCount = FRAME_SIZE;
while(readCount > 0){
tempBuff[FRAME_SIZE - readCount] = data->sampleValues[data->readFromCB];
data->readFromCB++;
readCount--;
}
fd = open(fifoPipe, O_WRONLY);
write(fd, tempBuff, sizeof(tempBuff));
// Reader thread called here
close(fd);
}
Upvotes: 1