Commit f6eed713 authored by justcoding121's avatar justcoding121

remove unused methods

parent dd9befc6
...@@ -93,112 +93,6 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -93,112 +93,6 @@ namespace Titanium.Web.Proxy.Helpers
return ((port >> 8) & 0x00FF00FFu) | ((port << 8) & 0xFF00FF00u); return ((port >> 8) & 0x00FF00FFu) | ((port << 8) & 0xFF00FF00u);
} }
/// <summary>
/// relays the input clientStream to the server at the specified host name and port with the given httpCmd and headers
/// as prefix
/// Usefull for websocket requests
/// Asynchronous Programming Model, which does not throw exceptions when the socket is closed
/// </summary>
/// <param name="clientStream"></param>
/// <param name="serverStream"></param>
/// <param name="bufferSize"></param>
/// <param name="onDataSend"></param>
/// <param name="onDataReceive"></param>
/// <param name="cancellationTokenSource"></param>
/// <param name="exceptionFunc"></param>
/// <returns></returns>
internal static async Task SendRawApm(Stream clientStream, Stream serverStream,
IBufferPool bufferPool, int bufferSize,
Action<byte[], int, int> onDataSend, Action<byte[], int, int> onDataReceive,
CancellationTokenSource cancellationTokenSource,
ExceptionHandler exceptionFunc)
{
var taskCompletionSource = new TaskCompletionSource<bool>();
cancellationTokenSource.Token.Register(() => taskCompletionSource.TrySetResult(true));
// Now async relay all server=>client & client=>server data
var clientBuffer = bufferPool.GetBuffer(bufferSize);
var serverBuffer = bufferPool.GetBuffer(bufferSize);
try
{
beginRead(clientStream, serverStream, clientBuffer, onDataSend, cancellationTokenSource, exceptionFunc);
beginRead(serverStream, clientStream, serverBuffer, onDataReceive, cancellationTokenSource,
exceptionFunc);
await taskCompletionSource.Task;
}
finally
{
bufferPool.ReturnBuffer(clientBuffer);
bufferPool.ReturnBuffer(serverBuffer);
}
}
private static void beginRead(Stream inputStream, Stream outputStream, byte[] buffer,
Action<byte[], int, int> onCopy, CancellationTokenSource cancellationTokenSource,
ExceptionHandler exceptionFunc)
{
if (cancellationTokenSource.IsCancellationRequested)
{
return;
}
bool readFlag = false;
var readCallback = (AsyncCallback)(ar =>
{
if (cancellationTokenSource.IsCancellationRequested || readFlag)
{
return;
}
readFlag = true;
try
{
int read = inputStream.EndRead(ar);
if (read <= 0)
{
cancellationTokenSource.Cancel();
return;
}
onCopy?.Invoke(buffer, 0, read);
var writeCallback = (AsyncCallback)(ar2 =>
{
if (cancellationTokenSource.IsCancellationRequested)
{
return;
}
try
{
outputStream.EndWrite(ar2);
beginRead(inputStream, outputStream, buffer, onCopy, cancellationTokenSource,
exceptionFunc);
}
catch (IOException ex)
{
cancellationTokenSource.Cancel();
exceptionFunc(ex);
}
});
outputStream.BeginWrite(buffer, 0, read, writeCallback, null);
}
catch (IOException ex)
{
cancellationTokenSource.Cancel();
exceptionFunc(ex);
}
});
var readResult = inputStream.BeginRead(buffer, 0, buffer.Length, readCallback, null);
if (readResult.CompletedSynchronously)
{
readCallback(readResult);
}
}
/// <summary> /// <summary>
/// relays the input clientStream to the server at the specified host name and port with the given httpCmd and headers /// relays the input clientStream to the server at the specified host name and port with the given httpCmd and headers
/// as prefix /// as prefix
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment