public bool TrySend(byte[] buffer, int offset, int count, out ZmqErrorCode error) { if ((uint)offset > (uint)buffer.Length || (uint)count > (uint)(buffer.Length - offset)) { ZmqUtil.ThrowArgOutOfRange(); } if (count == 0) { error = ZmqErrorCode.None; return(false); } fixed(byte *pBuf = &buffer[0]) { while (true) { var length = ZmqNative.send(_handle, pBuf + offset, (IntPtr)count, 0); if (length >= 0) { error = ZmqErrorCode.None; return(true); } error = ZmqNative.errno(); if (error == ZmqErrorCode.EINTR) { continue; } return(false); } } }
public bool TryReadMessage(ref byte[] buffer, out int messageLength, out ZmqErrorCode error) { ZmqMessage message; ZmqMessage.Init(&message); try { while ((messageLength = ZmqNative.msg_recv(&message, _handle, 0)) == -1) { error = ZmqNative.errno(); if (error == ZmqErrorCode.EINTR) { continue; } messageLength = 0; return(false); } if (messageLength <= 0) { error = ZmqErrorCode.None; return(false); } if (buffer == null || buffer.Length < messageLength) buffer = new byte[messageLength]; fixed(byte *pBuf = &buffer[0]) { Buffer.MemoryCopy(ZmqNative.msg_data(&message), pBuf, buffer.Length, messageLength); } error = ZmqErrorCode.None; return(true); } finally { ZmqMessage.Close(&message); } }
public static bool WasInterrupted() => ZmqNative.errno() == ZmqErrorCode.EINTR;
public static string GetLastErrorMessage() => ZmqNative.errno().ToErrorMessage();