@cryptotaxi247 / netdata-1 / commits / b7f32fde8

non-blocking `SocketService`

paulfantom committed Jul 19, 2016 at 02:40 UTC b7f32fde8b79ed7d63c444e1750d35d7a424b787
3 files changed +6 -26
python.d/python_modules/base.py
+2 -2
@@ -572,9 +572,9 @@ class SocketService(SimpleService):
572 break
573 if len(ready_to_read) > 0:
574 buf = self._sock.recv(4096)
575 - if len(buf) == 0 or buf is None:
575 + print(buf)
576 + if len(buf) == 0 or buf is None: # handle server disconnect
577 break
577 -
578 data += buf.decode()
579 if self._check_raw_data(data):
580 break
python.d/redis.chart.py
+1 -1
@@ -135,6 +135,6 @@ class Service(SocketService):
135
136 for name in data:
137 if name.startswith('db'):
138 - self.definitions['keys']['lines'].append([name.decode(), None, 'absolute'])
138 + self.definitions['keys']['lines'].append([name, None, 'absolute'])
139
140 return True
python.d/squid.chart.py
+3 -23
@@ -88,30 +88,10 @@ class Service(SocketService):
88 else:
89 self._keep_alive = False
90
91 - # if "client" in data and "server.all" in data:
92 - # return True
93 - # else:
94 - # return False
95 - if data[-7:] == "\r\n0\r\n\r\n":
91 + if data[-7:] == "\r\n0\r\n\r\n" and "Transfer-Encoding: chunked" in data[:1024]: # HTTP/1.1 response
92 return True
93 else:
94 return False
99 - # # TODO write some parser of "Transfer-Encoding: chunked"
100 - # if "Transfer-Encoding: chunked" in data[:1024]:
101 - # data = data[self.__last:]
102 - #
103 - #
104 - # print(data)
105 - # import time
106 - # time.sleep(10)
107 - # return False
108 - # supposed = 0
109 - # if length >= supposed:
110 - # return True
111 - # else:
112 - # return False
113 - #
114 - # return False
95
96 def check(self):
97 """
@@ -123,8 +103,8 @@ class Service(SocketService):
103 req = self.request.decode()
104 if not req.startswith("GET"):
105 req = "GET " + req
126 - if not req.endswith(" HTTP/1.1\r\n\r\n"):
127 - req += " HTTP/1.1\r\n\r\n"
106 + if not req.endswith(" HTTP/1.0\r\n\r\n"):
107 + req += " HTTP/1.0\r\n\r\n"
108 self.request = req.encode()
109 if self._get_data() is not None:
110 return True