Skip to content

Commit

Permalink
Rename MethodHelper to Retry.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgoz committed Oct 15, 2012
1 parent 18e9417 commit 76397c9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
{
using System;

internal static class MethodHelper
internal static class Retry
{
public static int RetryIfInterrupted<T1, T2, T3>(Func<T1, T2, T3, int> operation, T1 arg1, T2 arg2, T3 arg3)
public static int IfInterrupted<T1, T2, T3>(Func<T1, T2, T3, int> operation, T1 arg1, T2 arg2, T3 arg3)
{
int rc;

Expand All @@ -17,7 +17,7 @@ public static int RetryIfInterrupted<T1, T2, T3>(Func<T1, T2, T3, int> operation
return rc;
}

public static int RetryIfInterrupted<T1, T2, T3, T4>(Func<T1, T2, T3, T4, int> operation, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
public static int IfInterrupted<T1, T2, T3, T4>(Func<T1, T2, T3, T4, int> operation, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
{
int rc;

Expand Down
32 changes: 16 additions & 16 deletions src/ZeroMQ/Interop/SocketProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public int Receive(byte[] buffer, int flags)
// Use zmq_buffer_recv method if appropriate -> results in fewer P/Invoke calls
if (buffer.Length <= MaxBufferSize && LibZmq.zmq_buffer_recv != null)
{
bytesReceived = MethodHelper.RetryIfInterrupted(LibZmq.zmq_buffer_recv.Invoke, SocketHandle, _buffer, MaxBufferSize, flags);
bytesReceived = Retry.IfInterrupted(LibZmq.zmq_buffer_recv.Invoke, SocketHandle, _buffer, MaxBufferSize, flags);
int size = Math.Min(buffer.Length, bytesReceived);

Marshal.Copy(_buffer, buffer, 0, size);
Expand All @@ -99,7 +99,7 @@ public int Receive(byte[] buffer, int flags)
return -1;
}

bytesReceived = MethodHelper.RetryIfInterrupted(LibZmq.zmq_msg_recv.Invoke, _msg.Ptr, SocketHandle, flags);
bytesReceived = Retry.IfInterrupted(LibZmq.zmq_msg_recv.Invoke, _msg.Ptr, SocketHandle, flags);

if (bytesReceived == 0 && LibZmq.MajorVersion < 3)
{
Expand Down Expand Up @@ -129,7 +129,7 @@ public byte[] Receive(byte[] buffer, int flags, out int size)
return buffer;
}

int bytesReceived = MethodHelper.RetryIfInterrupted(LibZmq.zmq_msg_recv.Invoke, _msg.Ptr, SocketHandle, flags);
int bytesReceived = Retry.IfInterrupted(LibZmq.zmq_msg_recv.Invoke, _msg.Ptr, SocketHandle, flags);

if (bytesReceived >= 0)
{
Expand Down Expand Up @@ -165,7 +165,7 @@ public int Send(byte[] buffer, int size, int flags)
int sizeToSend = Math.Min(size, MaxBufferSize);
Marshal.Copy(buffer, 0, _buffer, sizeToSend);

return MethodHelper.RetryIfInterrupted(LibZmq.zmq_buffer_send.Invoke, SocketHandle, _buffer, sizeToSend, flags);
return Retry.IfInterrupted(LibZmq.zmq_buffer_send.Invoke, SocketHandle, _buffer, sizeToSend, flags);
}

if (_msg.Init(size) == -1)
Expand All @@ -178,7 +178,7 @@ public int Send(byte[] buffer, int size, int flags)
Marshal.Copy(buffer, 0, _msg.Data(), size);
}

int bytesSent = MethodHelper.RetryIfInterrupted(LibZmq.zmq_msg_send.Invoke, _msg.Ptr, SocketHandle, flags);
int bytesSent = Retry.IfInterrupted(LibZmq.zmq_msg_send.Invoke, _msg.Ptr, SocketHandle, flags);

if (bytesSent == 0 && LibZmq.MajorVersion < 3)
{
Expand Down Expand Up @@ -238,7 +238,7 @@ public int GetSocketOption(int option, out int value)
{
Marshal.WriteInt32(optionLength, sizeof(int));

int rc = MethodHelper.RetryIfInterrupted(LibZmq.zmq_getsockopt.Invoke, SocketHandle, option, optionValue.Ptr, optionLength.Ptr);
int rc = Retry.IfInterrupted(LibZmq.zmq_getsockopt.Invoke, SocketHandle, option, optionValue.Ptr, optionLength.Ptr);
value = Marshal.ReadInt32(optionValue);

return rc;
Expand All @@ -252,7 +252,7 @@ public int GetSocketOption(int option, out long value)
{
Marshal.WriteInt32(optionLength, sizeof(long));

int rc = MethodHelper.RetryIfInterrupted(LibZmq.zmq_getsockopt.Invoke, SocketHandle, option, optionValue.Ptr, optionLength.Ptr);
int rc = Retry.IfInterrupted(LibZmq.zmq_getsockopt.Invoke, SocketHandle, option, optionValue.Ptr, optionLength.Ptr);
value = Marshal.ReadInt64(optionValue);

return rc;
Expand All @@ -266,7 +266,7 @@ public int GetSocketOption(int option, out ulong value)
{
Marshal.WriteInt32(optionLength, sizeof(ulong));

int rc = MethodHelper.RetryIfInterrupted(LibZmq.zmq_getsockopt.Invoke, SocketHandle, option, optionValue.Ptr, optionLength.Ptr);
int rc = Retry.IfInterrupted(LibZmq.zmq_getsockopt.Invoke, SocketHandle, option, optionValue.Ptr, optionLength.Ptr);
value = unchecked(Convert.ToUInt64(Marshal.ReadInt64(optionValue)));

return rc;
Expand All @@ -280,7 +280,7 @@ public int GetSocketOption(int option, out byte[] value)
{
Marshal.WriteInt32(optionLength, MaxBinaryOptionSize);

int rc = MethodHelper.RetryIfInterrupted(LibZmq.zmq_getsockopt.Invoke, SocketHandle, option, optionValue.Ptr, optionLength.Ptr);
int rc = Retry.IfInterrupted(LibZmq.zmq_getsockopt.Invoke, SocketHandle, option, optionValue.Ptr, optionLength.Ptr);

value = new byte[Marshal.ReadInt32(optionLength)];
Marshal.Copy(optionValue, value, 0, value.Length);
Expand All @@ -296,7 +296,7 @@ public int GetSocketOption(int option, out string value)
{
Marshal.WriteInt32(optionLength, MaxBinaryOptionSize);

int rc = MethodHelper.RetryIfInterrupted(LibZmq.zmq_getsockopt.Invoke, SocketHandle, option, optionValue.Ptr, optionLength.Ptr);
int rc = Retry.IfInterrupted(LibZmq.zmq_getsockopt.Invoke, SocketHandle, option, optionValue.Ptr, optionLength.Ptr);

value = rc == 0 ? Marshal.PtrToStringAnsi(optionValue) : string.Empty;

Expand All @@ -308,15 +308,15 @@ public int SetSocketOption(int option, string value)
{
if (value == null)
{
return MethodHelper.RetryIfInterrupted(LibZmq.zmq_setsockopt.Invoke, SocketHandle, option, IntPtr.Zero, 0);
return Retry.IfInterrupted(LibZmq.zmq_setsockopt.Invoke, SocketHandle, option, IntPtr.Zero, 0);
}

var encoded = System.Text.Encoding.ASCII.GetBytes(value + "\x0");
using (var optionValue = new DisposableIntPtr(encoded.Length))
{
Marshal.Copy(encoded, 0, optionValue, encoded.Length);

return MethodHelper.RetryIfInterrupted(LibZmq.zmq_setsockopt.Invoke, SocketHandle, option, optionValue.Ptr, value.Length);
return Retry.IfInterrupted(LibZmq.zmq_setsockopt.Invoke, SocketHandle, option, optionValue.Ptr, value.Length);
}
}

Expand All @@ -326,7 +326,7 @@ public int SetSocketOption(int option, int value)
{
Marshal.WriteInt32(optionValue, value);

return MethodHelper.RetryIfInterrupted(LibZmq.zmq_setsockopt.Invoke, SocketHandle, option, optionValue.Ptr, sizeof(int));
return Retry.IfInterrupted(LibZmq.zmq_setsockopt.Invoke, SocketHandle, option, optionValue.Ptr, sizeof(int));
}
}

Expand All @@ -336,7 +336,7 @@ public int SetSocketOption(int option, long value)
{
Marshal.WriteInt64(optionValue, value);

return MethodHelper.RetryIfInterrupted(LibZmq.zmq_setsockopt.Invoke, SocketHandle, option, optionValue.Ptr, sizeof(long));
return Retry.IfInterrupted(LibZmq.zmq_setsockopt.Invoke, SocketHandle, option, optionValue.Ptr, sizeof(long));
}
}

Expand All @@ -346,7 +346,7 @@ public int SetSocketOption(int option, ulong value)
{
Marshal.WriteInt64(optionValue, unchecked(Convert.ToInt64(value)));

return MethodHelper.RetryIfInterrupted(LibZmq.zmq_setsockopt.Invoke, SocketHandle, option, optionValue.Ptr, sizeof(ulong));
return Retry.IfInterrupted(LibZmq.zmq_setsockopt.Invoke, SocketHandle, option, optionValue.Ptr, sizeof(ulong));
}
}

Expand All @@ -356,7 +356,7 @@ public int SetSocketOption(int option, byte[] value)
{
Marshal.Copy(value, 0, optionValue, value.Length);

return MethodHelper.RetryIfInterrupted(LibZmq.zmq_setsockopt.Invoke, SocketHandle, option, optionValue.Ptr, value.Length);
return Retry.IfInterrupted(LibZmq.zmq_setsockopt.Invoke, SocketHandle, option, optionValue.Ptr, value.Length);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ZeroMQ/ZeroMQ.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<Compile Include="Interop\EventDataFileDescriptorEntry.cs" />
<Compile Include="Interop\EventDataIntervalEntry.cs" />
<Compile Include="Interop\LibZmq.Mono.cs" />
<Compile Include="Interop\MethodHelper.cs" />
<Compile Include="Interop\Retry.cs" />
<Compile Include="Interop\Platform.Mono.cs" />
<Compile Include="Interop\Platform.NET.cs" />
<Compile Include="Interop\Platform.Unix.cs" />
Expand Down

0 comments on commit 76397c9

Please sign in to comment.