it can happen both events can be set, poll() return value holds the number of set revents but not an index. So, you need to check: if there is an exit event - just break, otherwise - read data