mirror of https://github.com/fail2ban/fail2ban
ENH: removed double tab indentation, pass use_poll into loop, reorderd log msg to come after action to be factually correct
parent
c84b6370c5
commit
deca0b80ab
|
@ -92,9 +92,12 @@ class RequestHandler(asynchat.async_chat):
|
||||||
|
|
||||||
|
|
||||||
def loop(active, timeout=None, use_poll=False):
|
def loop(active, timeout=None, use_poll=False):
|
||||||
# Use poll instead of loop, because of recognition of active flag,
|
"""Custom event loop implementation
|
||||||
# because of loop timeout mistake: different in poll and poll2 (sec vs ms),
|
|
||||||
# and to prevent sporadical errors like EBADF 'Bad file descriptor' etc. (see gh-161)
|
Uses poll instead of loop to respect `active` flag,
|
||||||
|
to avoid loop timeout mistake: different in poll and poll2 (sec vs ms),
|
||||||
|
and to prevent sporadic errors like EBADF 'Bad file descriptor' etc. (see gh-161)
|
||||||
|
"""
|
||||||
if timeout is None:
|
if timeout is None:
|
||||||
timeout = Utils.DEFAULT_SLEEP_TIME
|
timeout = Utils.DEFAULT_SLEEP_TIME
|
||||||
poll = asyncore.poll
|
poll = asyncore.poll
|
||||||
|
@ -177,7 +180,7 @@ class AsyncServer(asyncore.dispatcher):
|
||||||
# Sets the init flag.
|
# Sets the init flag.
|
||||||
self.__init = self.__active = True
|
self.__init = self.__active = True
|
||||||
# Event loop as long as active:
|
# Event loop as long as active:
|
||||||
loop(lambda: self.__active)
|
loop(lambda: self.__active, use_poll=use_poll)
|
||||||
# Cleanup all
|
# Cleanup all
|
||||||
self.stop()
|
self.stop()
|
||||||
|
|
||||||
|
@ -187,8 +190,8 @@ class AsyncServer(asyncore.dispatcher):
|
||||||
asyncore.dispatcher.close(self)
|
asyncore.dispatcher.close(self)
|
||||||
# Remove socket (file) only if it was created:
|
# Remove socket (file) only if it was created:
|
||||||
if self.__init and os.path.exists(self.__sock):
|
if self.__init and os.path.exists(self.__sock):
|
||||||
logSys.debug("Removed socket file " + self.__sock)
|
|
||||||
os.remove(self.__sock)
|
os.remove(self.__sock)
|
||||||
|
logSys.debug("Removed socket file " + self.__sock)
|
||||||
logSys.debug("Socket shutdown")
|
logSys.debug("Socket shutdown")
|
||||||
self.__active = False
|
self.__active = False
|
||||||
|
|
||||||
|
@ -198,6 +201,7 @@ class AsyncServer(asyncore.dispatcher):
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
|
# better remains a method (not a property) since used as a callable for wait_for
|
||||||
def isActive(self):
|
def isActive(self):
|
||||||
return self.__active
|
return self.__active
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue