PDA

View Full Version : data at fifo's receiving end has arrived?



quickNitin
5th November 2006, 09:24
This is related to Linux ,fifo and pthreads.

How i can come to know that data at receiving end of fifo has arrived. Is there any way to know this asynchronously other than blocked reading or continuous polling.

situation is such ( presenting in abstract manner): In main thread, an other member-thread is run( Qthread). In this member-thread , i open a fifo for non bloced reading. This fifo will receve values from some other process. And i want to pass these values to main thread.
2 issues are here:
1. How i will come to know some-data is available in fifo. Currently i am going for periodic reading?
2. How to inform this to main thread. Currently whenever i receives something, i send a signal connected to slot of main thread. This makes thread behaves as some function and control passes immediately to main thread-slot. and control do not come back. Ihave started a timer which will keep starting this member-thread.

here i know ,a lot of things are fishy. I am looking for guidance how to make that well.

quickNitin

wysota
5th November 2006, 10:20
You can send a unix signal from the sender thread/process after it writes to the pipe and you can handle the signal in the other thread/process. You'll need to do some masking though, so that proper thread receives the signal. And there is no guarantee that the data will be ready to read by then (it should be, but it might not be).

I hope I understood the problem correctly :)

quickNitin
5th November 2006, 10:22
for the question 1, ihave found there is a state based system call select() which gives the state of file descriptors. how it works i have to see? but again , it is not event based.
Is there any system call which will let kerenel tell me status of fd whenevr some event occurs which i could connect to slot.

quickNitin
5th November 2006, 10:26
yes wyotsa, you have understood one of them. It strkied me as one of solution. I hadnot implemented this till now as i not much knowledgeable about signals.

wysota
5th November 2006, 11:05
for the question 1, ihave found there is a state based system call select() which gives the state of file descriptors. how it works i have to see? but again , it is not event based.
Select() polls filedescriptors for their state, so it's not suitable for you if you want to be informed about the event.


Is there any system call which will let kerenel tell me status of fd whenevr some event occurs which i could connect to slot.

Not likely. You could check out file monitors (FAM) which have support in the kernel but I don't know if it works for pipes.

About unix signals - check out manual for signal and sigaction.