This to make it safe to call close() as many times as you wish. Right now it might be guaranteed in Socket, I think it's better to check here to avoid subtle problem in future.