|
@ -30,7 +30,6 @@ import socket |
|
|
import Queue |
|
|
import Queue |
|
|
from collections import defaultdict |
|
|
from collections import defaultdict |
|
|
|
|
|
|
|
|
DAEMON_SOCKET = 'daemon.sock' |
|
|
|
|
|
|
|
|
|
|
|
script_dir = os.path.dirname(os.path.realpath(__file__)) |
|
|
script_dir = os.path.dirname(os.path.realpath(__file__)) |
|
|
is_bundle = getattr(sys, 'frozen', False) |
|
|
is_bundle = getattr(sys, 'frozen', False) |
|
@ -350,13 +349,11 @@ class NetworkServer(util.DaemonThread): |
|
|
print_error("client quit:", len(self.clients)) |
|
|
print_error("client quit:", len(self.clients)) |
|
|
|
|
|
|
|
|
def run(self): |
|
|
def run(self): |
|
|
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) |
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
|
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) |
|
|
s.bind(('', 0)) |
|
|
daemon_socket = os.path.join(self.config.path, DAEMON_SOCKET) |
|
|
lockfile = os.path.join(self.config.path, 'lock') |
|
|
if os.path.exists(daemon_socket): |
|
|
with open(lockfile, 'w') as f: |
|
|
os.remove(daemon_socket) |
|
|
f.write("%d"%s.getsockname()[1]) |
|
|
daemon_timeout = self.config.get('daemon_timeout', None) |
|
|
|
|
|
s.bind(daemon_socket) |
|
|
|
|
|
s.listen(5) |
|
|
s.listen(5) |
|
|
s.settimeout(0.1) |
|
|
s.settimeout(0.1) |
|
|
while self.is_running(): |
|
|
while self.is_running(): |
|
@ -370,19 +367,17 @@ class NetworkServer(util.DaemonThread): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_daemon(config): |
|
|
def get_daemon(config): |
|
|
daemon_socket = os.path.join(config.path, DAEMON_SOCKET) |
|
|
lockfile = os.path.join(config.path, 'lock') |
|
|
try: |
|
|
try: |
|
|
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) |
|
|
with open(lockfile) as f: |
|
|
s.connect(daemon_socket) |
|
|
num = int(f.read()) |
|
|
|
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
|
|
|
|
s.connect(('', num)) |
|
|
return s |
|
|
return s |
|
|
except socket.error: |
|
|
|
|
|
return False |
|
|
|
|
|
except: |
|
|
except: |
|
|
# do not use daemon if AF_UNIX is not available (windows) |
|
|
|
|
|
return False |
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
if __name__ == '__main__': |
|
|
|
|
|
|
|
|
# make sure that certificates are here |
|
|
# make sure that certificates are here |
|
|