mirror of
https://opendev.org/x/pyghmi
synced 2025-01-29 04:17:35 +00:00
Enhance filehandle registration
Previously, pyghmi only could have file objects registered. Accept and adjust as appropriate to accomodate plain int filedescriptors. This allows, for example, os.pipe() construct to be hooked. Change-Id: Ie5e81a2276c68e9235d373d4a662f7b1aef153f5
This commit is contained in:
parent
35b50fb705
commit
ccac817f2b
@ -660,7 +660,10 @@ class Session:
|
||||
rdata = cls.socket.recvfrom(3000)
|
||||
pktqueue.append(rdata)
|
||||
for handlepair in _poller(cls.readersockets):
|
||||
myhandle = handlepair.fileno()
|
||||
if isinstance(handlepair, int):
|
||||
myhandle = handlepair
|
||||
else:
|
||||
myhandle = handlepair.fileno()
|
||||
if myhandle != cls.socket.fileno():
|
||||
myfile = cls._external_handlers[myhandle][1]
|
||||
cls._external_handlers[myhandle][0](myfile)
|
||||
@ -701,7 +704,10 @@ class Session:
|
||||
:param callback: function to call when input detected on the handle.
|
||||
will receive the handle as an argument
|
||||
"""
|
||||
cls._external_handlers[handle.fileno()] = (callback, handle)
|
||||
if isinstance(handle, int):
|
||||
cls._external_handlers[handle] = (callback, handle)
|
||||
else:
|
||||
cls._external_handlers[handle.fileno()] = (callback, handle)
|
||||
cls.readersockets += [handle]
|
||||
|
||||
@classmethod
|
||||
|
Loading…
x
Reference in New Issue
Block a user