Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Commit

Permalink
Remove remaining traces of channels
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfowl committed Nov 15, 2016
1 parent 1a81deb commit 56ee6e7
Show file tree
Hide file tree
Showing 44 changed files with 498 additions and 496 deletions.
15 changes: 7 additions & 8 deletions samples/System.IO.Pipelines.Samples/CompressionSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class CompressionSample
{
public static void Run()
{
using (var cf = new PipelineFactory())
using (var factory = new PipelineFactory())
{
var filePath = Path.GetFullPath("Program.cs");

Expand All @@ -21,16 +21,15 @@ public static void Run()
//fs.CopyTo(compressStream);
//compressStream.Flush();
//compressed.Seek(0, SeekOrigin.Begin);
// var input = channelFactory.MakeReadableChannel(compressed);

var input = cf.ReadFile(filePath)
.DeflateCompress(cf, CompressionLevel.Optimal)
.DeflateDecompress(cf);
var input = factory.ReadFile(filePath)
.DeflateCompress(factory, CompressionLevel.Optimal)
.DeflateDecompress(factory);

// Wrap the console in a writable channel
var output = cf.CreateWriter(Console.OpenStandardOutput());
// Wrap the console in a pipeline writer
var output = factory.CreateWriter(Console.OpenStandardOutput());

// Copy from the file channel to the console channel
// Copy from the file reader to the console writer
input.CopyToAsync(output).GetAwaiter().GetResult();

input.Complete();
Expand Down
36 changes: 18 additions & 18 deletions samples/System.IO.Pipelines.Samples/Framing/Codec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ public static void Run()
var listener = new UvTcpListener(thread, new IPEndPoint(ip, port));
listener.OnConnection(async connection =>
{
var channel = MakePipeline(connection);
var pipelineConnection = MakePipeline(connection);

var decoder = new LineDecoder();
var handler = new LineHandler();

// Initialize the handler with the channel
handler.Initialize(channel);
// Initialize the handler with the connection
handler.Initialize(pipelineConnection);

try
{
while (true)
{
// Wait for data
var result = await channel.Input.ReadAsync();
var result = await pipelineConnection.Input.ReadAsync();
var input = result.Buffer;

try
Expand All @@ -58,17 +58,17 @@ public static void Run()
finally
{
// Consume the input
channel.Input.Advance(input.Start, input.End);
pipelineConnection.Input.Advance(input.Start, input.End);
}
}
}
finally
{
// Close the input channel, which will tell the producer to stop producing
channel.Input.Complete();
// Close the input, which will tell the producer to stop producing
pipelineConnection.Input.Complete();

// Close the output channel, which will close the connection
channel.Output.Complete();
// Close the output, which will close the connection
pipelineConnection.Output.Complete();
}
});

Expand All @@ -81,10 +81,10 @@ public static void Run()
thread.Dispose();
}

public static IPipelineConnection MakePipeline(IPipelineConnection channel)
public static IPipelineConnection MakePipeline(IPipelineConnection connection)
{
// Do something fancy here to wrap the channel, SSL etc
return channel;
// Do something fancy here to wrap the connection, SSL etc
return connection;
}
}

Expand All @@ -95,18 +95,18 @@ public class Line

public class LineHandler : IFrameHandler<Line>
{
private WritableChannelFormatter _formatter;
private PipelineTextOutput _textOutput;

public void Initialize(IPipelineConnection channel)
public void Initialize(IPipelineConnection connection)
{
_formatter = new WritableChannelFormatter(channel.Output, EncodingData.InvariantUtf8);
_textOutput = new PipelineTextOutput(connection.Output, EncodingData.InvariantUtf8);
}

public Task HandleAsync(Line message)
{
// Echo back to the caller
_formatter.Append(message.Data);
return _formatter.FlushAsync();
_textOutput.Append(message.Data);
return _textOutput.FlushAsync();
}
}

Expand Down Expand Up @@ -135,7 +135,7 @@ public interface IFrameDecoder<TInput>

public interface IFrameHandler<TInput>
{
void Initialize(IPipelineConnection channel);
void Initialize(IPipelineConnection connection);

Task HandleAsync(TInput message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage

await requestBuffer.FlushAsync();

// Copy the body to the input channel
// Copy the body to the input
var body = await request.Content.ReadAsStreamAsync();

await body.CopyToAsync(connection.Output);
Expand All @@ -56,7 +56,7 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
}

var response = new HttpResponseMessage();
response.Content = new ChannelHttpContent(connection.Input);
response.Content = new PipelineHttpContent(connection.Input);

await ProduceResponse(state, connection, response);

Expand Down Expand Up @@ -240,7 +240,7 @@ private static async Task ProduceResponse(ConnectionState state, UvTcpConnection
{
// BAD but it's a proof of concept ok?
state.PreviousContentLength = (int)length.Value;
((ChannelHttpContent)response.Content).ContentLength = (int)length;
((PipelineHttpContent)response.Content).ContentLength = (int)length;
state.Consumed = consumed;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

namespace System.IO.Pipelines.Samples
{
public class ChannelHttpContent : HttpContent
public class PipelineHttpContent : HttpContent
{
private readonly IPipelineReader _output;

public ChannelHttpContent(IPipelineReader output)
public PipelineHttpContent(IPipelineReader output)
{
_output = output;
}
Expand Down
4 changes: 2 additions & 2 deletions samples/System.IO.Pipelines.Samples/HttpServer/HttpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ private async void StartAcceptingConnections<TContext>(IHttpApplication<TContext
_listenSocket.Bind(new IPEndPoint(ip, port));
_listenSocket.Listen(10);

using (var channelFactory = new PipelineFactory())
using (var factory = new PipelineFactory())
{
while (true)
{
try
{
var clientSocket = await _listenSocket.AcceptAsync();
clientSocket.NoDelay = true;
var task = ProcessConnection(application, channelFactory, clientSocket);
var task = ProcessConnection(application, factory, clientSocket);
}
catch (ObjectDisposedException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace System.IO.Pipelines.Samples.Http
public class ResponseHeaderDictionary : IHeaderDictionary
{
private static readonly DateHeaderValueManager _dateHeaderValueManager = new DateHeaderValueManager();
private static readonly byte[] _serverHeaderBytes = Encoding.UTF8.GetBytes("\r\nServer: Channels");
private static readonly byte[] _serverHeaderBytes = Encoding.UTF8.GetBytes("\r\nServer: Pipelines");
private static readonly byte[] _chunkedHeaderBytes = Encoding.UTF8.GetBytes("\r\nTransfer-Encoding: chunked");

private static readonly byte[] _headersStartBytes = Encoding.UTF8.GetBytes("\r\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// associated with an assembly.
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Channels.Samples")]
[assembly: AssemblyProduct("System.IO.Pipelines.Samples")]
[assembly: AssemblyTrademark("")]

// Setting ComVisible to false makes the types in this assembly not visible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static async Task Run()
var thread = new UvThread();
var client = new UvTcpClient(thread, new IPEndPoint(IPAddress.Loopback, 5000));

var consoleOutput = thread.ChannelFactory.CreateWriter(Console.OpenStandardOutput());
var consoleOutput = thread.PipelineFactory.CreateWriter(Console.OpenStandardOutput());

var connection = await client.ConnectAsync();

Expand All @@ -34,7 +34,7 @@ public static async Task Run()
await Task.Delay(1000);
}
}
private static async Task CopyCompletedAsync(IPipelineReader input, IPipelineWriter channel)
private static async Task CopyCompletedAsync(IPipelineReader input, IPipelineWriter output)
{
var result = await input.ReadAsync();
var inputBuffer = result.Buffer;
Expand All @@ -48,7 +48,7 @@ private static async Task CopyCompletedAsync(IPipelineReader input, IPipelineWri
return;
}

var buffer = channel.Alloc();
var buffer = output.Alloc();

buffer.Append(inputBuffer);

Expand Down
Loading

0 comments on commit 56ee6e7

Please sign in to comment.