Esempio n. 1
0
        protected int SendStreamImpl(NanomsgWriteStream stream, SendRecvFlags flags)
        {
            unsafe
            {
                int        bufferCount = stream.PageCount;
                nn_iovec * iovec       = stackalloc nn_iovec[bufferCount];
                nn_msghdr *hdr         = stackalloc nn_msghdr[1];

                var buffer = stream.FirstPage();
                int i      = 0;
                do
                {
                    iovec[i].iov_len  = buffer.Length;
                    iovec[i].iov_base = (void *)buffer.Buffer;
                    buffer            = stream.NextPage(buffer);
                } while (buffer.Buffer != IntPtr.Zero && i++ < bufferCount);

                (*hdr).msg_control    = null;
                (*hdr).msg_controllen = 0;
                (*hdr).msg_iov        = iovec;
                (*hdr).msg_iovlen     = bufferCount;

                return(Interop.nn_sendmsg(SocketID, hdr, (int)flags));
            }
        }
Esempio n. 2
0
        protected bool SendStreamImmediateImpl(NanomsgWriteStream stream)
        {
            int sentBytes = SendStreamImpl(stream, 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 == stream.Length);
                return(true);
            }
        }
Esempio n. 3
0
 protected void SendStreamImpl(NanomsgWriteStream stream)
 {
     SendStreamImpl(stream, SendRecvFlags.NONE);
 }
Esempio n. 4
0
 public bool SendStreamImmediate(NanomsgWriteStream stream)
 {
     return(SendStreamImmediateImpl(stream));
 }
Esempio n. 5
0
 public void SendStream(NanomsgWriteStream stream)
 {
     SendStreamImpl(stream);
 }
Esempio n. 6
0
 public bool SendStreamImmediate(NanomsgWriteStream stream)
 {
     return SendStreamImmediateImpl(stream);
 }
Esempio n. 7
0
 public void SendStream(NanomsgWriteStream stream)
 {
     SendStreamImpl(stream);
 }
Esempio n. 8
0
        internal static void Execute()
        {
            src = new byte[TestConstants.DataSize];
            new Random().NextBytes(src);

            var bufferSizes = Enumerable.Range(8,7).Select(i => 1 << i);
            const int IterationCount = 1000;
            foreach (var bufferSize in bufferSizes)
            {
                Console.WriteLine("Buffers: " + string.Join(" ", bufferSize));

                Test("msgstream", () =>
                {
                    fixed (byte* srcptr = src)
                    {
                        byte[] buffer = new byte[bufferSize];
                        for (int i = 0; i < IterationCount; i++)
                            using (var stream = new NanomsgReadStream((IntPtr)srcptr, src.Length, null))
                            {
                                int read;
                                do
                                {
                                    read = stream.Read(buffer, 0, buffer.Length);
                                } while (read > 0);
                            }
                    }
                });

                /*Test("msgstream_bytes", () =>
                {
                    fixed (byte* srcptr = src)
                    //foreach (var bufferSize in bufferSizes)
                    {
                        for (int i = 0; i < IterationCount; i++)
                            using (var stream = new NanomsgReadStream((IntPtr)srcptr, src.Length, null))
                                while (stream.ReadByte() >= 0) { }
                    }
                });

                Test("msgstream_int32", () =>
                {
                    fixed (byte* srcptr = src)
                    //foreach (var bufferSize in bufferSizes)
                    {
                        for (int i = 0; i < IterationCount; i++)
                            using (var stream = new NanomsgReadStream((IntPtr)srcptr, src.Length, null))
                                while (stream.ReadInt32().HasValue) { }
                    }
                });

                Test("msgstream_int64", () =>
                {
                    fixed (byte* srcptr = src)
                    //foreach (var bufferSize in bufferSizes)
                    {
                        for (int i = 0; i < IterationCount; i++)
                            using (var stream = new NanomsgReadStream((IntPtr)srcptr, src.Length, null))
                                while (stream.ReadInt64().HasValue) { }
                    }
                });*/

                Test("writestream", () =>
                    {
                        for (int i = 0; i < IterationCount; i++)
                            using (var dest = new NanomsgWriteStream(null))
                                dest.Write(src, 0, src.Length);
                    });

            }
        }