Skip to content

Commit 51ff443

Browse files
[PATCH] Applied changes from review (- WIP PR #348 -)
Changes in file multicast/env.py: * minor tweaks and related work Changes in file multicast/recv.py: * RECV implementation now honors new environment variable for muticast message buffering (- WIP #264 -) * related work Changes in file multicast/send.py: * SEND implementation now honors new environment variable for muticast message buffering (- WIP #264 -) * related work
1 parent d29014e commit 51ff443

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

multicast/env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ def load_config() -> dict:
862862
ttl = load_TTL()
863863
buffer_size = load_buffer_size()
864864
groups_str = os.getenv("MULTICAST_GROUPS", "")
865-
bind_addr = os.getenv("MULTICAST_BIND_ADDR", group) # skipcq: PYL-W1508
865+
bind_addr = os.getenv("MULTICAST_BIND_ADDR", str(group)) # skipcq: PYL-W1508
866866
# Process and validate groups
867867
groups = set()
868868
if groups_str:

multicast/recv.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,17 @@ def tryrecv(msgbuffer, chunk, sock):
310310
311311
Will try to listen on the given socket directly into the given chunk for decoding.
312312
If the read into the chunk results in content, the chunk will be decoded and appended
313-
to the caller-instantiated `msgbuffer`, which is a collection of strings (or None).
313+
to the caller-instantiated `msgbuffer`, which is a collection of utf8 strings (or None).
314314
After decoding, `chunk` is zeroed for memory efficiency and security. Either way the
315315
message buffer will be returned.
316316
317317
Tries to receive data without blocking and appends it to the message buffer.
318318
319+
Individual chunk sizes are controled by the module attribute `_MCAST_DEFAULT_BUFFER_SIZE` set
320+
at module's load-time. It is possible to override the buffer size via the environment variable
321+
"MULTICAST_BUFFER_SIZE" if available at load-time. However changing the value is not reccomended
322+
unless absolutly needed, and can be done on the sender side too.
323+
319324
Args:
320325
msgbuffer (list or None): Caller-instantiated collection to store received messages.
321326
chunk (variable or None): Caller-instantiated variable for raw received data.
@@ -381,7 +386,7 @@ def tryrecv(msgbuffer, chunk, sock):
381386
>>>
382387
383388
"""
384-
chunk = sock.recv(1316)
389+
chunk = sock.recv(multicast._MCAST_DEFAULT_BUFFER_SIZE)
385390
if not (chunk is None): # pragma: no branch
386391
msgbuffer += str(chunk, encoding='utf8') # pragma: no cover
387392
chunk = None # pragma: no cover

multicast/send.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,8 @@ def doStep(self, *args, **kwargs):
354354
# Read from stdin in chunks
355355
while True:
356356
try:
357-
chunk = sys.stdin.read(1316) # Read 1316 bytes at a time - matches read size
357+
# Read configured amount of bytes at a time - matches read size by default
358+
chunk = sys.stdin.read(multicast._MCAST_DEFAULT_BUFFER_SIZE)
358359
except IOError as e:
359360
print(f"Error reading from stdin: {e}", file=sys.stderr)
360361
break

0 commit comments

Comments
 (0)