how do you know when all data has been written to a socket?