"Her husband Elkanah would say to her, 'Hannah, why are you weeping? Why don't you eat? Why are you downhearted? Don't I mean more to you than ten sons?' Once when they had finished eating and drinking in Shiloh, Hannah stood up. Now Eli the priest was sitting on his chair by the doorpost of the Lord's house. In her deep anguish Hannah prayed to the Lord, weeping bitterly." NIV translation
Elkanah did not seem to understand what Hannah was going through. Finally, she could not hold it in any longer and cried out to God.
"And she made a vow, saying, 'Lord Almighty, if you will only look on your servant's misery and remember me, and not forget your servant but give her a son, then I will give him to the Lord for all the days of his life, and no razor will ever be used on his head.'" NIV translation
Long hair was one of the characteristics of the Nazirite vow and a Nazarite was one who was set apart for God.
Hannah promised the Lord that, if He gave her a son, she would give him back to God in service.
We see her humility in this promise as it could not be easy for any woman to give up her only child. But, by humbling herself, her shame at not having a son would be removed. She would, in fact, be honored as it was quite an honor to have a son that was a priest.
"As she kept on praying to the Lord, Eli observed her mouth. Hannah was praying in her heart, and her lips were moving but her voice was not heard. Eli thought she was drunk and said to her, 'How long are you going to stay drunk? Put away your wine.'" NIV translation
As she prayed, Eli the priest was watching and accused her of being drunk because he did not understand what was happening. Evidently, he was more used to seeing drunks at the House of the Lord than seeing people actually praying to God. He was quick to make a judgment about her and we can fall into that as well. For a modern parable on this topic, check out Simon's Tears.