Changes to SockAPI for hardening and bugfixes.