Guys do it all the time from the bike. Women, not having the proper anatomy to keep things away from themselves and the bike, are generally more civilized about it and pee breaks (where in it would be a VERY big breach of ettiquite to attack or otherwise try to change the outcome of the race) are called. Everyone stops, and discretely as possible does what is necessary at the side of the road.
I have heard of women just letting it go while riding, which seems more acceptable in the high level tri community, but is generally frowned upon in pack racing..... I witnessed a woman who was able to pull back her short leg just a little and let it flow (she must have practiced this move, because she did not get it on herself).... but she did it at the line up for a crit, right on the main street of the little town we were racing in

I thought it was pretty tactless, even if no one outside of the race could see her do it.