本文整理汇总了C#中SocketState.AddEdge方法的典型用法代码示例。如果您正苦于以下问题:C# SocketState.AddEdge方法的具体用法?C# SocketState.AddEdge怎么用?C# SocketState.AddEdge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SocketState
的用法示例。
在下文中一共展示了SocketState.AddEdge方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
}
}
示例2: 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 */
}
}
}
}