Fix close procedure in the net module

This improves the error messages in the net module. It also makes sure `SSL_shutdown` is called before closing the underlying socket. Requesting comments...