I am trying to connect a socket to a FIFO pipe, but can't find an easy way to do it.
At the moment I am using:
char localbuf[2];
while(1) {
memset(localbuf,0,sizeof(localbuf));
ret = read(sfd,localbuf,1);
test(ret,"Unable to read from socket");
ret = write(out,localbuf,1);
test(ret,"Unable to write to out FIFO");
read(in,localbuf,1);
test(ret,"Unable to read from in FIFO");
write(sfd,localbuf,1);
test(ret,"Unable to write to socket");
}
However, this seems horribly inefficient and wrong because it should not send the data until it receives a newline but cannot know beforehand how much data there will be.
Complete code here
Is there a better way?