public static void SetOption(this IZmqSocket source, SocketOpt option, byte[] buffer) { if (buffer == null) { throw new ArgumentNullException("buffer"); } source.SetOption <byte[]>((int)option, buffer); }
public static void SetOption(this IZmqSocket source, SocketOpt option, string value) { if (value == null) { throw new ArgumentNullException("value"); } source.SetOption <string>((int)option, value); }
/// <summary> /// Set Socket Option /// </summary> /// <param name="option">Socket Option</param> /// <param name="value">Option value</param> /// <exception cref="ZMQ.Exception">ZMQ Exception</exception> public void SetSockOpt(SocketOpt option, byte[] value) { using (DisposableIntPtr valPtr = new DisposableIntPtr(value.Length)) { Marshal.Copy(value, 0, valPtr.Ptr, value.Length); if (C.zmq_setsockopt(ptr, (int)option, valPtr.Ptr, value.Length) != 0) { throw new Exception(); } } }
/// <summary> /// Set Socket Option /// </summary> /// <param name="option">Socket Option</param> /// <param name="value">Option value</param> /// <exception cref="ZMQ.Exception">ZMQ Exception</exception> public void SetSockOpt(SocketOpt option, long value) { int sizeOfValue = Marshal.SizeOf(typeof(long)); using (DisposableIntPtr valPtr = new DisposableIntPtr(sizeOfValue)) { WriteSizeT(valPtr.Ptr, value); if (C.zmq_setsockopt(ptr, (int)option, valPtr.Ptr, sizeOfValue) != 0) { throw new Exception(); } } }
/// <summary> /// Set Socket Option /// </summary> /// <param name="option">Socket Option</param> /// <param name="value">Option value</param> /// <exception cref="ZMQ.Exception">ZMQ Exception</exception> public void SetSockOpt(SocketOpt option, int value) { int sizeOfValue = Marshal.SizeOf(typeof(int)); using (DisposableIntPtr valPtr = new DisposableIntPtr(sizeOfValue)) { Marshal.WriteInt32(valPtr.Ptr, Convert.ToInt32(value)); if (C.zmq_setsockopt(_ptr, (int)option, valPtr.Ptr, sizeOfValue) != 0) { throw new Exception(); } } }
/// <summary> /// Get the socket option value /// </summary> /// <param name="option">Socket Option</param> /// <returns>Option value</returns> /// <exception cref="ZMQ.Exception">ZMQ Exception</exception> public object GetSockOpt(SocketOpt option) { object output; using (DisposableIntPtr len = new DisposableIntPtr(IntPtr.Size)) { if (option == SocketOpt.IDENTITY) { using (DisposableIntPtr val = new DisposableIntPtr(255)) { WriteSizeT(len.Ptr, 255); if (C.zmq_getsockopt(ptr, (int)option, val.Ptr, len.Ptr) != 0) { throw new Exception(); } byte[] buffer = new byte[Convert.ToInt32(ReadSizeT(len.Ptr))]; Marshal.Copy(val.Ptr, buffer, 0, buffer.Length); output = buffer; } } else { using (DisposableIntPtr val = new DisposableIntPtr(IntPtr.Size)) { WriteSizeT(len.Ptr, Marshal.SizeOf(typeof(long))); if (C.zmq_getsockopt(ptr, (int)option, val.Ptr, len.Ptr) != 0) { throw new Exception(); } //Unchecked casting of uint64 options if (option == SocketOpt.HWM || option == SocketOpt.AFFINITY || option == SocketOpt.SNDBUF || option == SocketOpt.RCVBUF) { output = unchecked ((ulong)Marshal.ReadInt64(val.Ptr)); } else { output = Marshal.ReadInt64(val.Ptr); } } } } return(output); }
/// <summary> /// Get the socket option value /// </summary> /// <param name="option">Socket Option</param> /// <returns>Option value</returns> /// <exception cref="ZMQ.Exception">ZMQ Exception</exception> public object GetSockOpt(SocketOpt option) { const int IDLenSize = 255; //Identity value length 255 bytes const int lenSize = 8; //Non-Identity value size 8 bytes object output; using (var len = new DisposableIntPtr(IntPtr.Size)) { if (option == SocketOpt.IDENTITY) { using (var val = new DisposableIntPtr(IDLenSize)) { WriteSizeT(len.Ptr, IDLenSize); if (C.zmq_getsockopt(Ptr, (int)option, val.Ptr, len.Ptr) != 0) throw new Exception(); var buffer = new byte[Convert.ToInt32(ReadSizeT(len.Ptr))]; Marshal.Copy(val.Ptr, buffer, 0, buffer.Length); output = buffer; } } else { using (var val = new DisposableIntPtr(lenSize)) { WriteSizeT(len.Ptr, lenSize); if (C.zmq_getsockopt(Ptr, (int)option, val.Ptr, len.Ptr) != 0) throw new Exception(); switch (option) { case SocketOpt.HWM: case SocketOpt.AFFINITY: case SocketOpt.SNDBUF: case SocketOpt.RCVBUF: //Unchecked casting of uint64 options output = unchecked((ulong)Marshal.ReadInt64(val.Ptr)); break; case SocketOpt.LINGER: case SocketOpt.BACKLOG: case SocketOpt.RECONNECT_IVL: case SocketOpt.RECONNECT_IVL_MAX: output = Marshal.ReadInt32(val.Ptr); break; case SocketOpt.EVENTS: output = unchecked((uint)Marshal.ReadInt32(val.Ptr)); break; case SocketOpt.FD: #if POSIX output = Marshal.ReadInt32(val.Ptr); #else output = Marshal.ReadIntPtr(val.Ptr); #endif break; default: output = Marshal.ReadInt64(val.Ptr); break; } } } } return output; }
/// <summary> /// Set Socket Option /// </summary> /// <param name="option">Socket Option</param> /// <param name="value">Option value</param> /// <exception cref="ZMQ.Exception">ZMQ Exception</exception> public void SetSockOpt(SocketOpt option, long value) { int sizeOfValue = Marshal.SizeOf(typeof(long)); using (var valPtr = new DisposableIntPtr(sizeOfValue)) { Marshal.WriteInt64(valPtr.Ptr, Convert.ToInt64(value)); if (C.zmq_setsockopt(Ptr, (int)option, valPtr.Ptr, sizeOfValue) != 0) throw new Exception(); } }
/// <summary> /// Set Socket Option /// </summary> /// <param name="option">Socket Option</param> /// <param name="value">Option value</param> /// <exception cref="ZMQ.Exception">ZMQ Exception</exception> public void SetSockOpt(SocketOpt option, byte[] value) { if (value == null) { throw new ArgumentNullException("value"); } using (var valPtr = new DisposableIntPtr(value.Length)) { Marshal.Copy(value, 0, valPtr.Ptr, value.Length); if (C.zmq_setsockopt(Ptr, (int)option, valPtr.Ptr, value.Length) != 0) throw new Exception(); } }
/// <summary> /// Set Socket Option /// </summary> /// <param name="option">Socket Option</param> /// <param name="value">Option value</param> /// <exception cref="ZMQ.Exception">ZMQ Exception</exception> public void SetSockOpt(SocketOpt option, byte[] value) { using (DisposableIntPtr valPtr = new DisposableIntPtr(value.Length)) { Marshal.Copy(value, 0, valPtr.Ptr, value.Length); if (C.zmq_setsockopt(_ptr, (int)option, valPtr.Ptr, value.Length) != 0) throw new Exception(); } }
/// <summary> /// Get the socket option value /// </summary> /// <param name="option">Socket Option</param> /// <returns>Option value</returns> /// <exception cref="ZMQ.Exception">ZMQ Exception</exception> public object GetSockOpt(SocketOpt option) { const int IDLenSize = 255; //Identity value length 255 bytes const int lenSize32 = 4; //Non-Identity value size 4 or 8 bytes const int lenSize64 = 8; object output; using (DisposableIntPtr len = new DisposableIntPtr(IntPtr.Size)) { if (option == SocketOpt.IDENTITY) { using (DisposableIntPtr val = new DisposableIntPtr(IDLenSize)) { WriteSizeT(len.Ptr, IDLenSize); if (C.zmq_getsockopt(_ptr, (int)option, val.Ptr, len.Ptr) != 0) throw new Exception(); byte[] buffer = new byte[Convert.ToInt32(ReadSizeT(len.Ptr))]; Marshal.Copy(val.Ptr, buffer, 0, buffer.Length); output = buffer; } } else if (option == SocketOpt.AFFINITY || option == SocketOpt.MAXMSGSIZE) { using (DisposableIntPtr val = new DisposableIntPtr(lenSize64)) { WriteSizeT(len.Ptr, lenSize64); if (C.zmq_getsockopt(_ptr, (int)option, val.Ptr, len.Ptr) != 0) throw new Exception(); if (option == SocketOpt.AFFINITY) output = unchecked((ulong)Marshal.ReadInt64(val.Ptr)); else output = Marshal.ReadInt64(val.Ptr); } } else { using (DisposableIntPtr val = new DisposableIntPtr(lenSize32)) { WriteSizeT(len.Ptr, lenSize32); if (C.zmq_getsockopt(_ptr, (int)option, val.Ptr, len.Ptr) != 0) throw new Exception(); switch (option) { case SocketOpt.RATE: case SocketOpt.MULTICAST_HOPS: case SocketOpt.SNDHWM: case SocketOpt.RCVHWM: case SocketOpt.SNDBUF: case SocketOpt.RCVBUF: case SocketOpt.RCVLABEL: case SocketOpt.SNDTIME0: case SocketOpt.RCVTIME0: case SocketOpt.LINGER: case SocketOpt.BACKLOG: case SocketOpt.RECONNECT_IVL: case SocketOpt.RECONNECT_IVL_MAX: case SocketOpt.EVENTS: output = Marshal.ReadInt32(val.Ptr); break; case SocketOpt.FD: #if POSIX output = Marshal.ReadInt32(val.Ptr); #else output = Marshal.ReadIntPtr(val.Ptr); #endif break; default: output = Marshal.ReadInt32(val.Ptr); break; } } } } return output; }
/// <summary> /// Get the socket option value /// </summary> /// <param name="option">Socket Option</param> /// <returns>Option value</returns> /// <exception cref="ZMQ.Exception">ZMQ Exception</exception> public object GetSockOpt(SocketOpt option) { const int IDLenSize = 255; //Identity value length 255 bytes const int lenSize = 8; //Non-Identity value size 8 bytes object output; using (DisposableIntPtr len = new DisposableIntPtr(IntPtr.Size)) { if (option == SocketOpt.IDENTITY) { using (DisposableIntPtr val = new DisposableIntPtr(IDLenSize)) { WriteSizeT(len.Ptr, IDLenSize); if (C.zmq_getsockopt(_ptr, (int)option, val.Ptr, len.Ptr) != 0) { throw new Exception(); } byte[] buffer = new byte[Convert.ToInt32(ReadSizeT(len.Ptr))]; Marshal.Copy(val.Ptr, buffer, 0, buffer.Length); output = buffer; } } else { using (DisposableIntPtr val = new DisposableIntPtr(lenSize)) { WriteSizeT(len.Ptr, lenSize); if (C.zmq_getsockopt(_ptr, (int)option, val.Ptr, len.Ptr) != 0) { throw new Exception(); } switch (option) { case SocketOpt.HWM: case SocketOpt.AFFINITY: case SocketOpt.SNDBUF: case SocketOpt.RCVBUF: //Unchecked casting of uint64 options output = unchecked ((ulong)Marshal.ReadInt64(val.Ptr)); break; case SocketOpt.LINGER: case SocketOpt.BACKLOG: case SocketOpt.RECONNECT_IVL: case SocketOpt.RECONNECT_IVL_MAX: output = Marshal.ReadInt32(val.Ptr); break; case SocketOpt.EVENTS: output = unchecked ((uint)Marshal.ReadInt32(val.Ptr)); break; case SocketOpt.FD: #if POSIX output = Marshal.ReadInt32(val.Ptr); #else output = Marshal.ReadIntPtr(val.Ptr); #endif break; default: output = Marshal.ReadInt64(val.Ptr); break; } } } } return(output); }
public static void SetOption(this IZmqSocket source, SocketOpt option, Int64 value) { source.SetOption <Int64>((int)option, value); }
public static void SetOption(this IZmqSocket source, SocketOpt option, int value) { source.SetOption <int>((int)option, value); }
public static void SetOption(this IZmqSocket source, SocketOpt option, bool value) { SetOption(source, option, value ? 1 : 0); }
public static T GetOption <T>(this IZmqSocket source, SocketOpt option) { return(source.GetOption <T>((int)option)); }