Skip to content

Commit eb1d7e2

Browse files
authored
Minor changes
1 parent f7927dd commit eb1d7e2

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/NetMQ/NetMQBeacon.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ private void OnUdpReady(Socket socket)
199199
{
200200
Assumes.NotNull(m_pipe);
201201

202-
if (!TryReceiveUdpFrame(out NetMQFrame frame, out string peerName)) return;
202+
if (!TryReceiveUdpFrame(out NetMQFrame frame, out string peerName))
203+
return;
203204

204205
// If filter is set, check that beacon matches it
205206
var isValid = frame.MessageSize >= m_filter?.MessageSize && Compare(frame, m_filter, m_filter.MessageSize);
@@ -269,10 +270,8 @@ private void SendUdpFrame(NetMQFrame frame)
269270
{
270271
m_udpSocket.SendTo(frame.Buffer, 0, frame.MessageSize, SocketFlags.None, m_broadcastAddress);
271272
}
272-
catch (SocketException ex)
273+
catch (SocketException ex) when (ex.SocketErrorCode == SocketError.AddressNotAvailable)
273274
{
274-
if (ex.SocketErrorCode != SocketError.AddressNotAvailable) { throw; }
275-
276275
// Initiate Creation of new Udp here to solve issue related to 'sudden' network change.
277276
// On windows (7 OR 10) incorrect/previous ip address might still exist instead of new Ip
278277
// due to network change which causes crash (if no try/catch and keep trying to send to incorrect/not available address.
@@ -292,16 +291,15 @@ private bool TryReceiveUdpFrame(out NetMQFrame frame, out string peerName)
292291
{
293292
bytesRead = m_udpSocket.ReceiveFrom(buffer, ref peer);
294293
}
295-
catch(SocketException ex)
294+
catch (SocketException ex) when (ex.SocketErrorCode == SocketError.MessageSize)
296295
{
297-
if (ex.SocketErrorCode != SocketError.MessageSize) { throw; }
298-
frame = new NetMQFrame("");
299-
peerName = "";
296+
frame = default;
297+
peerName = null;
300298
return false;
301299
}
300+
302301
peerName = peer.ToString();
303302
frame = new NetMQFrame(buffer, bytesRead);
304-
305303
return true;
306304
}
307305
}

0 commit comments

Comments
 (0)