Last active
May 19, 2016 12:14
-
-
Save davidfowl/79c3eef80d18688a03412168f2aad6df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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