public void SendRecv()
        {
            using (var s = new StreamStuff(factory))
            {
                // Unmanaged memory
                var lbytes = Util.RandomBytes();
                var lmem   = factory.CreateAlloc(lbytes.Length);
                lbytes.CopyTo(lmem.AsSpan());
                var liov = new nng_iov {
                    iov_buf = lmem.Ptr, iov_len = lmem.Length
                };
                var dmem = factory.CreateAlloc(lbytes.Length);
                var diov = new nng_iov {
                    iov_buf = dmem.Ptr, iov_len = dmem.Length
                };

                s.laio.SetIov(new [] { liov });
                s.daio.SetIov(new [] { diov });
                s.lstream.Send(s.daio);
                s.dstream.Recv(s.laio);
                s.laio.Wait();
                s.daio.Wait();
                Assert.NotEqual(UIntPtr.Zero, s.daio.Count());
                Assert.True(Util.BytesEqual(lmem.AsSpan(), dmem.AsSpan()));

                // Pinned managed memory
                unsafe
                {
                    lbytes = Util.RandomBytes();
                    var dbytes = new byte[lbytes.Length];
                    fixed(byte *lptr = lbytes)
                    fixed(byte *dptr = dbytes)
                    {
                        liov = new nng_iov {
                            iov_buf = (IntPtr)lptr, iov_len = (UIntPtr)lbytes.Length
                        };
                        diov = new nng_iov {
                            iov_buf = (IntPtr)dptr, iov_len = (UIntPtr)dbytes.Length
                        };

                        s.laio.SetIov(new [] { liov });
                        s.daio.SetIov(new [] { diov });
                        s.lstream.Send(s.daio);
                        s.dstream.Recv(s.laio);
                        s.laio.Wait();
                        s.daio.Wait();
                        Assert.NotEqual(UIntPtr.Zero, s.daio.Count());
                        Assert.True(Util.BytesEqual(lbytes, dbytes));
                    }
                }
            }
        }
Beispiel #2
0
        public async Task Iov()
        {
            var url = UrlInproc();

            using (var socket = factory.PusherOpen().ThenListen(url).Unwrap())
                using (var context = socket.CreateAsyncContext(factory).Unwrap())
                {
                    // Maximum iov
                    var array = new nng_iov[MAX_IOV_BUFFERS];
                    context.Aio.SetIov(array).Unwrap();

                    // Too many iov
                    array = new nng_iov[MAX_IOV_BUFFERS + 1];
                    Assert.Equal(NngErrno.EINVAL, context.Aio.SetIov(array).Err());

                    // Stack-allocated iov
                    unsafe {
                        var span = stackalloc nng_iov[MAX_IOV_BUFFERS];
                        context.Aio.SetIov(new Span <nng_iov>(span, MAX_IOV_BUFFERS)).Unwrap();
                    }
                }
        }
Beispiel #3
0
 public static extern int nng_aio_set_iov(nng_aio aio, UInt32 count, nng_iov iov);