'Close the connection at the next available opportunity.
Call this to cause this FileDescriptor to lose its connection.  It will
first write any data that it has buffered.
If there is data buffered yet to be written, this method will cause the
transport to lose its connection as soon as it\'s done flushing its
write buffer.  If you have a producer registered, the connection won\'t
be closed until the producer is finished. Therefore, make sure you
unregister your producer when it\'s finished, or the connection will
never close.'

def loseConnection(self, _connDone=failure.Failure(main.CONNECTION_DONE)):

    if (self.connected and (not self.disconnecting)):
        if self._writeDisconnected:
            self.stopReading()
            self.stopWriting
            self.connectionLost(_connDone)
        else:
            self.stopReading()
            self.startWriting()
            self.disconnecting = 1
