static void Main(string[] args) { var pool = new MemoryPool(); var inputs = new SocketInput[100]; for (int i = 0; i < inputs.Length; i++) { var input = new SocketInput(pool); inputs[i] = input; Consume(input); } RandomlyWritetoInputs(inputs); }
private static async void Consume(SocketInput input) { while (true) { await input; if (input.DataComplete) { break; } var reader = new SocketInputTextReader(input, Encoding.UTF8); var jsonReader = new JsonTextReader(reader); var obj = await JObject.ReadFromAsync(jsonReader, new JsonLoadSettings() { }); Console.WriteLine(obj); } }
private static async void Produce(SocketInput input, byte[] data) { int at = 0; int increment = 1; while (at < data.Length) { var iter = input.IncomingStart(); int length = Math.Min(increment, data.Length - at); iter.CopyFrom(data, at, length); input.IncomingComplete(iter, completed: false, error: null); at += increment; await Task.Yield(); } input.IncomingComplete(completed: true, error: null); }
public State(SocketInput socketInput, Action <SocketInput> callback) { Iterator = new AsyncIterator(() => callback(socketInput)); }
public SocketInputTextReader(SocketInput input, Encoding encoding) { _input = input; _encoding = encoding; }