python-luxtronik icon indicating copy to clipboard operation
python-luxtronik copied to clipboard

Fix reading from socket

Open gerw opened this issue 1 year ago • 3 comments

Sometimes self._socket.recv returns fewer bytes than requested (for me, this happens sometimes over VPN). The current try-check in read_* is not helpful, since it just skews up the readings, e.g., if we only get 2 bytes for parameter 1, the remaining 2 bytes are then feed into parameter 2 and so on...

The current fix assures that the correct amount of bytes is read by introducing a new function _read_bytes().

gerw avatar Jul 22 '24 06:07 gerw

Coverage

Coverage Report
FileStmtsMissCoverMissing
luxtronik
   __init__.py18413328%39–51, 73–77, 80, 84–89, 93–97, 108–111, 119–121, 128–130, 137–139, 146–148, 157, 165–167, 170–173, 176–179, 182–198, 201–211, 214–226, 229–239, 243–245, 249–265, 269–270, 274–275, 286–288, 291, 294, 297, 300, 303–306, 309–312
   __main__.py21210%3–49
   datatypes.py275199%82
   discover.py403415%21–69
luxtronik/scripts
   dump_changes.py43430%7–85
   dump_luxtronik.py26260%6–52
TOTAL67525862% 

Tests Skipped Failures Errors Time
122 0 :zzz: 0 :x: 0 :fire: 0.762s :stopwatch:

github-actions[bot] avatar Jul 22 '24 06:07 github-actions[bot]

What will happen if we request to read more data that is provided by the socket? Can thete be any kind of dead lock in this way?

kbabioch avatar Jul 22 '24 07:07 kbabioch

Good point. I think one should check that at least one byte is returned, see https://docs.python.org/3/library/socket.html#socket.socket.recv.

In case nothing is returned by recv, the connection is lost. What to do in this case? Raise some error? Which one?

gerw avatar Jul 22 '24 08:07 gerw