Exemple #1
0
        private void StartSending()
        {
            if (current_write_op == null)
            {
                return;
            }
            bool cont = true;

            while (cont)
            {
                if (disabledsending)
                {
                    sending = false;
                    return;
                }
                cont = false;
                if (current_write_op.IsComplete)
                {
                    current_write_op.EndWrite(this);

                    if (write_ops.Count > 0)
                    {
                        IWriteOperation op = write_ops.Dequeue();
                        sending = false;
                        op.BeginWrite(this);
                        current_write_op = op;
                        current_write_op.HandleWrite(this);
                        lock (this)
                        {
                            if (!sending)
                            {
                                cont = true;
                            }
                        }
                    }
                    else
                    {
                        current_write_op = null;
                    }
                }
                else
                {
                    current_write_op.HandleWrite(this);
                    lock (this)
                    {
                        if (!sending)
                        {
                            cont = true;
                        }
                    }
                }
            }
        }
Exemple #2
0
        public void QueueWriteOperation(IWriteOperation op)
        {
            EnableWriting();

            UpdateExpires();

            write_ops.Enqueue(op);

            if (current_write_op == null)
            {
                current_write_op = write_ops.Dequeue();
                current_write_op.BeginWrite(this);
            }
        }
Exemple #3
0
        private void FinishCurrentWrite()
        {
            if (current_write_op == null)
            {
                return;
            }

            current_write_op.EndWrite(this);

            if (write_ops.Count > 0)
            {
                IWriteOperation op = write_ops.Dequeue();
                op.BeginWrite(this);
                current_write_op = op;
            }
            else
            {
                current_write_op = null;
                DisableWriting();
            }
        }
Exemple #4
0
 void InitializeTransfer()
 {
     stream.DisableWriting();
     Libeio.Libeio.fstat(fd, (r, stat, err) => {
         if (r == -1)
         {
             OnComplete(-1, err);
         }
         else
         {
             Length             = stat.st_size;
             var chunkHeader    = string.Format("{0:x}\r\n", Length);
             var headerBytes    = Encoding.ASCII.GetBytes(chunkHeader);
             currentPrefixBlock = new SendBytesOperation(new[] {
                 new ByteBuffer(headerBytes, 0, headerBytes.Length)
             }, null);
             stream.EnableWriting();
             currentPrefixBlock.BeginWrite(stream);
         }
     });
 }
Exemple #5
0
 protected void SendNextBlock()
 {
     stream.DisableWriting();
     Libeio.read(fd, transferBuffer, position, transferBuffer.Length, (len, buf, err) =>
     {
         if (position == Length)
         {
             OnComplete(len, err);
         }
         if (len > 0)
         {
             position          += len;
             currentPrefixBlock = new SendBytesOperation(new[] {
                 new ByteBuffer(transferBuffer, 0, len)
             }, null);
             currentPrefixBlock.BeginWrite(stream);
         }
         else
         {
             OnComplete(len, err);
         }
         stream.EnableWriting();
     });
 }
Exemple #6
0
 void InitializeTransfer()
 {
     stream.DisableWriting ();
     Libeio.Libeio.fstat (fd, (r, stat, err) => {
         if (r == -1) {
             OnComplete (-1, err);
         } else {
             Length = stat.st_size;
             var chunkHeader = string.Format ("{0:x}\r\n", Length);
             var headerBytes = Encoding.ASCII.GetBytes (chunkHeader);
             currentPrefixBlock = new SendBytesOperation (new[] {
                 new ByteBuffer (headerBytes, 0, headerBytes.Length)
             }, null);
             stream.EnableWriting ();
             currentPrefixBlock.BeginWrite (stream);
         }
     });
 }
Exemple #7
0
        public void QueueWriteOperation(IWriteOperation op)
        {
            EnableWriting();

            UpdateExpires();

            write_ops.Enqueue(op);

            if (current_write_op == null)
            {
                current_write_op = write_ops.Dequeue();
                current_write_op.BeginWrite(this);
            }
        }
Exemple #8
0
 protected void SendNextBlock()
 {
     stream.DisableWriting ();
     Libeio.read(fd, transferBuffer, position, transferBuffer.Length, (len, buf, err) =>
     {
         if (position == Length) {
             OnComplete (len, err);
         }
         if (len > 0) {
             position += len;
             currentPrefixBlock = new SendBytesOperation (new[] {
                 new ByteBuffer (transferBuffer, 0, len)
             }, null);
             currentPrefixBlock.BeginWrite (stream);
         } else {
             OnComplete (len, err);
         }
         stream.EnableWriting ();
     });
 }