Ejemplo n.º 1
0
        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));
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public void Basic()
 {
     using (var stream = new StreamStuff(factory))
     {
     }
 }