When to quit poker for good: When I am DEAD
When to quit playing in the middle of a session: NEVER
When to quit playing for a few days: When your bad luck brings your so many bad beats and bad cards that you can't help but go on tilt.
For me, that is when I automatically think "Don't lose this hand," when I enter a pot. It's way too much like stepping to the plate while thinking, "don't strike out, don't strike out". It ruins my ability to focus on the task at hand, and at that point continuing to play would only make things worse.
Of course if you are not having fun, you should stop playing. It is not always fun to play, even when you still love the game and have fun playing most of the time.