Serial port flush fuction.

Using arduino latest ide, i lost many hours figuring why flush was not clearing all serial data.

Why are you dumping random amounts of unprocessed data, anyway? It seems far better to process all the data, in my opinion. Or make the sender quit sending if you don't want to deal with it anymore.