From: Beat Bolli Date: Wed, 25 Dec 2013 14:28:06 +0000 (+0100) Subject: irk: reuse the already connected socket X-Git-Tag: 2.8~8 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=f6875352b0a3761ba0057b57e21c2d21057ecec9;p=irker.git irk: reuse the already connected socket Signed-off-by: Eric S. Raymond --- diff --git a/irk b/irk index 6b35826..0e88a1a 100755 --- a/irk +++ b/irk @@ -12,11 +12,10 @@ import socket import sys import fileinput -def send(target, message): +def send(s, target, message): data = {"to": target, "privmsg" : message} #print(json.dumps(data)) try: - s = socket.create_connection(("localhost", 6659)) s.sendall(json.dumps(data)) except socket.error, e: sys.stderr.write("irk: write to server failed: %r\n" % e) @@ -33,6 +32,6 @@ message = " ".join(sys.argv[2:]) message = message.decode('string_escape') if message == '-': for line in fileinput.input('-'): - send(target, line.rstrip('\n')) + send(s, target, line.rstrip('\n')) else: - send(target, message) + send(s, target, message)