Browse Source

fix #1554: use AF_INET instead of AF_UNIX, and write port number to lockfile

283
ThomasV 9 years ago
parent
commit
b727824eed
  1. 25
      electrum

25
electrum

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

Loading…
Cancel
Save