fixed an issue cuaisng router to die

- router should not die when an error happens when connecting to HW
+ install will restart changed network interfaces
This commit is contained in:
2021-03-26 09:30:45 +01:00
parent 53af769c3f
commit a9c1c38d51
3 changed files with 15 additions and 7 deletions

View File

@ -1,3 +1,4 @@
import sys
import socket
from select import select
from serial import serial_for_url
@ -98,7 +99,7 @@ class AcceptHandler:
:param: port offered port for routing
:param: addr where to route
:param: iocls the io ahndler class, currently TcpHandler or SerialHandler
:param: iocls the io handler class, currently TcpHandler or SerialHandler
:param: maxcount the maximal number of concurrent connections. defauls to 1
as a side effect, if the destination is a web server, the traffic
are serialized (only one connection at a time), which helps for
@ -140,8 +141,13 @@ class AcceptHandler:
if not self.available:
self.pending += 1
return
client, addr = self.socket.accept()
handler = self.iocls(client, self)
try:
client, addr = self.socket.accept()
handler = self.iocls(client, self)
except Exception as e:
print('ERROR creating %s(%r)' % (self.iocls.__name__, self.addr))
client.close()
return
self.readers[client.fileno()] = handler.request
self.readers[handler.fno] = handler.reply
self.available -= 1