def handle_reply (self, qid, error, result): if self.debug: LOG ('<=', self.conn.fd, qid, error, result) thread = self.pending_requests.get (qid, None) if thread is None: LOG ('unknown reply', qid) else: try: coro.schedule (thread, (error, result)) except coro.ScheduleError: # something (presumably a timeout?) already woke this guy up LOG ('handle_reply', 'ScheduleError', (error, result))
def handle_reply(self, qid, error, result): if self.debug: LOG('<=', self.conn.fd, qid, error, result) thread = self.pending_requests.get(qid, None) if thread is None: LOG('unknown reply', qid) else: try: coro.schedule(thread, (error, result)) except coro.ScheduleError: # something (presumably a timeout?) already woke this guy up LOG('handle_reply', 'ScheduleError', (error, result))
def reply_thread(self): try: while 1: #W ('reply thread: waiting for any replies\n') frame, props, data = self.consumer.pop() cid = props['correlation-id'] #W ('reply thread: got one: %r\n' % (cid,)) probe = self.pending.get(cid, None) if probe is None: W('dropping unknown correlation-id: %r' % (cid, )) else: del self.pending[cid] coro.schedule(probe, (frame, props, data)) except: W('exiting rpc reply thread\n') for k, v in self.pending.iteritems(): v.raise_exception(RPC_Client_Error)
def reply_thread (self): try: while 1: # W ('reply thread: waiting for any replies\n') frame, props, data = self.consumer.pop() cid = props['correlation-id'] # W ('reply thread: got one: %r\n' % (cid,)) probe = self.pending.get (cid, None) if probe is None: W ('dropping unknown correlation-id: %r' % (cid,)) else: del self.pending[cid] coro.schedule (probe, (frame, props, data)) except: W ('exiting rpc reply thread\n') for k, v in self.pending.iteritems(): v.raise_exception (RPC_Client_Error)
def handle_request (self, request): sid, c = self.find_session (request) # The sid=='None' test is temporary hack, can probably remove it if (not sid) or (sid=='None'): sid = self.gen_session_id() if c and c.isAlive(): # is c already running? # hack, must grok this coro.schedule (c, request) request._done = 1 else: # login c = coro.new (self.function, self, request, sid) # Wdy, DD-Mon-YYYY HH:MM:SS GMT expires = time.strftime ('%a, %d-%b-%Y 00:00:00 GMT', time.gmtime (int (time.time()) + self.expires_delta)) request['Set-Cookie'] = 'session=%s; path=/; expires=%s' % (sid, expires) # hack, must grok this request._done = 1 c.start()
def receive_loop(self): """receive_loop(self) -> None This is the receive thread. It runs forever processing messages off the socket. """ exc_type = exc_data = exc_tb = None while 1: try: packet, sequence_number = self._receive_packet() except Stop_Receiving_Exception: break except: exc_type, exc_data, exc_tb = sys.exc_info() break if self.ignore_first_packet: # This can only happen during the beginning of the # connection, so we don't need to worry about multiple # threads since there can be only 1. assert(len(self.tmc.processing_threads)<=1) self.debug.write(ssh_debug.DEBUG_1, 'receive_thread: ignoring first packet') self.ignore_first_packet = False continue message_type = ord(packet[0]) self.debug.write(ssh_debug.DEBUG_2, 'receive_thread: message_type=%i', (message_type,)) try: self._handle_packet(message_type, packet, sequence_number) except Stop_Receiving_Exception: break except: exc_type, exc_data, exc_tb = sys.exc_info() break # XXX: We should check here for SSH_MSG_KEXINIT. # If we see it, then we should lock down and prevent any # other messages other than those for the key exchange. #if message_type == SSH_MSG_KEXINIT: # Wake up anyone waiting for their message. if self.tmc.processing_messages.has_key(message_type): thread = self.tmc.processing_messages[message_type] try: self.debug.write(ssh_debug.DEBUG_2, 'receive_thread: waiting thread waking up') coro.schedule(thread, (message_type, packet)) except coro.ScheduleError: # Coro already scheduled. pass self.tmc.remove(thread) self.closed = True self.transport.close() self._receive_thread = None if exc_data is None: exc_data = SSH_Protocol_Error('Receive thread shut down.') # Wake up anyone still waiting for messages. for thread in self.tmc.processing_messages.values(): try: # XXX: Too bad can't pass in traceback. thread.raise_exception(exc_data, force=False) except coro.ScheduleError: # Coro already scheduled. pass self.tmc.clear()
def receive_loop(self): """receive_loop(self) -> None This is the receive thread. It runs forever processing messages off the socket. """ exc_type = exc_data = exc_tb = None while True: try: packet, sequence_number = self._receive_packet() except Stop_Receiving_Exception: break except: exc_type, exc_data, exc_tb = sys.exc_info() break if self.ignore_first_packet: # This can only happen during the beginning of the # connection, so we don't need to worry about multiple # threads since there can be only 1. assert (len(self.tmc.processing_threads) <= 1) self.debug.write(ssh_debug.DEBUG_1, 'receive_thread: ignoring first packet') self.ignore_first_packet = False continue message_type = ord(packet[0]) self.debug.write(ssh_debug.DEBUG_2, 'receive_thread: message_type=%i', (message_type, )) try: self._handle_packet(message_type, packet, sequence_number) except Stop_Receiving_Exception: break except: exc_type, exc_data, exc_tb = sys.exc_info() break # XXX: We should check here for SSH_MSG_KEXINIT. # If we see it, then we should lock down and prevent any # other messages other than those for the key exchange. # if message_type == SSH_MSG_KEXINIT: # Wake up anyone waiting for their message. if message_type in self.tmc.processing_messages: thread = self.tmc.processing_messages[message_type] try: self.debug.write( ssh_debug.DEBUG_2, 'receive_thread: waiting thread waking up') coro.schedule(thread, (message_type, packet)) except coro.ScheduleError: # Coro already scheduled. pass self.tmc.remove(thread) self.closed = True self.transport.close() self._receive_thread = None if exc_data is None: exc_data = SSH_Protocol_Error('Receive thread shut down.') # Wake up anyone still waiting for messages. for thread in self.tmc.processing_messages.values(): try: # XXX: Too bad can't pass in traceback. thread.raise_exception(exc_data, force=False) except coro.ScheduleError: # Coro already scheduled. pass self.tmc.clear()