add support for returning number of bytes written to socket