use IOVEC writes for performance, improve reference counting and fix a number of corner cases

Change-Id: I04db57e7cd6809263f1e70dc90f3ea5c440b7862
Signed-off-by: Alessandro Salvatori <sandr8@gmail.com>
Merge "use IOVEC writes for performance, improve reference counting and fix a number of corner cases"