fixed a possible NullReferenceException when check there is any data to be sent during the socket is being closed