当前位置: 首页>>代码示例>>C#>>正文


C# SocketAsyncEventArgs.ReturnPool方法代码示例

本文整理汇总了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;
 }
开发者ID:langhuihui,项目名称:csharprtmp,代码行数:42,代码来源:UdpIO.cs

示例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;
        }
开发者ID:langhuihui,项目名称:csharprtmp,代码行数:67,代码来源:TCPCarrier.cs

示例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;
        }
开发者ID:langhuihui,项目名称:csharprtmp,代码行数:60,代码来源:TCPAcceptor.cs

示例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;
 }
开发者ID:langhuihui,项目名称:csharprtmp,代码行数:42,代码来源:UDPCarrier.cs


注:本文中的System.Net.Sockets.SocketAsyncEventArgs.ReturnPool方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。