Skip to content

Commit

Permalink
Merge c141f7e into f53b714
Browse files Browse the repository at this point in the history
  • Loading branch information
icgood committed May 15, 2021
2 parents f53b714 + c141f7e commit 2443e1a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
license = f.read()

setup(name='swim-protocol',
version='0.3.7',
version='0.3.8',
author='Ian Good',
author_email='ian@icgood.net',
description='SWIM protocol implementation for exchanging cluster '
Expand Down
22 changes: 22 additions & 0 deletions swimprotocol/udp/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import annotations

import asyncio
import logging
from asyncio import BaseTransport, Condition, DatagramProtocol, \
DatagramTransport
from collections import deque
Expand All @@ -15,6 +16,8 @@

__all__ = ['SwimProtocol']

_log = logging.getLogger(__name__)


class SwimProtocol(DatagramProtocol, IO):
"""Implements :class:`~asyncio.DatagramProtocol` and
Expand Down Expand Up @@ -60,6 +63,25 @@ def datagram_received(self, data: bytes, addr: tuple[str, int]) -> None:
return
asyncio.create_task(self._push(packet))

def error_received(self, exc: Exception) -> None:
"""Called when a UDP send or receive operation fails.
See Also:
:meth:`asyncio.DatagramProtocol.error_received`
"""
_log.exception('UDP operation failed')

def connection_lost(self, exc: Optional[Exception]) -> None:
"""Called when the UDP socket is closed.
See Also:
:meth:`asyncio.BaseProtocol.connection_lost`
"""
_log.error('UDP connection lost: %s', exc)
self._transport = None

async def _push(self, packet: Packet) -> None:
async with self._queue_lock:
self._queue.append(packet)
Expand Down

0 comments on commit 2443e1a

Please sign in to comment.