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


C# SocketState.AddCreationState方法代码示例

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


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

示例1: Start

 /**
  * Implements the SocketStateAction interface.  This is called to trigger the ECB
  * in the SelectThread so we don't have to worry about multiple threads
  * accessing variables.
  */
 public override void Start(SocketState ss) {
   object result = Result.Value;
   if( result != null ) {
     TcpEdge new_edge = result as TcpEdge;
     if( new_edge != null ) {
       //Tell the world about the new Edge:
       ss.AddEdge(new_edge);
       ECB(true, new_edge, null); 
     }
     else {
       ECB(false, null, (Exception)result); 
     }
   }
   else {
     //Try to make a new start:
     if( IPAddressQueue.Count <= 0 ) {
       ECB(false, null, new EdgeException("No more IP Addresses"));
     }
     else {
       Socket s = null;
       try {
         s = new Socket(AddressFamily.InterNetwork,
                              SocketType.Stream,
                              ProtocolType.Tcp);
         s.Blocking = false;
         ss.AddCreationState(s, this);
         IPAddress ipaddr = (IPAddress)IPAddressQueue.Dequeue();
         IPEndPoint end = new IPEndPoint(ipaddr, Port);
         //This is a hack because of a bug in MS.Net and Mono:
         //https://bugzilla.novell.com/show_bug.cgi?id=349449
         //http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=332142
         s.Bind(new IPEndPoint(IPAddress.Any, 0));
         s.Connect(end);
       }
       catch(SocketException sx) {
         if( sx.SocketErrorCode != SocketError.WouldBlock ) {
           if( s != null ) {
             ss.TakeCreationState(s);
           }
           ECB(false, null, new EdgeException(false, "Could not Connect", sx)); 
         }
         /* else Ignore the non-blocking socket error */
       }
     }
   }
 }
开发者ID:xujyan,项目名称:brunet,代码行数:51,代码来源:TcpEdgeListener.cs


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