public void Writing_Disposed_Exception() { var memstream = new MemoryStream(); var writer = new MessageWriter(memstream); // Check that the BaseStream is opened. Assert.That(memstream.CanRead == true); writer.Dispose(); // Check that the BaseStream is closed. Assert.That(memstream.CanRead == false); Assert.Throws <ObjectDisposedException>(() => writer.Write(false)); Assert.Throws <ObjectDisposedException>(() => writer.Write((ushort)1)); Assert.Throws <ObjectDisposedException>(() => writer.Write((short)1)); Assert.Throws <ObjectDisposedException>(() => writer.Write((uint)1)); Assert.Throws <ObjectDisposedException>(() => writer.Write((int)1)); Assert.Throws <ObjectDisposedException>(() => writer.Write((float)1)); Assert.Throws <ObjectDisposedException>(() => writer.Write((ulong)1)); Assert.Throws <ObjectDisposedException>(() => writer.Write((long)1)); Assert.Throws <ObjectDisposedException>(() => writer.Write((double)1)); Assert.Throws <ObjectDisposedException>(() => writer.Write((decimal)1)); }
static int Main(string[] args) { Log.InfoFormat("start at current directory {0}", Directory.GetCurrentDirectory()); Log.Info("parsing command args"); if (!ParseCommandLine(args)) { Log.Error("command line parse error"); return(0); } Log.InfoFormat("Starting plugin, settings:width:{0},height:{1},url:{2},memfile:{3},inMem:{4},outMem:{5}, WebRtc:{6},Enable GPU:{7}", defWidth, defHeight, defUrl, defFileName, defInFileName, defOutFileName, useWebRTC, EnableGPU); Log.InfoFormat("Statring cef runtime"); if (!CefRintimePrepare(args, temporaryDirectoryPath)) { Log.Error("cef runtime initialisation failed"); return(0); //immediate exit } try { Log.Info("starting cef worker"); CefWorker worker = new CefWorker(); worker.Init(defWidth, defHeight, defUrl); Log.Info("Binding shared memory"); SharedTextureWriter server = new SharedTextureWriter(defFileName, defWidth * defHeight * 4); MessageReader inSrv = MessageReader.Create(defInFileName, 10000); MessageWriter outSrv = MessageWriter.Create(defOutFileName, 10000); Log.Info("complete to bind shared memory, ready and wait"); var app = new App(worker, server, inSrv, outSrv, false); Log.Info("Enter main loop"); try { while (app.IsRunning) { Application.DoEvents(); app.CheckMessage(); //check incoming messages } } catch (Exception e) { Log.ErrorFormat("abnormal exit main loop{0}", e.Message); } Log.Info("Exit main loop END DISPOSING ALL"); worker.Dispose(); server.Dispose(); inSrv.Dispose(); outSrv.Dispose(); } catch (Exception e) { Log.ErrorFormat("Unclean exit error {0}", e.Message); } GC.Collect(); GC.WaitForFullGCComplete(-1); Log.Info("CefRuntime.Shutdown"); CefRuntime.Shutdown(); Log.Info("Final exit"); return(0); }
//shut down by timer, in case of client crash/hang private void CheckExitTimer() { var delta = DateTime.UtcNow - this._lastMessageTime; if (delta <= TimeSpan.FromSeconds(10)) { return; } try { log.Info("Exiting by timer,timeout:" + delta.TotalSeconds); log.Info("==============SHUTTING DOWN=========="); _mainWorker.Shutdown(); _memServer.Dispose(); _inCommServer.Dispose(); _outCommServer.Dispose(); IsRunning = false; } catch (Exception ex) { log.Info("Exception on shutdown:" + ex.StackTrace); } }
protected virtual void Dispose(bool disposing) { if (!_disposed && disposing) { MessageWriter.Dispose(); _disposed = true; } }
public GameServer(ArgumentOptions options) : base(options) { game = new Game(MapInfo.defaultMap, options.TeamCount); communicationToGameID = new long[options.TeamCount, options.PlayerCountPerTeam]; for (int i = 0; i < communicationToGameID.GetLength(0); ++i) { for (int j = 0; j < communicationToGameID.GetLength(1); ++j) { communicationToGameID[i, j] = GameObject.invalidID; //初始值为无效ID,代表还未进入游戏 } } if (options.FileName != DefaultArgumentOptions.FileName) { try { mwr = new MessageWriter(options.FileName, options.TeamCount, options.PlayerCountPerTeam); } catch { Console.WriteLine($"Error: Cannot create the playback file: {options.FileName}!"); } } if (options.Token != DefaultArgumentOptions.Token && options.Url != DefaultArgumentOptions.Url) { httpSender = new HttpSender(options.Url, options.Token, "PUT"); } while (!game.GameMap.Timer.IsGaming) { Thread.Sleep(500); } while (game.GameMap.Timer.IsGaming) { Thread.Sleep(1000); } endGameInfoSema.WaitOne(); mwr?.Dispose(); }
//shut down by timer, in case of client crash/hang private void _exitTimer_Tick(object sender, EventArgs e) { try { log.Info("Exiting by timer,timeout:" + _exitTimer.Interval); log.Info("==============SHUTTING DOWN=========="); _mainWorker.Shutdown(); _memServer.Dispose(); _inCommServer.Dispose(); _outCommServer.Dispose(); IsRunning = false; } catch (Exception ex) { log.Info("Exception on shutdown:" + ex.StackTrace); } }
static int Main(string[] args) { var version = Environment.Version; Log.InfoFormat("start at current directory {0}", Directory.GetCurrentDirectory()); Log.Info("parsing command args"); if (!ParseCommandLine(args)) { Log.Error("command line parse error"); return(0); } Log.InfoFormat("Starting plugin, settings:{0}", parametres); Log.InfoFormat("Statring cef runtime"); if (!CefRintimePrepare(args, temporaryDirectoryPath)) { Log.Error("cef runtime initialisation failed"); return(0); //immediate exit } try { Log.Info("starting cef worker"); var worker = new CefWorker(parametres.SharedFileName); worker.Init(parametres); Log.Info("Binding shared memory"); SharedTextureWriter server = new SharedTextureWriter(parametres.SharedFileName, parametres.TextureSize); MessageReader inSrv = MessageReader.Create(parametres.inCommFile, 10000); MessageWriter outSrv = MessageWriter.Create(parametres.outCommFile, 10000); Log.Info("complete to bind shared memory, ready and wait"); var app = new App(worker, server, inSrv, outSrv, false); Log.Info("Enter main loop"); try { while (app.IsRunning) { Application.DoEvents(); app.CheckMessage(); //check incoming messages } } catch (Exception e) { Log.ErrorFormat("abnormal exit main loop{0}", e.Message); } Log.Info("Exit main loop END DISPOSING ALL"); worker.Dispose(); server.Dispose(); inSrv.Dispose(); outSrv.Dispose(); } catch (Exception e) { Log.ErrorFormat("Unclean exit error {0}", e.Message); } GC.Collect(); GC.WaitForFullGCComplete(-1); Log.Info("CefRuntime.Shutdown"); CefRuntime.Shutdown(); Log.Info("Final exit"); return(0); }
public void Cleanup() => _writer?.Dispose();
public IEnumerator InitPlugin(int width, int height, string sharedfilename, string initialURL, bool enableWebRTC, bool enableGPU) { _localhostname = WWW.EscapeURL(sharedfilename); initialURL = RedirectLocalhost(initialURL); _pollthread = new Thread(BackgroundPollThread); _pollthread.Start(); //Initialization (for now) requires a predefined path to PluginServer, //so change this section if you move the folder //Also change the path in deployment script. StreamingAssetPath = Application.streamingAssetsPath; #if UNITY_EDITOR_64 string PluginServerPath = Path.Combine(Application.dataPath, @"SimpleWebBrowser\PluginServer\x64"); #else #if UNITY_EDITOR_32 string PluginServerPath = Application.dataPath + @"\SimpleWebBrowser\PluginServer\x86"; #else //HACK string AssemblyPath = System.Reflection.Assembly.GetExecutingAssembly().Location; //log this for error handling Debug.Log("Assembly path:" + AssemblyPath); AssemblyPath = Path.GetDirectoryName(AssemblyPath); //Managed AssemblyPath = Directory.GetParent(AssemblyPath).FullName; //<project>_Data AssemblyPath = Directory.GetParent(AssemblyPath).FullName; //required string PluginServerPath = AssemblyPath + @"\PluginServer"; #endif #endif Debug.Log("Starting server from:" + PluginServerPath); kWidth = width; kHeight = height; _sharedFileName = sharedfilename; //randoms Guid inID = Guid.NewGuid(); _outCommFile = inID.ToString(); Guid outID = Guid.NewGuid(); _inCommFile = outID.ToString(); _initialURL = initialURL; _enableWebRTC = enableWebRTC; _enableGPU = enableGPU; if (BrowserTexture == null) { BrowserTexture = new Texture2D(kWidth, kHeight, TextureFormat.BGRA32, false); if (OnTextureObjectUpdated != null) { OnTextureObjectUpdated(BrowserTexture); } } string args = BuildParamsString(); _connected = false; _inCommServer = null; _outCommServer = null; var pluginpath = Path.Combine(PluginServerPath, @"SharedPluginServer.exe"); while (!_connected) { try { _pluginProcess = new Process { StartInfo = new ProcessStartInfo { WorkingDirectory = PluginServerPath, FileName = pluginpath, Arguments = args } }; _pluginProcess.Start(); Initialized = false; } catch (Exception ex) { //log the file Debug.Log("FAILED TO START SERVER FROM:" + PluginServerPath + @"\SharedPluginServer.exe"); throw; } yield return(new WaitForSeconds(1.0f)); bool isReady = false; while (!isReady) { try { isReady = _pluginProcess.WaitForInputIdle(0); } catch (Exception e) { Debug.LogException(e); if (_pluginProcess.HasExited) { break; } } yield return(new WaitForSeconds(0.5f)); } MessageReader inserv = null; MessageWriter outserv = null; try { inserv = MessageReader.Open(_inCommFile); outserv = MessageWriter.Open(_outCommFile); _inCommServer = inserv; _outCommServer = outserv; _connected = true; } catch (Exception e) { if (_inCommServer != null) { _inCommServer.Dispose(); } if (_outCommServer != null) { _outCommServer.Dispose(); } _pluginProcess.Dispose(); } } }
public void Dispose() { _writer.Dispose(); }