Пример #1
0
        private void OnBytesRead(IIOStream stream, byte [] data, int offset, int count)
        {
            ByteBuffer bytes = new ByteBuffer(data, offset, count);

            try {
                parser.Execute(parser_settings, bytes);
            } catch (Exception e) {
                Console.WriteLine("Exception while parsing");
                Console.WriteLine(e);
            }

            if (finished_reading && parser.Upgrade)
            {
                //
                // Well, this is a bit of a hack.  Ideally, maybe there should be a putback list
                // on the socket so we can put these bytes back into the stream and the upgrade
                // protocol handler can read them out as if they were just reading normally.
                //

                if (bytes.Position < bytes.Length)
                {
                    byte [] upgrade_head = new byte [bytes.Length - bytes.Position];
                    Array.Copy(bytes.Bytes, bytes.Position, upgrade_head, 0, upgrade_head.Length);

                    SetProperty("UPGRADE_HEAD", upgrade_head);
                }

                // This is delayed until here with upgrade connnections.
                OnFinishedReading(parser);
            }
        }
Пример #2
0
 public void EndWrite(IIOStream stream)
 {
     if (callback != null)
     {
         callback();
     }
 }
Пример #3
0
        public static void ResizeAndDismiss <T>(this IIOStream <T> stream, int length, Func <int, T> constructor)
        {
            var initialPosition = stream.Length;

            stream.Length = length;

            var buffer = MemoryPool <T> .GetArray();

            try
            {
                using (var writer = stream.GetWriter())
                {
                    writer.Position = initialPosition;
                    var numSlicesToWrite = writer.Length - writer.Position;
                    while (numSlicesToWrite > 0)
                    {
                        var blockSize = Math.Min(StreamUtils.BUFFER_SIZE, numSlicesToWrite);
                        initialPosition = writer.Position;
                        for (int i = 0; i < blockSize; i++)
                        {
                            buffer[i] = constructor(initialPosition + i);
                        }
                        numSlicesToWrite -= writer.Write(buffer, 0, blockSize);
                    }
                }
            }
            finally
            {
                MemoryPool <T> .PutArray(buffer);
            }
        }
Пример #4
0
 //these are for starting and stoppign the script from an external source like
 //notepad++
 public static void DirectInit(string f, string dir, string ll, IIOStream io, IExceptionListener listener)
 {
     IsConsole = false;
     IO        = io;
     Init(listener);
     Settings.SetQuickDirectory(dir);
     Settings.SetLogLevel(ll);
     DirectRun(f);
 }
Пример #5
0
 public void EndWrite(IIOStream stream)
 {
     Libeio.Libeio.close(fd, err => {
         fd = 0;
     });
     if (callback != null)
     {
         callback();
     }
 }
Пример #6
0
 public void EndWrite(IIOStream stream)
 {
     Libeio.close(fd, err =>
     {
         fd = null;
     });
     if (callback != null)
     {
         callback();
     }
 }
Пример #7
0
        public static void Resize <T>(this IIOStream <T> stream, int length, Func <T> constructor, Action <T> destructor)
        {
            var buffer = MemoryPool <T> .GetArray();

            try
            {
                using (var reader = stream.GetReader())
                {
                    reader.Position = length;
                    var numSlicesToRead = reader.Length - reader.Position;
                    while (numSlicesToRead > 0)
                    {
                        var blockSize = reader.Read(buffer, 0, StreamUtils.BUFFER_SIZE);
                        for (int i = 0; i < blockSize; i++)
                        {
                            if (buffer[i] != null)
                            {
                                destructor(buffer[i]);
                            }
                        }
                        numSlicesToRead -= blockSize;
                    }
                }

                var initialPosition = stream.Length;
                stream.Length = length;

                using (var writer = stream.GetWriter())
                {
                    writer.Position = initialPosition;
                    var numSlicesToWrite = writer.Length - writer.Position;
                    while (numSlicesToWrite > 0)
                    {
                        var blockSize = Math.Min(StreamUtils.BUFFER_SIZE, numSlicesToWrite);
                        for (int i = 0; i < blockSize; i++)
                        {
                            buffer[i] = constructor();
                        }
                        numSlicesToWrite -= writer.Write(buffer, 0, blockSize);
                    }
                }
            }
            finally
            {
                MemoryPool <T> .PutArray(buffer);
            }
        }
 void WriteStream <T>(IInStream <T> source, IIOStream <IInStream <T> > dest, int index)
 {
     if (dest.Length < (index + 1))
     {
         dest.Length = index + 1;
     }
     using (var w = dest.GetWriter())
     {
         w.Position = index;
         if (source == null)
         {
             w.Write(StreamUtils.GetEmptyStream <T>());
         }
         else
         {
             w.Write(source);
         }
     }
 }
