mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2025-01-03 02:02:33 +01:00
auto-t: hostapd.py: use non_block_wait
This commit is contained in:
parent
732871b601
commit
5ebbe07fa6
@ -86,30 +86,19 @@ class HostapdCLI:
|
|||||||
def __init__(self, config=None):
|
def __init__(self, config=None):
|
||||||
self._init_hostapd(config)
|
self._init_hostapd(config)
|
||||||
|
|
||||||
def wait_for_event(self, event, timeout=10):
|
def _poll_event(self, event):
|
||||||
global mainloop
|
if not self._data_available(0.25):
|
||||||
self._wait_timed_out = False
|
|
||||||
|
|
||||||
def wait_timeout_cb():
|
|
||||||
self._wait_timed_out = True
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
timeout = GLib.timeout_add_seconds(timeout, wait_timeout_cb)
|
data = self.ctrl_sock.recv(4096).decode('utf-8')
|
||||||
context = mainloop.get_context()
|
if event in data:
|
||||||
|
return data
|
||||||
|
|
||||||
while True:
|
return False
|
||||||
context.iteration(may_block=False)
|
|
||||||
|
|
||||||
while self._data_available(0.25):
|
def wait_for_event(self, event, timeout=10):
|
||||||
data = self.ctrl_sock.recv(4096).decode('utf-8')
|
return ctx.non_block_wait(self._poll_event, timeout, event,
|
||||||
if event in data:
|
exception=TimeoutError("waiting for event"))
|
||||||
GLib.source_remove(timeout)
|
|
||||||
return data
|
|
||||||
|
|
||||||
if self._wait_timed_out:
|
|
||||||
raise TimeoutError('waiting for hostapd event timed out')
|
|
||||||
|
|
||||||
return None
|
|
||||||
|
|
||||||
def _data_available(self, timeout=2):
|
def _data_available(self, timeout=2):
|
||||||
[r, w, e] = select.select([self.ctrl_sock], [], [], timeout)
|
[r, w, e] = select.select([self.ctrl_sock], [], [], timeout)
|
||||||
@ -123,10 +112,10 @@ class HostapdCLI:
|
|||||||
|
|
||||||
self.ctrl_sock.send(bytes(command))
|
self.ctrl_sock.send(bytes(command))
|
||||||
|
|
||||||
if self._data_available(timeout):
|
ctx.non_block_wait(self._data_available, timeout,
|
||||||
return self.ctrl_sock.recv(4096).decode('utf-8')
|
exception=TimeoutError("waiting for control response"))
|
||||||
|
|
||||||
raise Exception('timeout waiting for control response')
|
return self.ctrl_sock.recv(4096).decode('utf-8')
|
||||||
|
|
||||||
def _del_hostapd(self, force=False):
|
def _del_hostapd(self, force=False):
|
||||||
if not self.ctrl_sock:
|
if not self.ctrl_sock:
|
||||||
|
Loading…
Reference in New Issue
Block a user