Fix response handling working on wrong buffer.

For segmented responses, we have to work on the full buffer, not only
the last part.
Restructure response handling code.

Make handling the response easier by separating the parsing from the
message management. Also avoid permanent retries in case no data could
be read.