Commit 63ef0ac3 authored by Jim Fulton's avatar Jim Fulton

Wrap the socket in a file

So we don't have to worry about incomplete sends or recvs.
parent 9be1c9a9
...@@ -73,9 +73,13 @@ def check(addr, output_metrics, status, per): ...@@ -73,9 +73,13 @@ def check(addr, output_metrics, status, per):
s.connect(addr) s.connect(addr)
except socket.error: except socket.error:
return error("Can't connect %s" % sys.exc_info()[1]) return error("Can't connect %s" % sys.exc_info()[1])
s.send('\x00\x00\x00\x04ruok') fp = s.makefile()
proto = s.recv(struct.unpack(">I", s.recv(4))[0]) fp.write('\x00\x00\x00\x04ruok')
datas = s.recv(struct.unpack(">I", s.recv(4))[0]) fp.flush()
proto = fp.read(struct.unpack(">I", fp.read(4))[0])
datas = fp.read(struct.unpack(">I", fp.read(4))[0])
fp.close()
s.close()
data = json.loads(datas) data = json.loads(datas)
if not data: if not data:
return warn("No storages") return warn("No storages")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment