This commit is contained in:
Matteo ℱan 2020-07-21 22:39:27 +02:00
parent 1743156808
commit 771b70d376
No known key found for this signature in database
GPG Key ID: 3C30A05BC133D9B6
2 changed files with 7 additions and 5 deletions

1
.gitignore vendored
View File

@ -2,6 +2,7 @@
pykms_logserver.log*
pykms_logclient.log*
pykms_newlines.txt*
pykms_clean_newlines.txt*
pykms_config.pickle*
etrigan.log*

View File

@ -40,7 +40,7 @@ class KeyServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
self.address_family = socket.AF_INET6 # This call make sure the server creates an IPv6 socket and NOT an IPv4 by default
socketserver.TCPServer.__init__(self, server_address, RequestHandlerClass)
self.__shutdown_request = False
self.r_service, self.w_service = os.pipe()
self.r_service, self.w_service = socket.socketpair()
if hasattr(selectors, 'PollSelector'):
self._ServerSelector = selectors.PollSelector
@ -68,7 +68,8 @@ class KeyServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
with self._ServerSelector() as selector:
selector.register(fileobj = self, events = selectors.EVENT_READ)
# self-pipe trick.
selector.register(fileobj = self.r_service, events = selectors.EVENT_READ)
selector.register(fileobj = self.r_service.fileno(), events = selectors.EVENT_READ)
selector.register(fileobj = self.w_service.fileno(), events = selectors.EVENT_WRITE)
while not self.__shutdown_request:
ready = selector.select(timeout)
@ -84,9 +85,9 @@ class KeyServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
for key, mask in ready:
if key.fileobj is self:
self._handle_request_noblock()
elif key.fileobj is self.r_service:
elif key.fileobj is self.r_service.fileno():
# only to clean buffer.
msgkill = os.read(self.r_service, 8).decode('utf-8')
msgkill = os.read(self.r_service.fileno(), 8).decode('utf-8')
sys.exit(0)
finally:
self.__shutdown_request = False
@ -121,7 +122,7 @@ class server_thread(threading.Thread):
self.is_running_thread.set()
def terminate_eject(self):
os.write(self.server.w_service, u''.encode('utf-8'))
os.write(self.server.w_service.fileno(), u''.encode('utf-8'))
def run(self):
while not self.is_running_thread.is_set():