Limit the io vector passed to writev()

Make it less than IOV_MAX, otherwise it will fail with EINVAL.
add lock protection in addPrepareWriter