Mercurial > hg
changeset 40878:2525faf4ecdb
commandserver: loop over selector events
An IPC socket will be waited by the same selector.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Wed, 31 Oct 2018 22:05:45 +0900 |
parents | 9f00de4dc7cb |
children | 0c638ff69f5c |
files | mercurial/commandserver.py |
diffstat | 1 files changed, 7 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/commandserver.py Wed Oct 31 22:03:07 2018 +0900 +++ b/mercurial/commandserver.py Wed Oct 31 22:05:45 2018 +0900 @@ -541,7 +541,8 @@ exiting = False h = self._servicehandler selector = selectors.DefaultSelector() - selector.register(self._sock, selectors.EVENT_READ) + selector.register(self._sock, selectors.EVENT_READ, + self._acceptnewconnection) while True: if not exiting and h.shouldexit(): # clients can no longer connect() to the domain socket, so @@ -552,20 +553,21 @@ self._unlinksocket() exiting = True try: - ready = selector.select(timeout=h.pollinterval) + events = selector.select(timeout=h.pollinterval) except OSError as inst: # selectors2 raises ETIMEDOUT if timeout exceeded while # handling signal interrupt. That's probably wrong, but # we can easily get around it. if inst.errno != errno.ETIMEDOUT: raise - ready = [] - if not ready: + events = [] + if not events: # only exit if we completed all queued requests if exiting: break continue - self._acceptnewconnection(self._sock, selector) + for key, _mask in events: + key.data(key.fileobj, selector) selector.close() def _acceptnewconnection(self, sock, selector):