'Write the closing stream tag and destroy the underlaying socket. Used internally.'

def _stream_close(self, unregister=1):

    if (self._stream_state >= STREAM__CLOSED):
        return
    self.set_stream_state(STREAM__CLOSING)
    self.sendnow('</stream:stream>')
    self.set_stream_state(STREAM__CLOSED)
    self.push_queue()
    self._owner.flush_queues()
    if unregister:
        self._owner.unregistersession(self)
    self._destroy_socket()
