spambas
spambas

Reputation: 55

How to stop poll() from being interrupted by a specific signal

I have a C application using poll to wait for some data.

Currently I am implementing the rest of my application into this one and I use time based interrupts (SIGRTMIN). As expected poll() returns if one of my other timers call back.

How can I stop poll from doing that? I am reading a lot about ppoll(), but not sure how to use that... Can I use this to stop this function from returning when a timer event is fired?

(I do not have any problems with the poll being delayed a few ms)

Upvotes: 1

Views: 3592

Answers (1)

John Bollinger
John Bollinger

Reputation: 180256

If a thread / process blocking in poll() receives an unblocked signal then poll() will be interrupted. If you don't want that to happen then you can block the desired signal before calling poll(), and then unblock it after poll() returns (see sigprocmask()). Note, however, that that won't cause poll() to be delayed -- quite the opposite. If anything, it will cause receipt of the signal to be delayed. If poll() blocks long enough then it could cause multiple RT signals to queue up, so that after you unblock that signal you receive it multiple times in quick succession.

You should consider instead checking poll()'s return value (which you should always do anyway) and retrying if it is EINTR.

Upvotes: 4

Related Questions