def invoke_reliable(self, frame, content=None):
        if not self.synchronous:
            future = Future()
            self.request(frame, future.put_response, content)
            if not frame.method.responses: return None
            else: return future

        self.request(frame, self.queue_response, content)
        if not frame.method.responses:
            if self.use_execution_layer and frame.method_type.is_l4_command():
                self.execution_sync()
                self.completion.wait()
                if self._closed:
                    raise Closed(self.reason)
            return None
        try:
            resp = self.responses.get()
            if resp.method_type.content:
                return Message(self, resp, read_content(self.responses))
            else:
                return Message(self, resp)
        except QueueClosed, e:
            if self._closed:
                raise Closed(self.reason)
            else:
                raise e
Exemple #2
0
 def read(self, n):
     while len(self.rx_buf) < n:
         try:
             # QPID-5808: never consume more than n bytes from the socket,
             # otherwise the extra bytes are discarded.
             s = self.sock.recv(n - len(self.rx_buf))
             if self.security_layer_rx:
                 try:
                     s = self.security_layer_rx.decode(s)
                 except SASLError, e:
                     raise Closed(str(e))
         except socket.timeout:
             if self.aborted():
                 raise Closed()
             else:
                 continue
         except socket.error, e:
             if self.rx_buf != "":
                 raise e
             else:
                 raise Closed()
         if len(s) == 0:
             raise Closed()
         self.rx_buf += s
         raw.debug("RECV %r", s)
Exemple #3
0
  def invoke_method(self, frame, content = None):
    if frame.method.result:
      cmd_id = self.completion.command_id
      future = Future()
      self.futures[cmd_id] = future

    if frame.method.klass.name == "basic" and frame.method.name == "publish":
      self._flow_control_wait_condition.acquire()
      try:
        self.check_flow_control()
        self.write(frame, content)
      finally:
        self._flow_control_wait_condition.release()
    else:
      self.write(frame, content)

    try:
      # here we depend on all nowait fields being named nowait
      f = frame.method.fields.byname["nowait"]
      nowait = frame.args[frame.method.fields.index(f)]
    except KeyError:
      nowait = False

    try:
      if not nowait and frame.method.responses:
        resp = self.responses.get()
        if resp.method.content:
          content = read_content(self.responses)
        else:
          content = None
        if resp.method in frame.method.responses:
          return Message(self, resp, content)
        else:
          raise ValueError(resp)
      elif frame.method.result:
        if self.synchronous:
          fr = future.get_response(timeout=10)
          if self._closed:
            raise Closed(self.reason)
          return fr
        else:
          return future
      elif self.synchronous and not frame.method.response \
               and self.use_execution_layer and frame.method.is_l4_command():
        self.execution_sync()
        completed = self.completion.wait(timeout=10)
        if self._closed:
          raise Closed(self.reason)
        if not completed:
          self.closed("Timed-out waiting for completion of %s" % frame)
    except QueueClosed, e:
      if self._closed:
        raise Closed(self.reason)
      else:
        raise e
Exemple #4
0
 def get(self, block=True, timeout=None):
     result = BaseQueue.get(self, block, timeout)
     if result == Queue.END:
         # this guarantees that any other waiting threads or any future
         # calls to get will also result in a Closed exception
         self.put(Queue.END)
         raise Closed(self.error)
     else:
         return result
 def write(self, frame, content=None):
     if self._closed:
         raise Closed(self.reason)
     frame.channel = self.id
     self.outgoing.put(frame)
     if (isinstance(frame, (Method, Request)) and content == None
             and frame.method_type.content):
         content = Content()
     if content != None:
         self.write_content(frame.method_type.klass, content)
Exemple #6
0
 def flush(self):
     self.sock_lock.acquire()
     try:
         if self.security_layer_tx:
             try:
                 cipher_buf = self.security_layer_tx.encode(self.tx_buf)
             except SASLError, e:
                 raise Closed(str(e))
             self._write(cipher_buf)
         else:
Exemple #7
0
 def connection_start(self, ch, start):
   mech_list = ""
   for mech in start.mechanisms:
     if (not self.acceptableMechanisms) or mech in self.acceptableMechanisms:
       mech_list += str(mech) + " "
   mech = None
   initial = None
   try:
     mech, initial = self.sasl.start(mech_list)
   except Exception, e:
     raise Closed(str(e))
Exemple #8
0
 def _write(self, buf):
     while buf:
         try:
             n = self.sock.send(buf)
         except socket.timeout:
             if self.aborted():
                 raise Closed()
             else:
                 continue
         raw.debug("SENT %r", buf[:n])
         buf = buf[n:]
Exemple #9
0
 def connection_close(self, ch, close):
   self.connection.close_code = (close.reply_code, close.reply_text)
   ch.connection_close_ok()
   raise Closed(close.reply_text)
Exemple #10
0
 def connection_secure(self, ch, secure):
   resp = None
   try:
     resp = self.sasl.step(secure.challenge)
   except Exception, e:
     raise Closed(str(e))