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.
答案 0 :(得分:1)
总结所有评论点:
FILE_EXIST
错误。答案 1 :(得分:1)
感谢@LPs指出出了什么问题。进入PIPE后我的每个样品都在等待阅读。然而,我想要一个实现,其中我的读者线程可以一次读取所有10个样本。这是我的实施。 -
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);
}