jacobschaer / python-doipclient

Pure Python ISO 13400 Client
MIT License
160 stars 52 forks source link

Optimize the time loss of reconnection #37

Closed JumaLuata closed 1 year ago

JumaLuata commented 1 year ago

Hello I often need to use the reconnect interface in my projects, but the time required for reconnection is uncertain. At present, the interface directly uses time.sleep(). My optimization is to try to connect every second within the close_delaytime. If the connection is successful, directly return . So I just need to set a larger time as RECONNECT TIMEOUT

jacobschaer commented 1 year ago

I'm not sure this is safe in all contexts. Ideally, the ECU should actually fail at the doip layer if you try too soon but I expect there's going to be some that choke if you attempt to establish a socket too fast. TCP sockets are expensive and memory tends to be limited so during cleanup I wouldn't be surprised if some vendors don't handle this gracefully.

Perhaps a keyword argument to enable polling that is off by default.

Also you should be catching subsets of Exception at worst not just bare except. Ideally, specific socket exceptions but there's probably a bunch