'Generic method called when the attempts to connect failed. It basically
cleans everything it can: call connectionFailed, stop read and write,
delete socket related members.'

def failIfNotConnected(self, err):

    if (self.connected or self.disconnected or (not hasattr(self, 'connector'))):
        return
    self._stopReadingAndWriting()
    try:
        self._closeSocket(True)
    except AttributeError:
        pass
    else:
        self._collectSocketDetails()
    self.connector.connectionFailed(failure.Failure(err))
    del self.connector
