Skip to content

Commit a0ee3d6

Browse files
committed
Rationalize error handling when sending data
1 parent 78449ef commit a0ee3d6

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

zeroconf.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ def current_time_millis():
160160
# Exceptions
161161

162162

163+
class Error(Exception):
164+
pass
165+
166+
163167
class NonLocalNameException(Exception):
164168
pass
165169

@@ -1512,15 +1516,10 @@ def handle_query(self, msg, addr, port):
15121516
def send(self, out, addr=_MDNS_ADDR, port=_MDNS_PORT):
15131517
"""Sends an outgoing packet."""
15141518
packet = out.packet()
1515-
try:
1516-
while packet:
1517-
bytes_sent = self._socket.sendto(packet, 0, (addr, port))
1518-
if bytes_sent < 0:
1519-
break
1520-
packet = packet[bytes_sent:]
1521-
except Exception as e: # TODO stop catching all Exceptions
1522-
# Ignore this, it may be a temporary loss of network connection
1523-
log.exception('Unknown error, possibly benign: %r', e)
1519+
bytes_sent = self._socket.sendto(packet, 0, (addr, port))
1520+
if bytes_sent != len(packet):
1521+
raise Error(
1522+
'Should not happen, sent %d out of %d bytes' % (bytes_sent, len(packet)))
15241523

15251524
def close(self):
15261525
"""Ends the background threads, and prevent this instance from

0 commit comments

Comments
 (0)