def receive_once(self): """ block until messages are read off of socket @return: list of newly received messages @rtype: [Msg] @raise TransportException: if unable to receive message due to error """ sock = self.socket if sock is None: raise TransportException("connection not initialized") b = self.read_buff msg_queue = [] p = self.protocol try: sock.setblocking(1) while not msg_queue and not self.done and not is_shutdown(): if b.tell() >= 4: p.read_messages(b, msg_queue, sock) if not msg_queue: self.stat_bytes += recv_buff(sock, b, p.buff_size) self.stat_num_msg += len(msg_queue) #STATS # set the _connection_header field for m in msg_queue: m._connection_header = self.header # #1852: keep track of last latched message if self.is_latched and msg_queue: self.latch = msg_queue[-1] return msg_queue except DeserializationError as e: rospyerr(traceback.format_exc()) raise TransportException( "receive_once[%s]: DeserializationError %s" % (self.name, str(e))) except TransportTerminated as e: raise #reraise except ServiceException as e: raise except Exception as e: rospyerr(traceback.format_exc()) raise TransportException("receive_once[%s]: unexpected error %s" % (self.name, str(e))) return retval
self.latch = msg_queue[-1] return msg_queue except DeserializationError, e: rospyerr(traceback.format_exc()) raise TransportException( "receive_once[%s]: DeserializationError %s" % (self.name, str(e))) except TransportTerminated, e: raise #reraise except ServiceException, e: raise except Exception, e: rospyerr(traceback.format_exc()) raise TransportException("receive_once[%s]: unexpected error %s" % (self.name, str(e))) return retval def receive_loop(self, msgs_callback): """ Receive messages until shutdown @param msgs_callback: callback to invoke for new messages received @type msgs_callback: fn([msg]) """ # - use assert here as this would be an internal error, aka bug logger.debug("receive_loop for [%s]", self.name) try: try: while not self.done and not is_shutdown(): msgs = self.receive_once() if not self.done and not is_shutdown():