本文整理汇总了C#中System.Net.Sockets.SocketAsyncEventArgs.ReturnPool方法的典型用法代码示例。如果您正苦于以下问题:C# SocketAsyncEventArgs.ReturnPool方法的具体用法?C# SocketAsyncEventArgs.ReturnPool怎么用?C# SocketAsyncEventArgs.ReturnPool使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Sockets.SocketAsyncEventArgs
的用法示例。
在下文中一共展示了SocketAsyncEventArgs.ReturnPool方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnEvent
public bool OnEvent(SocketAsyncEventArgs e)
{
if (e.SocketError == SocketError.Success)
{
switch (e.LastOperation)
{
case SocketAsyncOperation.ReceiveFrom:
if (e.BytesTransferred > 0)
{
//Debug.WriteLine("receiveFrom:"+e.BytesTransferred);
}
else
{
return false;
}
InputBuffer.Published += (uint)e.BytesTransferred;
ReceiveData?.Invoke(e.RemoteEndPoint as IPEndPoint);
if (_readEnabled)
{
SetReceiveBuffer(InputBuffer, e, 65535);
// Protocol.InputBuffer.SetReceiveBuffer(e, 65535);
if (!Socket.ReceiveFromAsync(e) && !OnEvent(e))
{
}
}
else
{
ReadEnabled = false;
e.ReturnPool();
}
break;
case SocketAsyncOperation.Receive:
return false;
case SocketAsyncOperation.SendTo:
return false;
}
return true;
}
Logger.WARN(e.SocketError.ToString());
return false;
}
示例2: OnEvent
public override bool OnEvent(SocketAsyncEventArgs e)
{
if (e.SocketError == SocketError.Success)
{
switch (e.LastOperation)
{
case SocketAsyncOperation.Receive:
if (e.BytesTransferred > 0)
{
Rx += e.BytesTransferred;
}
else
{
Logger.WARN("socket read data error");
return false;
}
//Logger.INFO("rec:{0}",Rx);
Protocol.InputBuffer.Published += (uint)e.BytesTransferred;
Protocol.SignalInputData(e.BytesTransferred);
if (ReadEnabled)
{
SetReceiveBuffer(Protocol.InputBuffer,e);
if (!Socket.ReceiveAsync(e) && !OnEvent(e))
IOHandlerManager.EnqueueForDelete(this);
}
else
{
//ReadEnabled = false;
e.ReturnPool();
}
break;
//case SocketAsyncOperation.Send:
// if (Protocol.OutputBuffer == null)
// {
// DisableWriteData();
// }
// else
// {
// if (e.BytesTransferred < 0)
// {
// Logger.FATAL("Unable to send data.{0}:{1} -> {2}:{3}", FarIP, FarPort, NearIP, NearPort);
// IOHandlerManager.EnqueueForDelete(this);
// return false;
// }
// Protocol.OutputBuffer.Ignore((uint)e.BytesTransferred);
// // if(e.BytesTransferred==4096)Logger.Debug("{0}", e.BytesTransferred);
// Tx += e.BytesTransferred;
// if (Protocol.OutputBuffer != null && WriteEnabled)
// {
// SetSendBuffer( Protocol.OutputBuffer,e);
// if (!OutboundFd.SendAsync(e) && !OnEvent(e)) IOHandlerManager.EnqueueForDelete(this);
// }
// else
// {
// DisableWriteData();
// e.ReturnPool();
// }
// }
// break;
}
return true;
}
Logger.WARN("{1}({0}):"+e.SocketError,Id,GetType().Name);
return false;
}
示例3: Accept
public bool Accept(SocketAsyncEventArgs socketAsyncEvent)
{
if (!_enabled)
{
Logger.WARN("Acceptor is not enabled.");
_droppedCount++;
return true;
}
Logger.INFO("Client connected:{0}:{1} -> {2}:{3}", (socketAsyncEvent.AcceptSocket.RemoteEndPoint as IPEndPoint).Address.ToString(), (socketAsyncEvent.AcceptSocket.RemoteEndPoint as IPEndPoint).Port, _ipAddress, _port);
BaseProtocol pProtocol = ProtocolFactoryManager.CreateProtocolChain(_protocolChain, Parameters);
if (pProtocol == null)
{
Logger.FATAL("Unable to create protocol chain");
socketAsyncEvent.AcceptSocket.Close();
return false;
}
var pTcpCarrier = new TCPCarrier(socketAsyncEvent.AcceptSocket)
{
Protocol = pProtocol.FarEndpoint,
ReadEnabled = true
};
pProtocol.FarEndpoint.IOHandler = pTcpCarrier;
//6. Register the protocol stack with an application
if (Application != null)
{
pProtocol = pProtocol.NearEndpoint;
pProtocol.Application = Application;
}
//if (pProtocol.NearEndpoint.OutputBuffer != null)
// pProtocol.NearEndpoint.EnqueueForOutbound();
if (AcceptEnabled)
{
socketAsyncEvent.AcceptSocket = null;
try
{
if (!Socket.AcceptAsync(socketAsyncEvent))
{
OnEvent(socketAsyncEvent);
}
}
catch (Exception ex)
{
Logger.FATAL(ex.Message);
return false;
}
}
else
{
socketAsyncEvent.ReturnPool();
}
_acceptedCount++;
return true;
}
示例4: OnEvent
public override bool OnEvent(SocketAsyncEventArgs e)
{
if (e.SocketError == SocketError.Success)
{
switch (e.LastOperation)
{
case SocketAsyncOperation.ReceiveFrom:
if (e.BytesTransferred > 0)
{
//Debug.WriteLine("receiveFrom:"+e.BytesTransferred);
Rx += e.BytesTransferred;
}
else
{
Logger.WARN("socket read data error");
return false;
}
Protocol.InputBuffer.Published += (uint)e.BytesTransferred;
Protocol.SignalInputData(Protocol.InputBuffer, e.RemoteEndPoint as IPEndPoint);
if (ReadEnabled)
{
SetReceiveBuffer(Protocol.InputBuffer, e, 65535);
// Protocol.InputBuffer.SetReceiveBuffer(e, 65535);
if (!Socket.ReceiveFromAsync(e) && !OnEvent(e))
IOHandlerManager.EnqueueForDelete(this);
}
else
{
ReadEnabled = false;
e.ReturnPool();
}
break;
case SocketAsyncOperation.Receive:
return false;
case SocketAsyncOperation.SendTo:
return false;
}
return true;
}
Logger.WARN(e.SocketError.ToString());
return false;
}