Implemented stream_* instead of socket_*

Implemented stream_* instead of socket_*
Implemented proper non-blocking behaviour
Prepared for TLS support
Minor consistency improvements (shorthand arrays, naming, remove dead
code)