Write to the stream
the stream to write to
the data to write
the length of the data to write
the write flags
the number of bytes written, or an error code