diff --git a/scripts/n2n-ctl b/scripts/n2n-ctl index 2a26220..ab59f36 100755 --- a/scripts/n2n-ctl +++ b/scripts/n2n-ctl @@ -19,6 +19,7 @@ class JsonUDP(): self.key = None self.debug = False self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + self.sock.settimeout(1) def _next_tag(self): tagstr = str(self.tag) @@ -239,7 +240,12 @@ def main(): rpc.debug = args.debug rpc.key = args.key - result = func(rpc, args) + try: + result = func(rpc, args) + except socket.timeout as e: + print(e) + exit(1) + print(result) diff --git a/scripts/n2n-httpd b/scripts/n2n-httpd index 662d9b6..9211915 100755 --- a/scripts/n2n-httpd +++ b/scripts/n2n-httpd @@ -34,6 +34,7 @@ class JsonUDP(): self.key = None self.debug = False self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + self.sock.settimeout(1) def _next_tag(self): tagstr = str(self.tag) @@ -187,6 +188,9 @@ function rows2table(id, columns, data) { function do_get(url, id, handler, handler_param) { fetch(url) .then(function (response) { + if (!response.ok) { + throw new Error('Fetch got ' + response.status) + } return response.json(); }) .then(function (data) { @@ -205,6 +209,9 @@ function do_get(url, id, handler, handler_param) { function do_post(url, body, id, handler, handler_param) { fetch(url, {method:'POST', body: body}) .then(function (response) { + if (!response.ok) { + throw new Error('Fetch got ' + response.status) + } return response.json(); }) .then(function (data) { @@ -438,6 +445,9 @@ class SimpleHandler(http.server.BaseHTTPRequestHandler): self._simplereply(HTTPStatus.BAD_REQUEST, 'Bad Command') return + except socket.timeout as e: + self._simplereply(HTTPStatus.REQUEST_TIMEOUT, str(e)) + return self._replyjson(data) return