Fix write

the function returns the number of messages writen, not the
amount of data written.