zestyping / openpixelcontrol

A simple stream protocol for controlling arrays of RGB lights.
http://openpixelcontrol.org/
353 stars 103 forks source link

avoid closing the connection for zero-message-length packages. #36

Closed simon-budig closed 7 years ago

simon-budig commented 7 years ago

When the client sends a (useless) package with a zero lenght (i.e. no message data beyond the header) the opc-server inadvertedly closes the connection.

This patch fixes this behaviour, by explicitely checking if the recv() returned 0 (in this case the remote really has closed the connection) and setting "received" to -1 explicitely then.

zestyping commented 7 years ago

Hi Simon, thanks for catching this bug!

I've investigated the issue, and committed a different fix in 5d8da39 that I think is better: it ensures that we never attempt to recv zero bytes, and prevents the server from stalling (waiting for data that it doesn't need) when the header says there are zero pixels.