1
0
mirror of https://github.com/craigerl/aprsd.git synced 2025-06-25 13:35:20 -04:00

Reconnect on socket timeout

This commit is contained in:
craigerl 2020-12-04 09:43:11 -08:00 committed by Hemna
parent 5e96706f7a
commit ecd0e8f95e

View File

@ -111,17 +111,22 @@ args = parser.parse_args()
def setup_connection(): def setup_connection():
global sock global sock
global sock_file global sock_file
try: connected = False
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) while not connected:
sock.connect((CONFIG['aprs']['host'], 14580)) try:
except Exception as e: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print("Unable to connect to APRS-IS server.\n") sock.connect((CONFIG['aprs']['host'], 14580))
print(str(e)) sock.settimeout(60)
os._exit(1) connected = True
sock_file = sock.makefile(mode='r', bufsize=0) except Exception, e:
# disable nagle algorithm print "Unable to connect to APRS-IS server.\n"
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) print str(e)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 512) # buffer size time.sleep(5)
continue
#os._exit(1)
sock_file = sock.makefile(mode='r', bufsize=0 )
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) # disable nagle algorithm
sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 512) # buffer size
def signal_handler(signal, frame): def signal_handler(signal, frame):
@ -697,15 +702,17 @@ def main(args=args):
except Exception as e: except Exception as e:
LOG.error("Error in mainline loop:") LOG.error("Error in mainline loop:")
LOG.error("%s" % str(e)) LOG.error("%s" % str(e))
LOG.error("Exiting.") if str(e) == "timed out" or str(e) == "Temporary failure in name resolution" or str(e) == "Network is unreachable":
if str(e) == "timed out":
LOG.error("Attempting to reconnect.") LOG.error("Attempting to reconnect.")
sock.shutdown(0) sock.shutdown(0)
sock.close() sock.close()
setup_connection() setup_connection()
sock.send("user %s pass %s vers https://github.com/craigerl/aprsd 2.00\n" % (user, password)) sock.send("user %s pass %s vers https://github.com/craigerl/aprsd 2.00\n" % (user, password))
continue continue
os._exit(1) #LOG.error("Exiting.")
#os._exit(1)
time.sleep(5)
continue # don't know what failed, so wait and then continue main loop again
# end while True # end while True
# tn.close() # tn.close()