summaryrefslogtreecommitdiffstats
path: root/src/ogClient.py
diff options
context:
space:
mode:
authorRoberto Hueso Gomez <robertohueso96@gmail.com>2020-04-14 11:31:22 +0200
committerRoberto Hueso Gomez <robertohueso96@gmail.com>2020-04-14 11:31:22 +0200
commitd6c5f2443a5e0104bd8eb78454e7cd6d9f765cf0 (patch)
treeb81dcb4b9d95d8f8e76fb957b7d511e23826ce77 /src/ogClient.py
parentf56065a4385c8c97dfe477fe0f580b2077ac6195 (diff)
Avoid connection status infinite print loop
This patch avoids infinite writting of connection status messages to the log.
Diffstat (limited to 'src/ogClient.py')
-rw-r--r--src/ogClient.py24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/ogClient.py b/src/ogClient.py
index 3e6a0e4..324aacf 100644
--- a/src/ogClient.py
+++ b/src/ogClient.py
@@ -31,6 +31,7 @@ class ogClient:
self.port = port
self.mode = mode
self.ogrest = ogRest(self.mode)
+ self.logged = False
def get_socket(self):
return self.sock
@@ -39,7 +40,9 @@ class ogClient:
return self.state
def connect(self):
- print ('connecting')
+ if not self.logged:
+ print('connecting')
+ self.logged = True
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.setblocking(0)
self.state = State.CONNECTING
@@ -49,14 +52,13 @@ class ogClient:
try:
self.sock.connect((self.ip, self.port))
+ self.logged = False
except socket.error as err:
if err.errno == errno.EINPROGRESS:
return
elif err.errno == errno.ECONNREFUSED:
return
- print ('Error connect ' + str(err))
-
def send(self, msg):
self.sock.send(bytes(msg, 'utf-8'))
return len(msg)
@@ -64,12 +66,17 @@ class ogClient:
def connect2(self):
try:
self.sock.connect((self.ip, self.port))
+ self.logged = False
except socket.error as err:
if err.errno == errno.EISCONN:
- print ('connected')
+ if not self.logged:
+ print('connected')
+ self.logged = True
self.state = State.RECEIVING
else:
- print ('connection refused, retrying...')
+ if not self.logged:
+ print('connection refused, retrying...')
+ self.logged = True
self.state = State.CONNECTING
self.sock.close()
self.connect()
@@ -77,9 +84,12 @@ class ogClient:
def receive(self):
try:
data = self.sock.recv(1024).decode('utf-8')
+ self.logged = False
except socket.error as err:
data = ''
- print ('Error3 ' + str(err))
+ if not self.logged:
+ print('Error3 ' + str(err))
+ self.logged = True
if len(data) == 0:
self.state = State.CONNECTING
@@ -133,4 +143,4 @@ class ogClient:
elif state == State.RECEIVING and sock in readable:
self.receive()
else:
- print ('bad state' + str(state))
+ print('bad state' + str(state))