Generalized tcp transport implementation to support TLS.

Signed-off-by: Kirill Mikhailov <kirill.mikhailov@gmail.com>