Ejemplo n.º 1
0
        public unsafe void WriteGather(long position, IntPtr[] pages)
        {
            if (pages.Length == 0)
            {
                return; // nothing to do
            }
            var       start   = 0;
            const int IOV_MAX = 1024;

            while (start < pages.Length)
            {
                var byteLen = 0L;
                var locs    = new List <Iovec>
                {
                    new Iovec
                    {
                        iov_base = pages[start],
                        iov_len  = (ulong)_options.PageSize
                    }
                };
                start++;
                byteLen += _options.PageSize;
                for (int i = 1; i < pages.Length && locs.Count < IOV_MAX; i++, start++)
                {
                    byteLen += _options.PageSize;
                    var cur = locs[locs.Count - 1];
                    if (((byte *)cur.iov_base.ToPointer() + cur.iov_len) == (byte *)pages[i].ToPointer())
                    {
                        cur.iov_len          = cur.iov_len + (ulong)_options.PageSize;
                        locs[locs.Count - 1] = cur;
                    }
                    else
                    {
                        locs.Add(new Iovec
                        {
                            iov_base = pages[i],
                            iov_len  = (ulong)_options.PageSize
                        });
                    }
                }

                var result = Syscall.pwritev(_fd, locs.ToArray(), position);
                position += byteLen;
                if (result == -1)
                {
                    var err = Marshal.GetLastWin32Error();
                    PosixHelper.ThrowLastError(err);
                }
            }
        }
Ejemplo n.º 2
0
        public unsafe void WriteGather(long position, byte *[] pages)
        {
            var locs = new Iovec[pages.Length];

            for (int i = 0; i < locs.Length; i++)
            {
                locs[i].iov_base = new IntPtr(pages[i]);
                locs[i].iov_len  = AbstractPager.PageSize;
            }
            var result = Syscall.pwritev(_fd, locs, position);

            if (result == -1)
            {
                PosixHelper.ThrowLastError(Marshal.GetLastWin32Error());
            }
        }