Store connections by token instead of by fd
The connections are currently stored by fd. If a connection is removed via 'removeInputChannel', it is possible to re-create the same connection and have it keyed by the same fd. When this happens, a race condition may occur where a socket hangup on this fd would cause the removal of a newly registered connection. In this refactor, the connections are no longer stored by fd. The looper interface for adding fds has two versions: 1) the old one that we are currently using, which is marked as 'do not use' 2) the new one where a callback object is provided instead. In this CL, we switch to the new version of the callback. There is now also no need to store the inputchannels in a separate structure, because we can use the connections collection that's now keyed by token to find them. In a future refactor, we should switch to using 'unique_ptr' for the inputchannels. Most of the time when we are looking for an input channel, we are actually interested in finding the corresponding connection. If we switch Connection to shared_ptr, we can also look into switching LooperEventCallback to store a weak pointer to a connection instead of storing the connection token. This should speed up the handling of events, by avoiding a map lookup. Test: ./reinitinput.sh. Observe that it doesnt finish after this patch Test: atest inputflinger_tests Bug: 182478748 Change-Id: I601f765eebfadcaeff3661a10a10c4a4f0477389
Loading
Please register or sign in to comment