mirror of
https://github.com/SystemRage/py-kms.git
synced 2024-11-25 09:45:39 +01:00
Fix for #58
This commit is contained in:
parent
1743156808
commit
771b70d376
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,6 +2,7 @@
|
|||||||
pykms_logserver.log*
|
pykms_logserver.log*
|
||||||
pykms_logclient.log*
|
pykms_logclient.log*
|
||||||
pykms_newlines.txt*
|
pykms_newlines.txt*
|
||||||
|
pykms_clean_newlines.txt*
|
||||||
pykms_config.pickle*
|
pykms_config.pickle*
|
||||||
etrigan.log*
|
etrigan.log*
|
||||||
|
|
||||||
|
@ -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
|
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)
|
socketserver.TCPServer.__init__(self, server_address, RequestHandlerClass)
|
||||||
self.__shutdown_request = False
|
self.__shutdown_request = False
|
||||||
self.r_service, self.w_service = os.pipe()
|
self.r_service, self.w_service = socket.socketpair()
|
||||||
|
|
||||||
if hasattr(selectors, 'PollSelector'):
|
if hasattr(selectors, 'PollSelector'):
|
||||||
self._ServerSelector = selectors.PollSelector
|
self._ServerSelector = selectors.PollSelector
|
||||||
@ -68,7 +68,8 @@ class KeyServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
|
|||||||
with self._ServerSelector() as selector:
|
with self._ServerSelector() as selector:
|
||||||
selector.register(fileobj = self, events = selectors.EVENT_READ)
|
selector.register(fileobj = self, events = selectors.EVENT_READ)
|
||||||
# self-pipe trick.
|
# 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:
|
while not self.__shutdown_request:
|
||||||
ready = selector.select(timeout)
|
ready = selector.select(timeout)
|
||||||
@ -84,9 +85,9 @@ class KeyServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
|
|||||||
for key, mask in ready:
|
for key, mask in ready:
|
||||||
if key.fileobj is self:
|
if key.fileobj is self:
|
||||||
self._handle_request_noblock()
|
self._handle_request_noblock()
|
||||||
elif key.fileobj is self.r_service:
|
elif key.fileobj is self.r_service.fileno():
|
||||||
# only to clean buffer.
|
# 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)
|
sys.exit(0)
|
||||||
finally:
|
finally:
|
||||||
self.__shutdown_request = False
|
self.__shutdown_request = False
|
||||||
@ -121,7 +122,7 @@ class server_thread(threading.Thread):
|
|||||||
self.is_running_thread.set()
|
self.is_running_thread.set()
|
||||||
|
|
||||||
def terminate_eject(self):
|
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):
|
def run(self):
|
||||||
while not self.is_running_thread.is_set():
|
while not self.is_running_thread.is_set():
|
||||||
|
Loading…
Reference in New Issue
Block a user