[runtime] Rewrite io-layer process code to reduce duplication and make it conform to the mono coding conventions.