This is what I tried, and it is working now
read:
Code:
fd_set rfds;
int res=0;
int retval;
struct timeval tv;
//////////////////
FD_ZERO(&rfds);
int pipe_fd = open( FIFO_NAME, O_RDONLY | O_NONBLOCK);
FD_SET(pipe_fd, &rfds);
tv.tv_sec = 1;
tv.tv_usec = 0;
int nfds = max( pipe_fd,1 ) + 1;
retval = select(nfds, &rfds, NULL, NULL, &tv);
if ( retval!=-1 )
{
if (FD_ISSET(pipe_fd,&rfds))
res = read(pipe_fd, &T, sizeof(T));
}
close(pipe_fd);
//Ignore Invalid Messages
if(res != sizeof(T)) return -1;
write:
Code:
int pipe_fd=0, res=0;
//////////////////
while(1)
{
pipe_fd = open ( FIFO_NAME.c_str(), O_WRONLY );
if ( pipe_fd == -1 )
cout << "open error" << endl;
res = write ( pipe_fd, &T, sizeof ( T ) );
if ( res == -1 )
cout << "write error" << endl;
close ( pipe_fd );
sleep ( 1 );
}
So, there is a select, controlling pipe with FD_ISSET and a sleep. If there is any AMBIGUITY or something is missed, please tell me.
Thanks