Refactor to ease overwriting socket operations

This PR refactors some of the code in order to ease extending the base classes and overwrite the actual socket operations.

Needed in particular for https://github.com/clue/socket-react