irk: reuse the already connected socket
authorBeat Bolli <bbolli@ewanet.ch>
Wed, 25 Dec 2013 14:28:06 +0000 (15:28 +0100)
committerEric S. Raymond <esr@thyrsus.com>
Fri, 30 May 2014 14:14:54 +0000 (10:14 -0400)
Signed-off-by: Eric S. Raymond <esr@thyrsus.com>
irk

diff --git a/irk b/irk
index 6b3582678a2e5f06564d1654706e79bb62548b7c..0e88a1a04b0243a5789670c299277655357ff372 100755 (executable)
--- 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)