public int Receive(byte[] buffer, int flags) { if (LibZmq.zmq_msg_init_size(_message, buffer.Length) == -1) { return(-1); } int bytesReceived = RetryIfInterrupted(() => LibZmq.zmq_recvmsg(SocketHandle, _message, flags)); if (bytesReceived == 0 && LibZmq.MajorVersion < 3) { // 0MQ 2.x does not return number of bytes received bytesReceived = LibZmq.zmq_msg_size(_message); } if (bytesReceived > 0) { Marshal.Copy(LibZmq.zmq_msg_data(_message), buffer, 0, bytesReceived); } if (LibZmq.zmq_msg_close(_message) == -1) { return(-1); } return(bytesReceived); }
public int Send(byte[] buffer, int size, int flags) { if (LibZmq.zmq_msg_init_size(_message, size) == -1) { return(-1); } if (size > 0) { Marshal.Copy(buffer, 0, LibZmq.zmq_msg_data(_message), size); } int bytesSent = RetryIfInterrupted(() => LibZmq.zmq_sendmsg(SocketHandle, _message, flags)); if (bytesSent == 0 && LibZmq.MajorVersion < 3) { // 0MQ 2.x does not report number of bytes sent, so this may be inaccurate/misleading bytesSent = size; } if (LibZmq.zmq_msg_close(_message) == -1) { return(-1); } return(bytesSent); }
public byte[] Receive(byte[] buffer, int flags, out int size) { size = -1; if (LibZmq.zmq_msg_init(_message) == -1) { return(buffer); } int bytesReceived = RetryIfInterrupted(() => LibZmq.zmq_recvmsg(SocketHandle, _message, flags)); if (bytesReceived >= 0) { if (bytesReceived == 0 && LibZmq.MajorVersion < 3) { // 0MQ 2.x does not return number of bytes received bytesReceived = LibZmq.zmq_msg_size(_message); } size = bytesReceived; if (buffer == null || size > buffer.Length) { buffer = new byte[size]; } Marshal.Copy(LibZmq.zmq_msg_data(_message), buffer, 0, size); } if (LibZmq.zmq_msg_close(_message) == -1) { size = -1; } return(buffer); }
public IntPtr Data() { return(LibZmq.zmq_msg_data(_ptr)); }