示例#1
0
 public void clear()
 {
     using (MutexObject.section(_mutex))
     {
         FileTools.deletePath(_messageDir);
     }
 }
示例#2
0
 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);
 }
示例#3
0
 public static EnterLeave section(MutexObject m)
 {
     return(new EnterLeave(delegate
     {
         m.waitForever();
     },
                           delegate
     {
         m.release();
     }));
 }
示例#4
0
            public void Dispose()
            {
                if (_mutex != null)
                {
                    _mutex.Dispose();
                    _mutex = null;

                    _messagePostEvent.Dispose();
                    _messagePostEvent = null;
                }
            }
示例#5
0
            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);
            }
示例#6
0
        public static EnterLeave section(string name)
        {
            MutexObject m = new MutexObject(name);

            return(new EnterLeave(delegate
            {
                m.waitForever();
            },
                                  delegate
            {
                m.release();
                m.Dispose();
            }));
        }
示例#7
0
        public static EnterLeave deadSection(MutexObject m)
        {
            return(new EnterLeave(delegate
            {
                m.release();

                // app >

                Thread.Sleep(1);                 // context switching

                // < app
            },
                                  delegate
            {
                m.waitForever();
            }));
        }
示例#8
0
            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);
            }