Stop TLS sockets being closed when attaching

When calling attach_socket, the response is garbage collected, which triggers a close method on the file object, closing the socket.

This stops the response from being garbage collected until we've finished with the underlying socket.

Fixes #350