Example #1
0
 /// <summary>
 /// 触发异常
 /// </summary>
 /// <param name="runtime">运行时</param>
 /// <param name="ex">触发的异常</param>
 private void ThrowException(InternalRuntime runtime, Exception ex)
 {
     runtime.Result = ex;
     runtime.IsDone = true;
     Trigger(SocketEvents.Error, ex);
     Dispose();
 }
Example #2
0
        public IAwait Send(byte[] data, int offset, int length)
        {
            var asyncResult = new InternalRuntime
            {
                Result = data
            };

            networkStream.BeginWrite(data, offset, length, OnSendCallBack, asyncResult);
            return(asyncResult);
        }
Example #3
0
        /// <summary>
        /// 异步发送
        /// </summary>
        /// <param name="data">发送数据</param>
        /// <returns>异步等待接口</returns>
        public IAwait Send(byte[] data)
        {
            Guard.Requires <InvalidOperationException>(status == Status.Establish);

            var asyncResult = new InternalRuntime
            {
                Result = data
            };

            networkStream.BeginWrite(data, 0, data.Length, OnSendCallBack, asyncResult);
            return(asyncResult);
        }
Example #4
0
        /// <summary>
        /// 建立链接
        /// </summary>
        /// <param name="hostname">服务器地址</param>
        /// <param name="port">端口</param>
        /// <returns>异步等待接口</returns>
        public IAwait Connect(string hostname, int port)
        {
            if (status != Status.Initial && status != Status.Closed)
            {
                throw new RuntimeException("Current statu [" + status + "] can not connect");
            }

            remoteHostname = hostname;
            remotePort     = port;

            status = Status.Connecting;
            var asyncResult = new InternalRuntime();

            Dns.BeginGetHostAddresses(remoteHostname, OnDnsGetHostAddressesComplete, asyncResult);
            return(asyncResult);
        }
Example #5
0
 protected override void CloseCore(DbgDispatcher dispatcher)
 {
     DbgThread[]    removedThreads;
     DbgModule[]    removedModules;
     DbgAppDomain[] removedAppDomains;
     DbgObject[]    objsToClose;
     lock (lockObj) {
         removedThreads    = threads.ToArray();
         removedModules    = modules.ToArray();
         removedAppDomains = appDomains.ToArray();
         objsToClose       = closeOnContinueList.ToArray();
         threads.Clear();
         modules.Clear();
         appDomains.Clear();
         closeOnContinueList.Clear();
     }
     currentThread = default;
     if (removedThreads.Length != 0)
     {
         ThreadsChanged?.Invoke(this, new DbgCollectionChangedEventArgs <DbgThread>(removedThreads, added: false));
     }
     if (removedModules.Length != 0)
     {
         ModulesChanged?.Invoke(this, new DbgCollectionChangedEventArgs <DbgModule>(removedModules, added: false));
     }
     if (removedAppDomains.Length != 0)
     {
         AppDomainsChanged?.Invoke(this, new DbgCollectionChangedEventArgs <DbgAppDomain>(removedAppDomains, added: false));
     }
     foreach (var obj in objsToClose)
     {
         obj.Close(dispatcher);
     }
     foreach (var thread in removedThreads)
     {
         thread.Close(dispatcher);
     }
     foreach (var module in removedModules)
     {
         module.Close(dispatcher);
     }
     foreach (var appDomain in removedAppDomains)
     {
         appDomain.Close(dispatcher);
     }
     InternalRuntime.Close(dispatcher);
 }