break
packet = self.buffer[2:frameend]
self.buffer = self.buffer[frameend + 2 :]
+ if len(packet) < 2: # frameend comes too early
+ log.warning("Packet too short: %s", packet)
+ break
if proto_of_message(packet) == LOGIN.PROTO:
- self.imei = parse_message(packet).imei
- log.info(
- "LOGIN from fd %d (IMEI %s)", self.sock.fileno(), self.imei
- )
+ msg = parse_message(packet)
+ if isinstance(msg, LOGIN): # Can be unparseable
+ self.imei = msg.imei
+ log.info(
+ "LOGIN from fd %d (IMEI %s)",
+ self.sock.fileno(),
+ self.imei,
+ )
msgs.append((when, self.addr, packet))
return msgs
except OSError as e:
log.error(
"Sending to fd %d (IMEI %s): %s",
- self.sock.fileno,
+ self.sock.fileno(),
self.imei,
e,
)
else:
log.debug("Stray event: %s on socket %s", fl, sk)
# poll queue consumed, make changes now
- for fd in tostop:
- poller.unregister(fd) # type: ignore
- clients.stop(fd)
for zmsg in tosend:
zpub.send(
Bcast(
)
log.debug("Sending to the client: %s", zmsg)
clients.response(zmsg)
+ for fd in tostop:
+ poller.unregister(fd) # type: ignore
+ clients.stop(fd)
for clntsock, clntaddr in topoll:
fd = clients.add(clntsock, clntaddr)
poller.register(fd, flags=zmq.POLLIN)