Skip to content

Commit

Permalink
Merge pull request #551 from danielballan/debug_win_socket2
Browse files Browse the repository at this point in the history
FIX: Bind client-side UDP sockets.
  • Loading branch information
klauer committed Apr 10, 2020
2 parents 905154b + 0f8cad5 commit faf0979
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
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 @@ -326,6 +326,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

0 comments on commit faf0979

Please sign in to comment.