I understand your shock at how you responded - it's not your usual mode of communication. But consider that the person at whom you exploded sounds as if he would not have responded to much less than that.
In future the only thing I could think of doing differently would be to actually say, "I'm sorry, xxxxx, but I'm no longer able to talk about [whatever is being discussed]. I really don't want to become rude, so I'm extricating myself from this. I hope you don't mind, but even if you do, the conversation is over."
(To be honest, I probably couldn't even take my own advice, and would undoubtedly end up doing what you did, but at least it's an idea.)
no subject
In future the only thing I could think of doing differently would be to actually say, "I'm sorry, xxxxx, but I'm no longer able to talk about [whatever is being discussed]. I really don't want to become rude, so I'm extricating myself from this. I hope you don't mind, but even if you do, the conversation is over."
(To be honest, I probably couldn't even take my own advice, and would undoubtedly end up doing what you did, but at least it's an idea.)