Skip to content

Commit

Permalink
✨ kwargs
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatXliner committed Dec 31, 2024
1 parent ac99f7a commit 59f066a
Show file tree
Hide file tree
Showing 4 changed files with 531 additions and 434 deletions.
10 changes: 8 additions & 2 deletions aioudp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import asyncio
from contextlib import asynccontextmanager
from typing import AsyncIterator
from typing import Any, AsyncIterator

from aioudp import connection

Expand Down Expand Up @@ -56,6 +56,7 @@ async def connect(
host: str,
port: int,
queue_size: int | None = None,
**kwargs: Any, # noqa: ANN401
) -> AsyncIterator[connection.Connection]:
"""Connect to a UDP server.
Expand All @@ -67,7 +68,11 @@ async def connect(
port (int): The server's port number.
queue_size (int | None):
The maximum size of the message queue used internally.
Defaults to None, meaning an unlimited size
Defaults to None, meaning an unlimited size. Unless you know for sure
what you're doing, there is no need to change this value.
**kwargs:
Additional keyword arguments to pass to
:func:`asyncio.loop.create_datagram_endpoint`.
Returns:
An asynchronous iterator yielding a connection to the UDP server.
Expand All @@ -79,6 +84,7 @@ async def connect(
transport, _ = await loop.create_datagram_endpoint(
lambda: _ClientProtocol(on_connection, on_connection_lost, queue_size),
remote_addr=(host, port),
**kwargs,
)

conn = await on_connection
Expand Down
4 changes: 4 additions & 0 deletions aioudp/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ async def recv(self) -> bytes:
async def send(self, data: bytes) -> None:
"""Send a message to the connection.
The reason why this send function is `async` is due to API consistency.
There is actually no underlying `async` call so feel free to
just forgo the `await`.
.. warning::
Since this is UDP, there is no guarantee that the message will be sent
Expand Down
8 changes: 7 additions & 1 deletion aioudp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ async def serve(
port: int,
handler: Callable[[connection.Connection], Coroutine[Any, Any, None]],
queue_size: int | None = None,
**kwargs: Any, # noqa: ANN401
) -> AsyncIterator[None]:
"""Run a UDP server.
Expand All @@ -112,7 +113,11 @@ async def serve(
queue_size (int | None):
The maximum size of the message queue used internally.
Defaults to None, meaning an unlimited size
Defaults to None, meaning an unlimited size. Unless you know for sure
what you're doing, there is no need to change this value.
**kwargs:
Additional keyword arguments to pass to
:func:`asyncio.loop.create_datagram_endpoint`.
"""
loop = asyncio.get_running_loop()
Expand All @@ -121,6 +126,7 @@ async def serve(
transport, _ = await loop.create_datagram_endpoint(
lambda: _ServerProtocol(handler, queue_size),
local_addr=(host, port),
**kwargs,
)
try:
yield
Expand Down
Loading

0 comments on commit 59f066a

Please sign in to comment.