Dealing with short writes. A more clean implementation of SynchronizeStreams to give a higher guarantee that all data will be written before the connections are closed.