From 8e242f54755afbca602d29fa8d1f14bf06082664 Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Thu, 3 Mar 2022 01:24:59 -0600 Subject: [PATCH] Converted to use unix socket --- .../SolarFM/solarfm/ipc_server.py | 30 +++++++++++++++---- .../solarfm-0.0.1/SolarFM/solarfm/main.py | 2 +- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/versions/solarfm-0.0.1/SolarFM/solarfm/ipc_server.py b/src/versions/solarfm-0.0.1/SolarFM/solarfm/ipc_server.py index 9223edd..0972d86 100644 --- a/src/versions/solarfm-0.0.1/SolarFM/solarfm/ipc_server.py +++ b/src/versions/solarfm-0.0.1/SolarFM/solarfm/ipc_server.py @@ -1,5 +1,5 @@ # Python imports -import threading, time +import os, threading, time from multiprocessing.connection import Listener, Client # Lib imports @@ -17,17 +17,30 @@ def threaded(fn): class IPCServer: """ Create a listener so that other SolarFM instances send requests back to existing instance. """ - def __init__(self): + def __init__(self, conn_type="socket"): self.is_ipc_alive = False + self._conn_type = conn_type self.ipc_authkey = b'solarfm-ipc' - self.ipc_address = '127.0.0.1' - self.ipc_port = 4848 self.ipc_timeout = 15.0 + if conn_type == "socket": + self.ipc_address = '/tmp/solarfm-ipc.sock' + else: + self.ipc_address = '127.0.0.1' + self.ipc_port = 4848 + @threaded def create_ipc_server(self): - listener = Listener((self.ipc_address, self.ipc_port), authkey=self.ipc_authkey) + if self._conn_type == "socket": + if os.path.exists(self.ipc_address): + return + + listener = Listener(address=self.ipc_address, family="AF_UNIX", authkey=self.ipc_authkey) + else: + listener = Listener((self.ipc_address, self.ipc_port), authkey=self.ipc_authkey) + + self.is_ipc_alive = True while True: conn = listener.accept() @@ -65,7 +78,12 @@ class IPCServer: def send_ipc_message(self, message="Empty Data..."): try: - conn = Client((self.ipc_address, self.ipc_port), authkey=self.ipc_authkey) + if self._conn_type == "socket": + conn = Client(address=self.ipc_address, family="AF_UNIX", authkey=self.ipc_authkey) + else: + conn = Client((self.ipc_address, self.ipc_port), authkey=self.ipc_authkey) + + conn.send(message) conn.send('close connection') except Exception as e: diff --git a/src/versions/solarfm-0.0.1/SolarFM/solarfm/main.py b/src/versions/solarfm-0.0.1/SolarFM/solarfm/main.py index 4a26b4d..ecd2d03 100644 --- a/src/versions/solarfm-0.0.1/SolarFM/solarfm/main.py +++ b/src/versions/solarfm-0.0.1/SolarFM/solarfm/main.py @@ -17,7 +17,7 @@ class Main(EventSystem): def __init__(self, args, unknownargs): if not trace_debug: event_system.create_ipc_server() - time.sleep(0.2) # Make sure everything's up before proceeding. + time.sleep(0.1) if not event_system.is_ipc_alive: if unknownargs: