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:
parent
5e96706f7a
commit
ecd0e8f95e
@ -111,16 +111,21 @@ args = parser.parse_args()
|
|||||||
def setup_connection():
|
def setup_connection():
|
||||||
global sock
|
global sock
|
||||||
global sock_file
|
global sock_file
|
||||||
|
connected = False
|
||||||
|
while not connected:
|
||||||
try:
|
try:
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
sock.connect((CONFIG['aprs']['host'], 14580))
|
sock.connect((CONFIG['aprs']['host'], 14580))
|
||||||
except Exception as e:
|
sock.settimeout(60)
|
||||||
print("Unable to connect to APRS-IS server.\n")
|
connected = True
|
||||||
print(str(e))
|
except Exception, e:
|
||||||
os._exit(1)
|
print "Unable to connect to APRS-IS server.\n"
|
||||||
sock_file = sock.makefile(mode='r', bufsize=0)
|
print str(e)
|
||||||
# disable nagle algorithm
|
time.sleep(5)
|
||||||
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
|
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
|
sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 512) # buffer size
|
||||||
|
|
||||||
|
|
||||||
@ -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()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user