public void clear() { using (MutexObject.section(_mutex)) { FileTools.deletePath(_messageDir); } }
public PostOfficeBox(String ident) { _ident = IDENT_PREFIX + StringTools.toHex(SecurityTools.getSHA512(StringTools.ENCODING_SJIS.GetBytes(ident))).Substring(0, 32); _mutex = new MutexObject(_ident + "_m"); _messagePostEvent = new NamedEventObject(_ident + "_e"); _messageDir = Path.Combine(Environment.GetEnvironmentVariable("TMP"), _ident); }
public static EnterLeave section(MutexObject m) { return(new EnterLeave(delegate { m.waitForever(); }, delegate { m.release(); })); }
public void Dispose() { if (_mutex != null) { _mutex.Dispose(); _mutex = null; _messagePostEvent.Dispose(); _messagePostEvent = null; } }
public void send(Queue <byte[]> sendData) { //Stopwatch sw = new Stopwatch(); // test //sw.Reset(); //sw.Start(); using (MutexObject.section(_mutex)) { //sw.Stop(); //laps.Add(sw.Elapsed.TotalMilliseconds); //sw.Reset(); //sw.Start(); getMessageRange(); //sw.Stop(); //laps.Add(sw.Elapsed.TotalMilliseconds); //sw.Reset(); //sw.Start(); tryRenumber(); //sw.Stop(); //laps.Add(sw.Elapsed.TotalMilliseconds); //sw.Reset(); //sw.Start(); if (_gmrLastNo == -1) { FileTools.deletePath(_messageDir); Directory.CreateDirectory(_messageDir); } //sw.Stop(); //laps.Add(sw.Elapsed.TotalMilliseconds); //sw.Reset(); //sw.Start(); using (FileStream wfs = new FileStream( Path.Combine(_messageDir, StringTools.zPad(_gmrLastNo + 1, 4)), FileMode.Create, FileAccess.Write )) foreach (byte[] block in sendData) { wfs.Write(block, 0, block.Length); } //sw.Stop(); //laps.Add(sw.Elapsed.TotalMilliseconds); //sw.Reset(); //sw.Start(); } //sw.Stop(); //laps.Add(sw.Elapsed.TotalMilliseconds); //sw.Reset(); //sw.Start(); _messagePostEvent.set(); //sw.Stop(); //laps.Add(sw.Elapsed.TotalMilliseconds); }
public static EnterLeave section(string name) { MutexObject m = new MutexObject(name); return(new EnterLeave(delegate { m.waitForever(); }, delegate { m.release(); m.Dispose(); })); }
public static EnterLeave deadSection(MutexObject m) { return(new EnterLeave(delegate { m.release(); // app > Thread.Sleep(1); // context switching // < app }, delegate { m.waitForever(); })); }
private byte[] tryRecv() { using (MutexObject.section(_mutex)) { getMessageRange(); if (_gmrFirstNo != -1) { String file = Path.Combine(_messageDir, StringTools.zPad(_gmrFirstNo, 4)); byte[] recvData = File.ReadAllBytes(file); FileTools.deletePath(file); if (_gmrFirstNo == _gmrLastNo) { FileTools.deletePath(_messageDir); } return(recvData); } } return(null); }