Beispiel #1
0
 private static void VerifyMessage(ZmqMessage message)
 {
     if (message == null)
     {
         throw new ArgumentNullException("message");
     }
 }
Beispiel #2
0
        /// <summary>
        /// Receive all parts of a multi-part message from a remote socket in non-blocking mode.
        /// </summary>
        /// <remarks>
        /// The <paramref name="frameTimeout"/> will be used for each underlying Receive operation. If the timeout
        /// elapses before the last message is received, an incomplete message will be returned.
        /// </remarks>
        /// <param name="socket">A <see cref="ZmqSocket"/> object.</param>
        /// <param name="message">The <see cref="ZmqMessage"/> to which message-parts will be appended.</param>
        /// <param name="frameTimeout">A <see cref="TimeSpan"/> specifying the receive timeout for each frame.</param>
        /// <returns>A <see cref="ZmqMessage"/> containing newly received <see cref="Frame"/> objects.</returns>
        /// <exception cref="ZmqSocketException">An error occurred receiving data from a remote endpoint.</exception>
        /// <exception cref="ObjectDisposedException">The <see cref="ZmqSocket"/> has been closed.</exception>
        /// <exception cref="NotSupportedException">The current socket type does not support Receive operations.</exception>
        public static ZmqMessage ReceiveMessage(this ZmqSocket socket, ZmqMessage message, TimeSpan frameTimeout)
        {
            VerifySocket(socket);
            VerifyMessage(message);

            Frame frame;

            do
            {
                frame = socket.ReceiveFrame(frameTimeout);

                if (frame.ReceiveStatus == ReceiveStatus.Received)
                {
                    message.AppendShallowCopy(frame);
                }
            }while (frame.ReceiveStatus == ReceiveStatus.Received && frame.HasMore);

            return(message);
        }
Beispiel #3
0
        /// <summary>
        /// Queue a multi-part message to be sent by the socket in blocking mode.
        /// </summary>
        /// <param name="socket">A <see cref="ZmqSocket"/> object.</param>
        /// <param name="message">A <see cref="ZmqMessage"/> that contains the message parts to be sent.</param>
        /// <returns>A <see cref="SendStatus"/> describing the outcome of the send operation.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="message"/> is null.</exception>
        /// <exception cref="ArgumentException"><paramref name="message"/> is incomplete.</exception>
        /// <exception cref="ZmqSocketException">An error occurred sending data to a remote endpoint.</exception>
        /// <exception cref="ObjectDisposedException">The <see cref="ZmqSocket"/> has been closed.</exception>
        /// <exception cref="NotSupportedException">The current socket type does not support Send operations.</exception>
        public static SendStatus SendMessage(this ZmqSocket socket, ZmqMessage message)
        {
            VerifySocket(socket);
            VerifyMessage(message);

            if (message.IsEmpty)
            {
                return(SendStatus.Sent);
            }

            if (!message.IsComplete)
            {
                throw new ArgumentException("Unable to send an incomplete message. Ensure HasMore on the last Frame is set to 'false'.", "message");
            }

            foreach (Frame frame in message)
            {
                socket.SendFrame(frame);
            }

            return(socket.SendStatus);
        }
Beispiel #4
0
 /// <summary>
 /// Receive all parts of a multi-part message from a remote socket in blocking mode
 /// and append them to a given message.
 /// </summary>
 /// <param name="socket">A <see cref="ZmqSocket"/> object.</param>
 /// <param name="message">The <see cref="ZmqMessage"/> to which message-parts will be appended.</param>
 /// <returns>The supplied <see cref="ZmqMessage"/> with newly received <see cref="Frame"/> objects appended.</returns>
 /// <exception cref="ArgumentNullException"><paramref name="message"/> is null.</exception>
 /// <exception cref="ZmqSocketException">An error occurred receiving data from a remote endpoint.</exception>
 /// <exception cref="ObjectDisposedException">The <see cref="ZmqSocket"/> has been closed.</exception>
 /// <exception cref="NotSupportedException">The current socket type does not support Receive operations.</exception>
 public static ZmqMessage ReceiveMessage(this ZmqSocket socket, ZmqMessage message)
 {
     return(ReceiveMessage(socket, message, TimeSpan.MaxValue));
 }