Skip to content

Instantly share code, notes, and snippets.

@davidfowl
Last active May 19, 2016 12:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save davidfowl/79c3eef80d18688a03412168f2aad6df to your computer and use it in GitHub Desktop.
Save davidfowl/79c3eef80d18688a03412168f2aad6df to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication8
{
class Program
{
static void Main(string[] args)
{
var pool = new MemoryPool();
var input = new SocketAwaiter(pool);
var output = new SocketAwaiter(pool);
ReadInput(input);
WriteOutput(output);
while (true)
{
var iter = input.IncomingStart();
var data = Encoding.UTF8.GetBytes("Hello World ");
iter.CopyFrom(data);
// Write to the block
input.IncomingComplete(iter, false, null);
}
}
private static async void WriteOutput(SocketAwaiter output)
{
while (!output.DataComplete)
{
await output;
var scan = output.ConsumingStart();
// Do complicated write logic here
output.ConsumingComplete(scan, scan);
}
}
private static async void ReadInput(SocketAwaiter input)
{
while (!input.DataComplete)
{
await input;
var scan = input.ConsumingStart();
// Parse http here
int ch;
while ((ch = scan.Take()) != -1)
{
Console.Write((char)ch);
}
input.ConsumingComplete(scan, scan);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment