Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bind client-side UDP sockets. #551

Merged
merged 2 commits into from Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions caproto/curio/client.py
Expand Up @@ -238,6 +238,9 @@ def __init__(self):

# UDP socket broadcasting to CA servers
self.udp_sock = ca.bcast_socket(socket)
# Must bind or getsocketname() will raise on Windows.
# See https://github.com/caproto/caproto/issues/514.
self.udp_sock.bind(('', 0))
self.broadcaster.our_address = safe_getsockname(self.udp_sock)
self.registered = False # refers to RepeaterRegisterRequest
self.loop_ready_event = curio.Event()
Expand Down
12 changes: 12 additions & 0 deletions caproto/sync/client.py
Expand Up @@ -326,6 +326,9 @@ def read(pv_name, *, data_type=None, timeout=1, priority=0, notify=True,
# caproto-repeater that will continue running after it exits.
spawn_repeater()
udp_sock = ca.bcast_socket()
# Must bind or getsocketname() will raise on Windows.
# See https://github.com/caproto/caproto/issues/514.
udp_sock.bind(('', 0))
try:
udp_sock.settimeout(timeout)
chan = make_channel(pv_name, udp_sock, priority, timeout)
Expand Down Expand Up @@ -461,6 +464,9 @@ def block(*subscriptions, duration=None, timeout=1, force_int_enums=False,
loggers[sub.pv_name] = logging.LoggerAdapter(logging.getLogger('caproto.ch'),
{'pv': sub.pv_name})
udp_sock = ca.bcast_socket()
# Must bind or getsocketname() will raise on Windows.
# See https://github.com/caproto/caproto/issues/514.
udp_sock.bind(('', 0))
try:
udp_sock.settimeout(timeout)
channels = {}
Expand Down Expand Up @@ -651,6 +657,9 @@ def write(pv_name, data, *, notify=False, data_type=None, metadata=None,
spawn_repeater()

udp_sock = ca.bcast_socket()
# Must bind or getsocketname() will raise on Windows.
# See https://github.com/caproto/caproto/issues/514.
udp_sock.bind(('', 0))
try:
udp_sock.settimeout(timeout)
chan = make_channel(pv_name, udp_sock, priority, timeout)
Expand Down Expand Up @@ -734,6 +743,9 @@ def read_write_read(pv_name, data, *, notify=False,
spawn_repeater()

udp_sock = ca.bcast_socket()
# Must bind or getsocketname() will raise on Windows.
# See https://github.com/caproto/caproto/issues/514.
udp_sock.bind(('', 0))
try:
udp_sock.settimeout(timeout)
chan = make_channel(pv_name, udp_sock, priority, timeout)
Expand Down
3 changes: 3 additions & 0 deletions caproto/threading/client.py
Expand Up @@ -317,6 +317,9 @@ def __init__(self, *, registration_retry_time=10.0):
self.ca_server_port = self.environ['EPICS_CA_SERVER_PORT']

self.udp_sock = ca.bcast_socket()
# Must bind or getsocketname() will raise on Windows.
# See https://github.com/caproto/caproto/issues/514.
self.udp_sock.bind(('', 0))

self._search_lock = threading.RLock()
self._retry_unanswered_searches_thread = None
Expand Down
3 changes: 3 additions & 0 deletions caproto/trio/client.py
Expand Up @@ -327,6 +327,9 @@ async def register(self):

async def _broadcaster_recv_loop(self, task_status):
self.udp_sock = ca.bcast_socket(socket_module=socket)
# Must bind or getsocketname() will raise on Windows.
# See https://github.com/caproto/caproto/issues/514.
self.udp_sock.bind(('', 0))
self.broadcaster.our_address = safe_getsockname(self.udp_sock)
command = self.broadcaster.register('127.0.0.1')
await self.send(ca.EPICS_CA2_PORT, command)
Expand Down