Пример #1
0
        public unsafe PosixResult TrySend(ArraySegment <byte> buffer)
        {
            ValidateSegment(buffer);
            fixed(byte *buf = buffer.Array)
            {
                IOVector ioVector = new IOVector()
                {
                    Base = buf + buffer.Offset, Count = (void *)buffer.Count
                };

                return(SocketInterop.Send(this, &ioVector, 1));
            }
        }
Пример #2
0
        private static unsafe PosixResult TrySend(int fd, ref ReadableBuffer buffer)
        {
            int ioVectorLength = 0;

            foreach (var memory in buffer)
            {
                if (memory.Length == 0)
                {
                    continue;
                }
                ioVectorLength++;
                if (ioVectorLength == MaxIOVectorSendLength)
                {
                    // No more room in the IOVector
                    break;
                }
            }
            if (ioVectorLength == 0)
            {
                return(new PosixResult(0));
            }

            var ioVectors = stackalloc IOVector[ioVectorLength];
            int i         = 0;

            foreach (var memory in buffer)
            {
                if (memory.Length == 0)
                {
                    continue;
                }
                void *pointer;
                memory.TryGetPointer(out pointer);
                ioVectors[i].Base  = pointer;
                ioVectors[i].Count = (void *)memory.Length;
                i++;
                if (i == ioVectorLength)
                {
                    // No more room in the IOVector
                    break;
                }
            }
            return(SocketInterop.Send(fd, ioVectors, ioVectorLength));
        }
Пример #3
0
 public unsafe PosixResult TrySend(IOVector *ioVectors, int ioVectorLen)
 {
     return(SocketInterop.Send(this, ioVectors, ioVectorLen));
 }