コード例 #1
0
        public new IAsyncFuture Close()
        {
            Future.SimpleFuture closeFuture = new Future.SimpleFuture();
            Action closeCallback            = base.Close;

            closeFuture.AsyncResult = closeCallback.BeginInvoke(p =>
            {
                closeCallback.EndInvoke(closeFuture);
                closeFuture.Set();
            }, null);

            return(closeFuture);
        }
コード例 #2
0
        public virtual IAsyncFuture Close()
        {
            var future = new Future.SimpleFuture();

            if (Socket == null || !Socket.Connected)
            {
                Log.Warn("Socket == null || !Socket.Connected.");
                InternalCloseSocket();
                InternalOnConnectionClosed();
                return(future);
            }

            try
            {
                Log.Info("Socket shutdown");
                Socket.Shutdown(SocketShutdown.Both);
            }
            catch (SocketException ex)
            {
                future.Exception = new NetException(ex.SocketErrorCode);
                InternalCloseSocket();
                InternalOnConnectionClosed();
            }
            catch (Exception ex)
            {
                future.Exception = new NetException(ex.Message, ex);
                InternalCloseSocket();
                InternalOnConnectionClosed();
            }

            try
            {
                Action closeCallback = Socket.Close;

                future.AsyncResult = closeCallback.BeginInvoke(p =>
                {
                    try
                    {
                        closeCallback.EndInvoke(future.AsyncResult);
                        Log.Info("Socket close.");
                        future.Set();
                    }
                    catch (SocketException ex)
                    {
                        future.Exception = new NetException(ex.SocketErrorCode);
                        InternalOnConnectionClosed();
                    }
                    catch (Exception ex)
                    {
                        future.Exception = new NetException(ex.Message, ex);
                        InternalOnConnectionClosed();
                    }

                    OnConnectionClosed();
                }, null);
            }
            catch (SocketException ex)
            {
                future.Exception = new NetException(ex.SocketErrorCode);
                InternalOnConnectionClosed();
            }
            catch (Exception ex)
            {
                future.Exception = new NetException(ex.Message, ex);
                InternalOnConnectionClosed();
            }


            return(future);
        }