Пример #9
0
        public void HandleWrite(IIOStream stream)
        {
            while (this.buffers.Length > bufferOffset)
            {
                int len = -1;
                int error;
                len = sstream.Send(buffers[bufferOffset], out error);

                if (len > 0)
                {
                    AdjustSegments(len);
                }
                else
                {
                    return;
                }
            }

            FireCallbacks();
            IsComplete = (buffers.Length == bufferOffset);
        }
Пример #10
0
        public void HandleWrite(IIOStream stream)
        {
            while (this.buffers.Length > bufferOffset)
            {
                int len = -1;
                int error;
                len = sstream.Send(buffers[bufferOffset], out error);

                if (len > 0)
                {
                    AdjustSegments(len);
                }
                else
                {
                    return;
                }
            }

            FireCallbacks();
            IsComplete = (buffers.Length == bufferOffset);
        }
Пример #11
0
 public void HandleWrite(IIOStream stream)
 {
     this.stream = (ISocketStream)stream;
     if (currentPrefixBlock != null && !currentPrefixBlock.IsComplete)
     {
         currentPrefixBlock.HandleWrite(stream);
         if (currentPrefixBlock.IsComplete)
         {
             currentPrefixBlock.EndWrite(stream);
             currentPrefixBlock.Dispose();
             currentPrefixBlock = null;
         }
     }
     if (fd == -1)
     {
         OpenFile();
     }
     else if (Length == -1)
     {
         if (!Chunked)
         {
             stream.DisableWriting();
         }
         else
         {
             InitializeTransfer();
         }
     }
     else if (position != Length)
     {
         SendNextBlock();
     }
     else
     {
         OnComplete(0, 0);
     }
 }
Пример #12
0
 public static void ResizeAndDismiss <T>(this IIOStream <T> stream, int length)
     where T : new()
 {
     stream.ResizeAndDismiss(length, () => new T());
 }
Пример #13
0
 internal static extern int RIL_Load(string location, IIOStream stream, string formatType, int frame, int backgroundColor, int loadOptions, Size maxSize, Native.ProgressFnc progressFunction, out Native.RLoadOut loadOut);
Пример #14
0
 internal static extern int RIL_Save(IntPtr handle, string location, IIOStream stream, string formatType, int quality);
Пример #15
0
 public void EndWrite(IIOStream stream)
 {
 }
Пример #16
0
 public void BeginWrite(IIOStream stream)
 {
     sstream = (ISocketStream)stream;
 }
Пример #17
0
 internal static extern int RIL_Load(string location, IIOStream stream, string formatType, int frame, int backgroundColor, int loadOptions, Size maxSize, Native.ProgressFnc progressFunction, out Native.RLoadOut loadOut);
Пример #18
0
 public void BeginWrite(IIOStream stream)
 {
 }
Пример #19
0
 public void HandleWrite(IIOStream stream)
 {
 }
Пример #20
0
 public void BeginWrite(IIOStream stream)
 {
     sstream = (ISocketStream)stream;
 }
Пример #21
0
 public void HandleWrite(IIOStream stream)
 {
 }
Пример #22
0
 public void BeginWrite(IIOStream stream)
 {
 }
Пример #23
0
 public static void ResizeAndDispose <T>(this IIOStream <T> stream, int length, Func <T> constructor)
     where T : IDisposable
 {
     stream.Resize(length, constructor, (t) => t.Dispose());
 }
Пример #24
0
 public void EndWrite(IIOStream stream)
 {
 }
Пример #25
0
 public static void ResizeAndDispose <T>(this IIOStream <T> stream, int length)
     where T : IDisposable, new()
 {
     stream.Resize(length, () => new T(), (t) => t.Dispose());
 }
Пример #26
0
 internal static extern int RIL_Save(IntPtr handle, string location, IIOStream stream, string formatType, int quality);
Пример #27
0
 public void HandleWrite(IIOStream stream)
 {
     this.stream = (ISocketStream) stream;
     if (currentPrefixBlock != null && !currentPrefixBlock.IsComplete) {
         currentPrefixBlock.HandleWrite (stream);
         if (currentPrefixBlock.IsComplete) {
             currentPrefixBlock.EndWrite (stream);
             currentPrefixBlock.Dispose ();
             currentPrefixBlock = null;
         }
     }
     if (fd == -1) {
         OpenFile ();
     } else if (Length == -1) {
         if (!Chunked) {
             stream.DisableWriting ();
         } else {
             InitializeTransfer ();
         }
     } else if (position != Length) {
         SendNextBlock ();
     } else {
         OnComplete (0, 0);
     }
 }
Пример #28
0
 public void EndWrite(IIOStream stream)
 {
     if (callback != null)
         callback ();
 }