/// <summary>
        /// Sends the data, blocking until a send buffer can be acquired.
        /// </summary>
        /// <param name="buffer">The data to send</param>
        /// <exception cref="NNanomsg.NanomsgException">Thrown if the socket is in an invalid state, the send was interrupted, or the send timeout has expired</exception>
        protected void SendImpl(byte[] buffer)
        {
            int sentBytes = Interop.nn_send(_socket, buffer, buffer.Length, (int)SendRecvFlags.NONE);

            if (sentBytes < 0)
            {
                throw new NanomsgException("nn_send");
            }
            else
            {
                Debug.Assert(sentBytes == buffer.Length);
            }
        }
        /// <summary>
        /// Sends the data.  If a send buffer cannot be immediately acquired, this method returns false and no send is performed.
        /// </summary>
        /// <param name="buffer">The data to send.</param>
        /// <returns>True if the data was sent, false if the data couldn't be sent at this time, and should be reattempted.</returns>
        /// <exception cref="NNanomsg.NanomsgException">Thrown if the socket is in an invalid state, the send was interrupted, or the send timeout has expired</exception>
        protected bool SendImmediateImpl(byte[] buffer)
        {
            int sentBytes = Interop.nn_send(_socket, buffer, buffer.Length, (int)SendRecvFlags.DONTWAIT);

            if (sentBytes < 0)
            {
                int error = Interop.nn_errno();
                if (error == NanomsgSymbols.EAGAIN)
                {
                    return(false);
                }
                else
                {
                    throw new NanomsgException("nn_send", error);
                }
            }
            else
            {
                Debug.Assert(sentBytes == buffer.Length);
                return(true);
            }
        }
Beispiel #3
0
 public static int Send(int s, byte[] buf, SendRecvFlags flags)
 {
     return(Interop.nn_send(s, buf, buf.Length, (int)flags));
 }