def recv_tracer_event(sck): """ Reads an event off the socket. """ try: return next(get_events_from_socket(sck)) except StopIteration: return {}
def recv_tracer_event(sck): """ Reads an event off the socket. """ try: return next(get_events_from_socket(sck, green=True)) except StopIteration: return {}
def read_event(self, conn): """ Reads a single message. """ try: return next(get_events_from_socket(conn, green=True)) except StopIteration: return {}
def handle_tracer(self, conn, addr): """ Handles new connections from the tracers. """ uuid = None local_pid, pause_signal = 0, 0 message = '' log.info('New tracer request from (%s, %d)' % addr) try: start_event = None with Timeout(self.auth_timeout, False): start_event = self.read_event(conn) if not start_event: # No start_event was ever recieved because we timed out. log.info('No start message was sent from (%s, %d)' % addr) message = 'No start event received' else: try: uuid, (local_pid, pause_signal) \ = self.validate_start_event(start_event, addr) except AuthenticationFailed as a: message = a.message if message: # If we have an error, we need to report that back to the # trace so that it may raise a QdbAuthenticationError in the # user's code. auth_failed_dict = { 'e': 'error', 'p': { 'type': 'auth', 'data': '', } } auth_failed_dict['p']['data'] = message err_msg = pickle.dumps(auth_failed_dict) conn.sendall(pack('>i', len(err_msg))) conn.sendall(err_msg) log.warn('Invalid start message from (%s, %d)' % addr) return log.info('Assigning stream from (%s, %d) to session %s' % (addr[0], addr[1], uuid)) if not self.session_store.attach_tracer( uuid, conn, local_pid, pause_signal ): return # No browser so the attach failed. for event in get_events_from_socket(conn, green=True): # Send the serialized event back to the browser. self.session_store.send_to_clients(uuid, event=event) # When this is done, we should kill off the client connections too. self.session_store.slaughter(uuid) except socket.error: log.info('Stream from %s to session %s closed unexpectedly' % (addr, uuid)) return finally: log.info('Closing stream from %s to session %s' % (addr, uuid)) # The session_store should close this, but closing it again here # assures that it is closed even if it never makes it to the # session_store. conn.close()
def handle_tracer(self, conn, addr): """ Handles new connections from the tracers. """ uuid = None local_pid, pause_signal = 0, 0 message = '' log.info('New tracer request from (%s, %d)' % addr) try: start_event = None with Timeout(self.auth_timeout, False): start_event = self.read_event(conn) if not start_event: # No start_event was ever recieved because we timed out. log.info('No start message was sent from (%s, %d)' % addr) message = 'No start event received' else: try: uuid, (local_pid, pause_signal) \ = self.validate_start_event(start_event, addr) except AuthenticationFailed as a: message = a.message if message: # If we have an error, we need to report that back to the # trace so that it may raise a QdbAuthenticationError in the # user's code. auth_failed_dict = { 'e': 'error', 'p': { 'type': 'auth', 'data': '', } } auth_failed_dict['p']['data'] = message err_msg = pickle.dumps(auth_failed_dict) conn.sendall(pack('>i', len(err_msg))) conn.sendall(err_msg) log.warn('Invalid start message from (%s, %d)' % addr) return log.info('Assigning stream from (%s, %d) to session %s' % (addr[0], addr[1], uuid)) if not self.session_store.attach_tracer(uuid, conn, local_pid, pause_signal): return # No browser so the attach failed. for event in get_events_from_socket(conn, green=True): # Send the serialized event back to the browser. self.session_store.send_to_clients(uuid, event=event) # When this is done, we should kill off the client connections too. self.session_store.slaughter(uuid) except socket.error: log.info('Stream from %s to session %s closed unexpectedly' % (addr, uuid)) return finally: log.info('Closing stream from %s to session %s' % (addr, uuid)) # The session_store should close this, but closing it again here # assures that it is closed even if it never makes it to the # session_store. conn.close()