Commit d6730be8 authored by Kirill Smelkov's avatar Kirill Smelkov

tmcast: Don't block forever if there is no packets to receive

Or else cancellation does not work.
Amends 334a148f (tmcast.py: Handle SIGINT/SIGTERM).
parent ff4711d0
......@@ -8,7 +8,7 @@ import sys, time
from socket import socket, AF_INET, AF_INET6, SOCK_DGRAM, IPPROTO_UDP, \
SOL_SOCKET, SO_REUSEADDR, IPPROTO_IP, IPPROTO_IPV6, IP_ADD_MEMBERSHIP, \
IPV6_JOIN_GROUP, IP_MULTICAST_TTL, IPV6_MULTICAST_HOPS, IP_MULTICAST_LOOP, \
IPV6_MULTICAST_LOOP, inet_pton
IPV6_MULTICAST_LOOP, inet_pton, timeout as TimeoutError
import socket as net
from struct import pack
......@@ -88,10 +88,14 @@ def txloop(ctx, sk, pkt):
time.sleep(1)
def rxloop(ctx, sk):
sk.settimeout(1)
while 1:
if ctx.err():
raise ctx.err()
pkt = sk.recv(4096)
try:
pkt = sk.recv(4096)
except TimeoutError:
continue
print("rx: %s" % u(pkt))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment