BeginDisconnect() public method

public BeginDisconnect ( bool reuseSocket, AsyncCallback callback, object state ) : IAsyncResult
reuseSocket bool
callback AsyncCallback
state object
return IAsyncResult
示例#1
0
            public override void Close()
            {
                if (socket == null)
                {
                    return;
                }

                socket.BeginDisconnect(false, ar => {
                    Enqueue(delegate {
                        try {
                            ((System.Net.Sockets.Socket)ar.AsyncState).EndDisconnect(ar);
                            ((System.Net.Sockets.Socket)ar.AsyncState).Dispose();
                        } catch {
                        }

                        RaiseEndOfStream();
                        if (readTimer != null)
                        {
                            readTimer.Dispose();
                        }
                        if (writeTimer != null)
                        {
                            writeTimer.Dispose();
                        }
                        readTimer  = null;
                        writeTimer = null;
                        socket     = null;

                        base.Close();
                    });
                }, socket);
            }
示例#2
0
文件: Socket.cs 项目: soywiz/NodeNet
 public void DisconnectAsync(Action Action = null)
 {
     AsyncQueue.Add(() =>
     {
         try
         {
             NativeSocket.BeginDisconnect(true, (IAsyncResult) =>
             {
                 try
                 {
                     NativeSocket.EndDisconnect(IAsyncResult);
                     Core.EnqueueTask(() =>
                     {
                         if (Action != null)
                         {
                             Action();
                         }
                         AsyncQueue.Next();
                     });
                 }
                 catch (SocketException SocketException)
                 {
                     SocketExceptionThrown(SocketException);
                 }
             }, null);
         }
         catch (SocketException SocketException)
         {
             SocketExceptionThrown(SocketException);
         }
     });
 }
示例#3
0
 System.IAsyncResult Utils.Wrappers.Interfaces.ISocket.BeginDisconnect(bool reuseSocket, System.AsyncCallback callback, object state)
 {
     return(InternalSocket.BeginDisconnect(reuseSocket, callback, state));
 }
示例#4
0
 Task IConnectable.Disconnect()
 {
     System.Net.Sockets.Socket socket = GetSocket();
     return(System.Threading.Tasks.Task <bool> .Factory.FromAsync(
                (handler, obj) => socket.BeginDisconnect(false, handler, null), _ResultDisconnect, null));
 }
示例#5
-1
 public Connection(GameServer server, Socket socket)
 {
     _socket = socket;
     _server = server;
     _socket.BeginReceive(buffer, 0, 256, SocketFlags.None, new AsyncCallback(ReceiveData), _socket);
     _socket.BeginDisconnect(false, new AsyncCallback(Disconnect), null);
 }
示例#6
-1
		[Category ("NotDotNet")] // "Needs XP or later"
		public void BeginDisconnect ()
		{
			Socket sock = new Socket (AddressFamily.InterNetwork,
						  SocketType.Stream,
						  ProtocolType.Tcp);
			Socket listen = new Socket (AddressFamily.InterNetwork,
						    SocketType.Stream,
						    ProtocolType.Tcp);
			IPAddress ip = IPAddress.Loopback;
			IPEndPoint ep = new IPEndPoint (ip, 1254);
			
			listen.Bind (ep);
			listen.Listen (1);
			
			sock.Connect (ip, 1254);
			
			Assert.AreEqual (true, sock.Connected, "BeginDisconnect #1");
			
			sock.Shutdown (SocketShutdown.Both);

			BDCalledBack.Reset ();
			BDDisconnected = false;
			
			sock.BeginDisconnect (false, BDCallback, sock);
		
			if (BDCalledBack.WaitOne (2000, false) == false) {
				Assert.Fail ("BeginDisconnect wait timed out");
			}
			
			Assert.AreEqual (true, BDDisconnected, "BeginDisconnect #2");
			Assert.AreEqual (false, sock.Connected, "BeginDisconnect #3");
			
			sock.Close ();
			listen.Close ();
		}
示例#7
-1
 /// <summary>
 /// 断开此SOCKET
 /// </summary>
 /// <param name="sock"></param>
 public void Disconnect(Socket socks)
 {
     try
     {
         if (sock != null)
             socks.BeginDisconnect(false, AsynCallBackDisconnect, socks);
     }
     catch (ObjectDisposedException)
     {
     }
 }