Sockets secure implementations

Rebased on `master`.
Necessary?