BeginDisconnect() публичный Метод

public BeginDisconnect ( bool reuseSocket, AsyncCallback callback, object state ) : IAsyncResult
reuseSocket bool
callback AsyncCallback
state object
Результат 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
 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)
     {
     }
 }