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


C# SocketState.GetReceiveState方法代码示例

本文整理汇总了C#中SocketState.GetReceiveState方法的典型用法代码示例。如果您正苦于以下问题:C# SocketState.GetReceiveState方法的具体用法?C# SocketState.GetReceiveState怎么用?C# SocketState.GetReceiveState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SocketState的用法示例。


在下文中一共展示了SocketState.GetReceiveState方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HandleReads

 protected void HandleReads(SocketState ss) {
   ArrayList readsocks = ss.ReadSocks;
   Socket listen_sock = ss.ListenSock;
   for(int i = 0; i < readsocks.Count; i++) {
     Socket s = (Socket)readsocks[i];
     //See if this is a new socket
     if( s == listen_sock ) {
       TcpEdge e = null;
       Socket new_s = null;
       try {
         new_s = listen_sock.Accept();
         IPEndPoint rep = (IPEndPoint)new_s.RemoteEndPoint;
         new_s.LingerState = new LingerOption (true, 0);
         TransportAddress rta =
                  TransportAddressFactory.CreateInstance(TransportAddress.TAType.Tcp, rep);
         if( ss.TAA.Authorize(rta) == TAAuthorizer.Decision.Deny ) {
           //No thank you Dr. Evil
           Console.Error.WriteLine("Denying: {0}", rta);
           new_s.Close();
         }
         else {
           //This edge looks clean
           TcpEdgeListener.SetSocketOpts(s);
           e = new TcpEdge(TEL, true, new_s);
           ss.AddEdge(e);
           //Handle closes in the select thread:
           CloseAction ca = new CloseAction(e, TEL.ActionQueue);
           e.CloseEvent += ca.CloseHandler;
           TEL.SendEdgeEvent(e);
         }
       }
       catch(Exception) {
         //Looks like this Accept has failed.  Do nothing
         //Console.Error.WriteLine("New incoming edge ({0}) failed: {1}", new_s, sx);
         //Make sure the edge is closed
         if( e != null ) {
           TEL.RequestClose(e);
           //Go ahead and forget about this socket.
           CloseAction ca = new CloseAction(e, null);
           ca.Start(ss);
         }
         else if( new_s != null) {
           //This should not be able to throw an exception:
           new_s.Close();
         }
       }
     }
     else {
       ReceiveState rs = ss.GetReceiveState(s);
       if( rs != null && !rs.Receive() ) {
         TEL.RequestClose(rs.Edge);
         //Go ahead and forget about this socket.
         CloseAction ca = new CloseAction(rs.Edge, null);
         ca.Start(ss);
       }
     }
   }
 }
开发者ID:xujyan,项目名称:brunet,代码行数:58,代码来源:TcpEdgeListener.cs


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