'Perform binding. Use provided domain name (if not provided).'

def Bind(self, domain=None):

    while ((self.bound is None) and self._owner.Process(1)):
        pass
    if self.sasl:
        xmlns = NS_COMPONENT_1
    else:
        xmlns = None
    self.bindresponse = None
    ttl = dispatcher.DefaultTimeout
    self._owner.RegisterHandler('bind', self.BindHandler, xmlns=xmlns)
    self._owner.send(Protocol('bind', attrs={'name': domain}, xmlns=NS_COMPONENT_1))
    while ((self.bindresponse is None) and self._owner.Process(1) and (ttl > 0)):
        ttl -= 1
    self._owner.UnregisterHandler('bind', self.BindHandler, xmlns=xmlns)
    resp = self.bindresponse
    if (resp and resp.getAttr('error')):
        self.DEBUG(('Binding    failed:    %s.' % resp.getAttr('error')), 'error')
    elif resp:
        self.DEBUG('Successfully    bound.', 'ok')
        return 'ok'
    else:
        self.DEBUG('Binding    failed:    timeout    expired.', 'error')
        return ''
