예제 #1
0
        protected virtual void Dispose(bool disposing)
        {
#if !MONO
            if (disposing)
            {
                if (m_PipeStream != null)
                {
                    if (m_AsyncResult != null)
                    {
                        /*
                         * try
                         * {
                         *  m_PipeStream.EndWaitForConnection(m_AsyncResult);
                         * }
                         * catch (Exception)
                         * {
                         * }
                         */
                        m_AsyncResult = null;
                    }
                    m_PipeStream.Dispose();
                    m_PipeStream = null;
                }
                if (m_Memory != null)
                {
                    m_Memory.Lock();
                    m_Memory.Unlock();
                    m_Memory.Dispose();
                    m_Memory = null;
                }
            }
#endif
            m_Disposed = true;
        }
예제 #2
0
        public void StreamDataExchange_Pipes()
        {
            bool success   = false;
            bool completed = false;

            int    size    = 200000000;
            string message = GenerateMessage(size);

            var client = new System.IO.Pipes.NamedPipeClientStream("TESTPIPE");
            var server = new System.IO.Pipes.NamedPipeServerStream("TESTPIPE");

            var banchmarkTimer = new System.Diagnostics.Stopwatch();

            banchmarkTimer.Start();

            var reading = new Task(async delegate()
            {
                await client.ConnectAsync();

                try
                {
                    // Data to message format.
                    string receivedMessage = await StreamHandler.StreamReaderAsync <string>(client);

                    // Stoping banchmark.
                    banchmarkTimer.Stop();

                    // Validate data.
                    success   = receivedMessage.Equals(message);
                    completed = true;
                }
                catch (Exception ex)
                {
                    Assert.Fail(ex.Message);
                    return;
                }
            });

            var writing = new Task(async delegate()
            {
                // Wait client connection.
                await server.WaitForConnectionAsync();

                try
                {
                    // Sending message to stream.
                    await StreamHandler.StreamWriterAsync(server, message);
                }
                catch (Exception ex)
                {
                    Assert.Fail(ex.Message);
                    return;
                }
            });


            reading.Start();
            writing.Start();

            while (!completed)
            {
                Thread.Sleep(5);
            }

            float secondsFromStart = banchmarkTimer.ElapsedMilliseconds / (1000.0f);
            float sharedMBSize     = size / 1000000.0f;
            float speedMBpS        = sharedMBSize / secondsFromStart;

            Console.WriteLine("Transmission time: " + secondsFromStart + " seconds");
            Console.WriteLine("Transmisted: " + sharedMBSize + " MB");
            Console.WriteLine("Speed: " +
                              speedMBpS + " MB/s | " +
                              (speedMBpS * 8) + "Mb/s");


            client.Dispose();
            server.Dispose();

            Assert.IsTrue(success);
        }
예제 #3
0
        public EditorWorkProgressShowerInConsole()
        {
#if UNITY_EDITOR_WIN
            var pipeName = System.DateTime.Now.ToString("yyMMddHHmmss");
            var pipeout  = new System.IO.Pipes.NamedPipeServerStream("ProgressShowerInConsole" + pipeName, System.IO.Pipes.PipeDirection.Out);
            var pipein   = new System.IO.Pipes.NamedPipeServerStream("ProgressShowerInConsoleControl" + pipeName, System.IO.Pipes.PipeDirection.In);
            var arout    = pipeout.BeginWaitForConnection(null, null);
            var arin     = pipein.BeginWaitForConnection(null, null);

            var dir     = Application.dataPath + "/../";
            var tooldir = CapsModEditor.GetPackageOrModRoot(CapsEditorUtils.__MOD__) + "/~Tools~/";
            System.Diagnostics.ProcessStartInfo si = new System.Diagnostics.ProcessStartInfo(tooldir + "ProgressShowerInConsole.exe", pipeName);
            si.WorkingDirectory = tooldir;
            _ExProc             = System.Diagnostics.Process.Start(si);

            var thd_Write = new System.Threading.Thread(() =>
            {
                try
                {
                    pipeout.EndWaitForConnection(arout);
                    var sw = new System.IO.StreamWriter(pipeout);
                    while (_MessageReady.WaitOne())
                    {
                        _MessageReady.Reset();
                        lock (_MessageQueue)
                        {
                            foreach (var line in _MessageQueue)
                            {
                                sw.WriteLine(line);
                            }
                            sw.Flush();
                            _MessageQueue.Clear();
                        }
                    }
                }
                finally
                {
                    pipeout.Dispose();
                }
            });
            thd_Write.Start();

            var thd_Read = new System.Threading.Thread(() =>
            {
                try
                {
                    pipein.EndWaitForConnection(arin);
                    var sr = new System.IO.StreamReader(pipein);
                    while (!_ExProc.HasExited)
                    {
                        var line = sr.ReadLine();
                        if (line != null)
                        {
                            if (line == "\uEE05Quit")
                            {
                                break;
                            }
                        }
                    }
                }
                finally
                {
                    _ShouldQuit = true;
                    thd_Write.Abort();
                    _MessageReady.Set();
                    pipein.Dispose();
                }
            });
            thd_Read.Start();
#endif
        }