Esempio n. 1
0
        /// <summary>
        /// Sends a sequence of bytes to the connected socket.
        /// </summary>
        /// <param name="data">A <see cref="byte"/> array of data to send.</param>
        public async void Send(byte[] data)
        {
            IPEndPoint destination = await GetDestination();

            if (!Parent.LegacySupport)
            {
                PacketHeader.AddHeader(ref data);
            }

            var dataPacket = new SendPacket(destination, data);

            lock (SendBuffer.SyncRoot)
                SendBuffer.PushBack(dataPacket);

            StartSendLoop();
        }
Esempio n. 2
0
        public byte[] GetDataToSend(int bufferSize, bool legacySupport)
        {
            if (_data != null && _data.Length > 0)
            {
                return(ArrayMethods.Shrink(ref _data, bufferSize));
            }
            if (!IsFileData)
            {
                return(null);
            }

            if (!FileDataHeaderSent && !legacySupport)
            {
                _data = ObjectPacker.Pack(FileData);
                PacketHeader.AddHeader(ref _data);
                FileDataHeaderSent = true;
                return(ArrayMethods.Shrink(ref _data, bufferSize));
            }

            var part = FileData.GetNextPart(bufferSize);

            if (part != null)
            {
                if (!legacySupport)
                {
                    _data = ObjectPacker.Pack(part);
                    PacketHeader.AddHeader(ref _data);
                }
                else
                {
                    _data = part.Data;
                }
                return(ArrayMethods.Shrink(ref _data, bufferSize));
            }
            return(null);
        }