Sockets secure implementations

Rebased on `master`.
nit: rather than declaring this as "throws", add a try / catch inside. There's no reason it actually should ever throw, and it uglifies all call-sites.