Warship foils pirate attack