make write operation iterative if socket couldn't handle whole buffer from the first time