diff options
author | paulfantom <paulfantom@gmail.com> | 2016-07-15 20:35:54 +0200 |
---|---|---|
committer | paulfantom <paulfantom@gmail.com> | 2016-07-15 20:35:54 +0200 |
commit | 54c79c47770b513baab4174195f423f9be268af5 (patch) | |
tree | e676fcde87d31ff835f29c67d072df056153ee8e /python.d/python_modules/base.py | |
parent | a6b4a8ef36487c98fd6b74b18c3818688f4f1409 (diff) |
fix `SocketService`
Diffstat (limited to 'python.d/python_modules/base.py')
-rw-r--r-- | python.d/python_modules/base.py | 34 |
1 files changed, 10 insertions, 24 deletions
diff --git a/python.d/python_modules/base.py b/python.d/python_modules/base.py index 7163731326..a1d768b58c 100644 --- a/python.d/python_modules/base.py +++ b/python.d/python_modules/base.py @@ -485,7 +485,8 @@ class SocketService(SimpleService): Get raw data with low-level "socket" module. :return: str """ - if self._sock is None: + #if self._sock is None: + if True: try: if self.unix_socket is None: self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -513,37 +514,22 @@ class SocketService(SimpleService): self._sock.send(self.request) except Exception as e: try: - self._sock.shutdown(1) + self._sock.shutdown(0) self._sock.close() except: pass self._sock = None self.error(str(e), "used configuration: host:", str(self.host), "port:", str(self.port), "socket:", str(self.unix_socket)) return None - # data = "" - # import select - # while True: - # try: - # ready_to_read, _, in_error = select.select([sock, ], [], [], 0.01) - # except Exception as e: - # self.debug("SELECT", str(e)) - # sock.shutdown(0) - # break - # if len(ready_to_read) > 0: - # buf = sock.recv(1024) - # if len(buf) == 0 or buf is None: - # break - # data += buf.decode() - # if data == "": - # return None - # return data size = 2 try: data = self._sock.recv(size).decode() except Exception as e: self.error(str(e), "used configuration: host:", str(self.host), "port:", str(self.port), "socket:", str(self.unix_socket)) + self._sock.shutdown(0) self._sock.close() + self._sock = None return None while True: @@ -552,11 +538,11 @@ class SocketService(SimpleService): size *= 2 buf = self._sock.recv(size) data += buf.decode() - if len(buf) < size: - if self._more_data_available(): - size = 2 - else: - break + if len(buf) == 0: break + if len(buf) < size and not self._more_data_available(): + break + else: + size = 4 return data |