'Clean up when the connection has been lost.
When the loss of connection was initiated by the client due to a
timeout, the L{_timedOut} flag will be set.  When it was initiated by
the client due to an error in the server greeting, L{_greetingError}
will be set to the server response minus the status indicator.
@type reason: L{Failure <twisted.python.failure.Failure>}
@param reason: The reason the connection was terminated.'

def connectionLost(self, reason):

    if (self.timeout > 0):
        self.setTimeout(None)
    if self._timedOut:
        reason = error.TimeoutError()
    elif self._greetingError:
        reason = ServerErrorResponse(self._greetingError)
    d = []
    if (self._waiting is not None):
        d.append(self._waiting)
        self._waiting = None
    if (self._blockedQueue is not None):
        d.extend([deferred for (deferred, f, a) in self._blockedQueue])
        self._blockedQueue = None
    for w in d:
        w.errback(reason)
