// Receive a multi-part message // // Receives up to *count_ parts of a multi-part message. // Sets *count_ to the actual number of parts read. // ZMQ_RCVMORE is set to indicate if a complete multi-part message was read. // Returns number of message parts read, or -1 on error. // // Note: even if -1 is returned, some parts of the message // may have been read. Therefore the client must consult // *count_ to retrieve message parts successfully read, // even if -1 is returned. // // The iov_base* buffers of each iovec *a_ filled in by this // function may be freed using free(). // // Implementation note: We assume zmq::msg_t buffer allocated // by zmq::recvmsg can be freed by free(). // We assume it is safe to steal these buffers by simply // not closing the zmq::msg_t. // public int RecvIOv(SocketBase s, byte[][] a, int count, SendReceiveOptions flags) { if (s == null || !s.CheckTag()) { throw NetMQException.Create(ErrorCode.EFAULT); } int nread = 0; bool recvmore = true; for (int i = 0; recvmore && i < count; ++i) { // Cheat! We never close any msg // because we want to steal the buffer. Msg msg = RecvMsg(s, flags); if (msg == null) { nread = -1; break; } // Cheat: acquire zmq_msg buffer. a[i] = msg.Data; // Assume zmq_socket ZMQ_RVCMORE is properly set. recvmore = msg.HasMore; } return(nread); }
public static bool Connect(SocketBase s, String addr) { if (s == null || !s.CheckTag()) { throw new InvalidOperationException(); } return s.Connect(addr); }
public static void Close(SocketBase s) { if (s == null || !s.CheckTag()) { throw new InvalidOperationException(); } s.Close(); }
public static void Close(SocketBase s) { if (s == null || !s.CheckTag()) { throw NetMQException.Create(ErrorCode.EFAULT); } s.Close(); }
public static bool Unbind(SocketBase s, String addr) { if (s == null || !s.CheckTag()) { throw NetMQException.Create(ErrorCode.EFAULT); } return(s.TermEndpoint(addr)); }
public static void Disconnect(SocketBase s, String addr) { if (s == null || !s.CheckTag()) { throw NetMQException.Create(ErrorCode.EFAULT); } s.TermEndpoint(addr); }
public static void Connect(SocketBase s, String addr) { if (s == null || !s.CheckTag()) { throw NetMQException.Create(ErrorCode.EFAULT); } s.Connect(addr); }
public static int BindRandomPort(SocketBase s, String addr) { if (s == null || !s.CheckTag()) { throw NetMQException.Create(ErrorCode.EFAULT); } return s.BindRandomPort(addr); }
public static void SetSocketOption(SocketBase s, ZmqSocketOptions option, Object optval) { if (s == null || !s.CheckTag()) { throw NetMQException.Create(ErrorCode.EFAULT); } s.SetSocketOption(option, optval); }
public static Object GetSocketOptionX(SocketBase s, ZmqSocketOptions option) { if (s == null || !s.CheckTag()) { throw NetMQException.Create(ErrorCode.EFAULT); } return(s.GetSocketOptionX(option)); }
public static void SocketMonitor(SocketBase s, String addr, SocketEvent events) { if (s == null || !s.CheckTag()) { throw NetMQException.Create(ErrorCode.EFAULT); } s.Monitor(addr, events); }
public static void Bind(SocketBase s, String addr) { if (s == null || !s.CheckTag()) { throw NetMQException.Create(ErrorCode.EFAULT); } s.Bind(addr); }
public static int BindRandomPort(SocketBase s, String addr) { if (s == null || !s.CheckTag()) { throw NetMQException.Create(ErrorCode.EFAULT); } return(s.BindRandomPort(addr)); }
public static void Send(SocketBase s, byte[] buf, int len, SendReceiveOptions flags) { if (s == null || !s.CheckTag()) { throw NetMQException.Create(ErrorCode.EFAULT); } Msg msg = new Msg(len); msg.Put(buf, 0, len); SendMsg(s, msg, flags); }
// Send multiple messages. // // If flag bit ZMQ_SNDMORE is set the vector is treated as // a single multi-part message, i.e. the last message has // ZMQ_SNDMORE bit switched off. // public void SendIOv(SocketBase s, byte[][] a, int count, SendReceiveOptions flags) { if (s == null || !s.CheckTag()) { throw NetMQException.Create(ErrorCode.EFAULT); } Msg msg; for (int i = 0; i < count; ++i) { msg = new Msg(a[i]); if (i == count - 1) { flags = flags & ~SendReceiveOptions.SendMore; } SendMsg(s, msg, flags); } }
// Receiving functions. public static Msg Recv(SocketBase s, SendReceiveOptions flags) { if (s == null || !s.CheckTag()) { throw NetMQException.Create(ErrorCode.EFAULT); } Msg msg = RecvMsg(s, flags); if (msg == null) { return(null); } // At the moment an oversized message is silently truncated. // TODO: Build in a notification mechanism to report the overflows. //int to_copy = nbytes < len_ ? nbytes : len_; return(msg); }
public static Object GetSocketOptionX(SocketBase s, ZmqSocketOptions option) { if (s == null || !s.CheckTag()) { throw new InvalidOperationException(); } return s.GetSocketOptionX(option); }
public static int Send(SocketBase s, byte[] buf, int len, SendRecieveOptions flags) { if (s == null || !s.CheckTag()) { throw new InvalidOperationException(); } Msg msg = new Msg(len); msg.Put(buf, 0, len); int rc = SendMsg(s, msg, flags); if (rc < 0) { return -1; } return rc; }
public static void SetSocketOption(SocketBase s, ZmqSocketOptions option, Object optval) { if (s == null || !s.CheckTag()) { throw new InvalidOperationException(); } s.SetSocketOption(option, optval); }
public static bool SocketMonitor(SocketBase s, String addr, SocketEvent events) { if (s == null || !s.CheckTag()) { throw new InvalidOperationException(); } return s.Monitor(addr, events); }
public static bool Unbind(SocketBase s, String addr) { if (s == null || !s.CheckTag()) { throw new InvalidOperationException(); } return s.TermEndpoint(addr); }
// Send multiple messages. // // If flag bit ZMQ_SNDMORE is set the vector is treated as // a single multi-part message, i.e. the last message has // ZMQ_SNDMORE bit switched off. // public int SendIOv(SocketBase s, byte[][] a, int count, SendRecieveOptions flags) { if (s == null || !s.CheckTag()) { throw new InvalidOperationException(); } int rc = 0; Msg msg; for (int i = 0; i < count; ++i) { msg = new Msg(a[i]); if (i == count - 1) flags = flags & ~SendRecieveOptions.SendMore; rc = SendMsg(s, msg, flags); if (rc < 0) { rc = -1; break; } } return rc; }
public static Object GetSocketOptionX(SocketBase s, ZmqSocketOptions option) { if (s == null || !s.CheckTag()) { throw NetMQException.Create(ErrorCode.EFAULT); } return s.GetSocketOptionX(option); }
// Receiving functions. public static Msg Recv(SocketBase s, SendReceiveOptions flags) { if (s == null || !s.CheckTag()) { throw NetMQException.Create(ErrorCode.EFAULT); } Msg msg = RecvMsg(s, flags); if (msg == null) { return null; } // At the moment an oversized message is silently truncated. // TODO: Build in a notification mechanism to report the overflows. //int to_copy = nbytes < len_ ? nbytes : len_; return msg; }
// Send multiple messages. // // If flag bit ZMQ_SNDMORE is set the vector is treated as // a single multi-part message, i.e. the last message has // ZMQ_SNDMORE bit switched off. // public void SendIOv(SocketBase s, byte[][] a, int count, SendReceiveOptions flags) { if (s == null || !s.CheckTag()) { throw NetMQException.Create(ErrorCode.EFAULT); } Msg msg; for (int i = 0; i < count; ++i) { msg = new Msg(a[i]); if (i == count - 1) flags = flags & ~SendReceiveOptions.SendMore; SendMsg(s, msg, flags); } }
// Receive a multi-part message // // Receives up to *count_ parts of a multi-part message. // Sets *count_ to the actual number of parts read. // ZMQ_RCVMORE is set to indicate if a complete multi-part message was read. // Returns number of message parts read, or -1 on error. // // Note: even if -1 is returned, some parts of the message // may have been read. Therefore the client must consult // *count_ to retrieve message parts successfully read, // even if -1 is returned. // // The iov_base* buffers of each iovec *a_ filled in by this // function may be freed using free(). // // Implementation note: We assume zmq::msg_t buffer allocated // by zmq::recvmsg can be freed by free(). // We assume it is safe to steal these buffers by simply // not closing the zmq::msg_t. // public int RecvIOv(SocketBase s, byte[][] a, int count, SendReceiveOptions flags) { if (s == null || !s.CheckTag()) { throw NetMQException.Create(ErrorCode.EFAULT); } int nread = 0; bool recvmore = true; for (int i = 0; recvmore && i < count; ++i) { // Cheat! We never close any msg // because we want to steal the buffer. Msg msg = RecvMsg(s, flags); if (msg == null) { nread = -1; break; } // Cheat: acquire zmq_msg buffer. a[i] = msg.Data; // Assume zmq_socket ZMQ_RVCMORE is properly set. recvmore = msg.HasMore; } return nread; }
public static bool Unbind(SocketBase s, String addr) { if (s == null || !s.CheckTag()) { throw NetMQException.Create(ErrorCode.EFAULT); } return s.TermEndpoint(addr); }