本文整理汇总了C#中Microsoft.AspNet.Server.Kestrel.Networking.UvStreamHandle类的典型用法代码示例。如果您正苦于以下问题:C# UvStreamHandle类的具体用法?C# UvStreamHandle怎么用?C# UvStreamHandle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UvStreamHandle类属于Microsoft.AspNet.Server.Kestrel.Networking命名空间,在下文中一共展示了UvStreamHandle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Shutdown
public void Shutdown(UvStreamHandle handle, Action<UvShutdownReq, int, object> callback, object state)
{
_callback = callback;
_state = state;
_pin = GCHandle.Alloc(this, GCHandleType.Normal);
_uv.shutdown(this, handle, _uv_shutdown_cb);
}
示例2: Shutdown
public void Shutdown(UvStreamHandle handle, Action<UvShutdownReq, int, object> callback, object state)
{
_callback = callback;
_state = state;
Pin();
_uv.shutdown(this, handle, _uv_shutdown_cb);
}
示例3: SocketOutput
public SocketOutput(KestrelThread thread, UvStreamHandle socket, long connectionId, IKestrelTrace log)
{
_thread = thread;
_socket = socket;
_connectionId = connectionId;
_log = log;
_callbacksPending = new Queue<CallbackContext>();
}
示例4: Write
public unsafe void Write(
UvStreamHandle handle,
MemoryPoolIterator2 start,
MemoryPoolIterator2 end,
int nBuffers,
Action<UvWriteReq, int, Exception, object> callback,
object state)
{
try
{
// add GCHandle to keeps this SafeHandle alive while request processing
_pins.Add(GCHandle.Alloc(this, GCHandleType.Normal));
var pBuffers = (Libuv.uv_buf_t*)_bufs;
if (nBuffers > BUFFER_COUNT)
{
// create and pin buffer array when it's larger than the pre-allocated one
var bufArray = new Libuv.uv_buf_t[nBuffers];
var gcHandle = GCHandle.Alloc(bufArray, GCHandleType.Pinned);
_pins.Add(gcHandle);
pBuffers = (Libuv.uv_buf_t*)gcHandle.AddrOfPinnedObject();
}
var block = start.Block;
for (var index = 0; index < nBuffers; index++)
{
var blockStart = block == start.Block ? start.Index : block.Data.Offset;
var blockEnd = block == end.Block ? end.Index : block.Data.Offset + block.Data.Count;
// create and pin each segment being written
pBuffers[index] = Libuv.buf_init(
block.Pin() + blockStart,
blockEnd - blockStart);
block = block.Next;
}
_callback = callback;
_state = state;
_uv.write(this, handle, pBuffers, nBuffers, _uv_write_cb);
}
catch
{
_callback = null;
_state = null;
Unpin(this);
var block = start.Block;
for (var index = 0; index < nBuffers; index++)
{
block.Unpin();
block = block.Next;
}
throw;
}
}
示例5: Connection
public Connection(ListenerContext context, UvStreamHandle socket) : base(context)
{
_socket = socket;
ConnectionControl = this;
_connectionId = Interlocked.Increment(ref _lastConnectionId);
_rawSocketInput = new SocketInput(Memory2, ThreadPool);
_rawSocketOutput = new SocketOutput(Thread, _socket, Memory2, this, _connectionId, Log, ThreadPool, WriteReqPool);
}
示例6: Connection
public Connection(ListenerContext context, UvStreamHandle socket)
: base(context)
{
_socket = socket;
ConnectionControl = this;
_connectionId = Interlocked.Increment(ref _lastConnectionId);
SocketInput = new SocketInput(Memory2);
SocketOutput = new SocketOutput(Thread, _socket, _connectionId, Log);
_frame = new Frame(this);
}
示例7: ConnectionCallback
protected static void ConnectionCallback(UvStreamHandle stream, int status, Exception error, object state)
{
var listener = (Listener) state;
if (error != null)
{
listener.Log.LogError("Listener.ConnectionCallback ", error);
}
else
{
listener.OnConnection(stream, status);
}
}
示例8: Write
public unsafe void Write(
UvStreamHandle handle,
ArraySegment<ArraySegment<byte>> bufs,
Action<UvWriteReq, int, Exception, object> callback,
object state)
{
try
{
// add GCHandle to keeps this SafeHandle alive while request processing
_pins.Add(GCHandle.Alloc(this, GCHandleType.Normal));
var pBuffers = (Libuv.uv_buf_t*)_bufs;
var nBuffers = bufs.Count;
if (nBuffers > BUFFER_COUNT)
{
// create and pin buffer array when it's larger than the pre-allocated one
var bufArray = new Libuv.uv_buf_t[nBuffers];
var gcHandle = GCHandle.Alloc(bufArray, GCHandleType.Pinned);
_pins.Add(gcHandle);
pBuffers = (Libuv.uv_buf_t*)gcHandle.AddrOfPinnedObject();
}
for (var index = 0; index != nBuffers; ++index)
{
// create and pin each segment being written
var buf = bufs.Array[bufs.Offset + index];
var gcHandle = GCHandle.Alloc(buf.Array, GCHandleType.Pinned);
_pins.Add(gcHandle);
pBuffers[index] = Libuv.buf_init(
gcHandle.AddrOfPinnedObject() + buf.Offset,
buf.Count);
}
_callback = callback;
_state = state;
_uv.write(this, handle, pBuffers, nBuffers, _uv_write_cb);
}
catch
{
_callback = null;
_state = null;
Unpin(this);
throw;
}
}
示例9: OnConnection
/// <summary>
/// Handles an incoming connection
/// </summary>
/// <param name="listenSocket">Socket being used to listen on</param>
/// <param name="status">Connection status</param>
protected override void OnConnection(UvStreamHandle listenSocket, int status)
{
var acceptSocket = new UvTcpHandle(Log);
acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle);
try
{
listenSocket.Accept(acceptSocket);
}
catch (UvException ex)
{
Log.LogError("TcpListenerPrimary.OnConnection", ex);
return;
}
DispatchConnection(acceptSocket);
}
示例10: OnConnection
/// <summary>
/// Handles an incoming connection
/// </summary>
/// <param name="listenSocket">Socket being used to listen on</param>
/// <param name="status">Connection status</param>
protected override void OnConnection(UvStreamHandle listenSocket, int status)
{
var acceptSocket = new UvPipeHandle(Log);
acceptSocket.Init(Thread.Loop, false);
try
{
listenSocket.Accept(acceptSocket);
}
catch (UvException ex)
{
Log.LogError("PipeListener.OnConnection", ex);
return;
}
DispatchConnection(acceptSocket);
}
示例11: OnListenPipe
private void OnListenPipe(UvStreamHandle pipe, int status, Exception error, object state)
{
if (status < 0)
{
return;
}
var dispatchPipe = new UvPipeHandle();
dispatchPipe.Init(Thread.Loop, true);
try
{
pipe.Accept(dispatchPipe);
}
catch (Exception)
{
dispatchPipe.Dispose();
return;
}
_dispatchPipes.Add(dispatchPipe);
}
示例12: OnListenPipe
private void OnListenPipe(UvStreamHandle pipe, int status, Exception error)
{
if (status < 0)
{
return;
}
var dispatchPipe = new UvPipeHandle(Log);
dispatchPipe.Init(Thread.Loop, true);
try
{
pipe.Accept(dispatchPipe);
}
catch (UvException ex)
{
dispatchPipe.Dispose();
Log.LogError("ListenerPrimary.OnListenPipe", ex);
return;
}
_dispatchPipes.Add(dispatchPipe);
}
示例13: DispatchConnection
protected override void DispatchConnection(UvStreamHandle socket)
{
var index = _dispatchIndex++ % (_dispatchPipes.Count + 1);
if (index == _dispatchPipes.Count)
{
base.DispatchConnection(socket);
}
else
{
var dispatchPipe = _dispatchPipes[index];
var write = new UvWriteReq(Log);
write.Init(Thread.Loop);
write.Write2(
dispatchPipe,
_dummyMessage,
socket,
(write2, status, error, state) =>
{
write2.Dispose();
((UvStreamHandle)state).Dispose();
},
socket);
}
}
示例14: SocketOutput
public SocketOutput(
KestrelThread thread,
UvStreamHandle socket,
MemoryPool2 memory,
Connection connection,
long connectionId,
IKestrelTrace log,
IThreadPool threadPool,
Queue<UvWriteReq> writeReqPool)
{
_thread = thread;
_socket = socket;
_connection = connection;
_connectionId = connectionId;
_log = log;
_threadPool = threadPool;
_tasksPending = new Queue<TaskCompletionSource<object>>(_initialTaskQueues);
_tasksCompleted = new Queue<TaskCompletionSource<object>>(_initialTaskQueues);
_writeContextPool = new Queue<WriteContext>(_maxPooledWriteContexts);
_writeReqPool = writeReqPool;
_head = memory.Lease();
_tail = _head;
}
示例15: Contextualize
internal void Contextualize(
SocketOutput socketOutput,
UvStreamHandle socket,
ArraySegment<byte> buffer,
Action<Exception, object> callback,
object state)
{
_self = socketOutput;
_socket = socket;
_buffer = buffer;
_callback = callback;
_state = state;
}