Helios.Channels.Sockets.TcpSocketChannel.DoWriteBytes C# (CSharp) Method

DoWriteBytes() protected method

protected DoWriteBytes ( IByteBuf buf ) : int
buf IByteBuf
return int
        protected override int DoWriteBytes(IByteBuf buf)
        {
            if (!buf.HasArray)
            {
                throw new NotImplementedException("Only IByteBuffer implementations backed by array are supported.");
            }

            SocketError errorCode;
            var sent = Socket.Send(buf.Array, buf.ArrayOffset + buf.ReaderIndex, buf.ReadableBytes, SocketFlags.None,
                out errorCode);

            if (errorCode != SocketError.Success && errorCode != SocketError.WouldBlock)
            {
                throw new SocketException((int) errorCode);
            }

            if (sent > 0)
            {
                buf.SetReaderIndex(buf.ReaderIndex + sent);
            }

            return sent;
        }