gatzka / cio

An ANSI C Conformant I/O Library.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fix socket_echo example.

gatzka opened this issue · comments

After some bytes were received, the pointer to that data is retrieved by cio_read_buffer_get_read_ptr().
This pointer is used directly to initialize the write buffer.
Afterwards, the data is "consumed", which means the read_buffer is allowed to overwrite it.

This is a bug because reading should be done only when all of the received data is actually written.
So the number of bytes read must be saved in the client structure and write_some must be called until all that data has been written. Only then it is allowed to call read_some again.