예제 #1
0
        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);
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
        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);
        }
예제 #4
0
 public State(SocketInput socketInput, Action <SocketInput> callback)
 {
     Iterator = new AsyncIterator(() => callback(socketInput));
 }
예제 #5
0
 public SocketInputTextReader(SocketInput input, Encoding encoding)
 {
     _input    = input;
     _encoding = encoding;
 }