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); } }
public void EndWrite(IIOStream stream) { if (callback != null) { callback(); } }
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); } }
//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); }
public void EndWrite(IIOStream stream) { Libeio.Libeio.close(fd, err => { fd = 0; }); if (callback != null) { callback(); } }
public void EndWrite(IIOStream stream) { Libeio.close(fd, err => { fd = null; }); if (callback != null) { callback(); } }
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); } } }
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); }
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); }
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); } }
public static void ResizeAndDismiss <T>(this IIOStream <T> stream, int length) where T : new() { stream.ResizeAndDismiss(length, () => new T()); }
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);
internal static extern int RIL_Save(IntPtr handle, string location, IIOStream stream, string formatType, int quality);
public void EndWrite(IIOStream stream) { }
public void BeginWrite(IIOStream stream) { sstream = (ISocketStream)stream; }
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);
public void BeginWrite(IIOStream stream) { }
public void HandleWrite(IIOStream stream) { }
public void BeginWrite(IIOStream stream) { sstream = (ISocketStream)stream; }
public void HandleWrite(IIOStream stream) { }
public void BeginWrite(IIOStream stream) { }
public static void ResizeAndDispose <T>(this IIOStream <T> stream, int length, Func <T> constructor) where T : IDisposable { stream.Resize(length, constructor, (t) => t.Dispose()); }
public void EndWrite(IIOStream stream) { }
public static void ResizeAndDispose <T>(this IIOStream <T> stream, int length) where T : IDisposable, new() { stream.Resize(length, () => new T(), (t) => t.Dispose()); }
internal static extern int RIL_Save(IntPtr handle, string location, IIOStream stream, string formatType, int quality);
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); } }
public void EndWrite(IIOStream stream) { if (callback != null) callback (); }