Split out socketcall processing code.

Small refactoring for #447.