Fix socket receive function

read() on socket may return without filling the complete buffer - even
in non-error conditions. Instead use recv() with MSG_WAITALL.