Example #1
0
        void Execute(ref Request req)
        {
            HandleImpl handle = req.handle;

            if (handle.done)             // もう終わってる。たぶんエラー
            {
                // 何もしない
            }
            else if (!handle.opened)             // 開いてない。開ける要求と解釈する
            {
                handle.BeginWrite(_root, _temporaryFilePostfix);
            }
            else if (req.length == 0)             // 書き込むものがない。閉じる要求と解釈する
            {
                handle.EndWrite(_root);
            }
            else             // 開いていて書きこむ
            {
                int length0 = Mathf.Min(_buffer.Length - req.offset, req.length);
                handle.Write(_buffer, req.offset, length0);
                int length1 = req.length - length0;
                if (length1 > 0)
                {
                    handle.Write(_buffer, 0, length1);
                }
                int rp = _readPos;
                rp += req.length;
                if (rp >= _buffer.Length)
                {
                    rp -= _buffer.Length;
                }
                Interlocked.Exchange(ref _readPos, rp);
            }
        }
        public Handle Begin(string path)
        {
            Debug.Assert(path != null);
            Debug.Assert(!path.Contains("/../"));
            var handle = new HandleImpl(path);

            Enqueue(Request.Type.Begin, handle, 0, 0);
            return(handle);
        }
        void Execute(ref Request req)
        {
            HandleImpl handle = req.handle;

            Request.Type type = req.type;
            if (handle.done)
            {
                // 終わってれば前の要求に重なっている。でもバグじゃね?
                Debug.Assert(false, "Handle.done == true. バグじゃね?");
            }
            else if (type == Request.Type.None)
            {
                // 何もしない
                Debug.Assert(false, "Request.type == None. バグじゃね?");
            }
            else if (type == Request.Type.Begin)             // 開いてない。開ける要求と解釈する
            {
                Debug.Assert(!handle.opened);
                handle.BeginWrite(_root, _temporaryFilePostfix);
            }
            else if (type == Request.Type.End)             // 書き込むものがない。閉じる要求と解釈する
            {
                handle.EndWrite(_root);
            }
            else if (type == Request.Type.Abort)
            {
                handle.Abort();
            }
            else if (type == Request.Type.Write)
            {
                int length0 = Mathf.Min(_buffer.Length - req.offset, req.length);
                handle.Write(_buffer, req.offset, length0);
                int length1 = req.length - length0;
                if (length1 > 0)
                {
                    handle.Write(_buffer, 0, length1);
                }
                int rp = _readPos;
                rp += req.length;
                if (rp >= _buffer.Length)
                {
                    rp -= _buffer.Length;
                }
                Interlocked.Exchange(ref _readPos, rp);
            }
            else
            {
                Debug.Assert(false, "Unknown RequestType. " + (int)type);
            }
        }
Example #4
0
        public String addticktime(Int64 process, tickHandle handle)
        {
            process += Tick;
            if (!addtickHandle.ContainsKey(process))
            {
                addtickHandle.Add(process, new List <HandleImpl>());
            }

            var impl = new HandleImpl(handle);
            var uuid = System.Guid.NewGuid().ToString();

            addtickHandle[process].Add(impl);
            delimpldict.Add(uuid, impl);

            return(uuid);
        }
Example #5
0
        void Execute(ref Request req)
        {
            HandleImpl handle = req.handle;

            try
            {
                if (handle.done)                 // もう終わってるのに来てるのは不正
                {
                    Debug.Assert(false);
                }
                else if (!handle.opened)                 // 開いてない。開ける要求と解釈する
                {
                    handle.Open(_root);
                }
                else if (req.length == 0)                 // 書き込むものがない。閉じる要求と解釈する
                {
                    handle.Close();
                }
                else                 // 開いていて書きこむ
                {
                    int length0 = Mathf.Min(_buffer.Length - req.offset, req.length);
                    handle.Write(_buffer, req.offset, length0);
                    int length1 = req.length - length0;
                    if (length1 > 0)
                    {
                        handle.Write(_buffer, 0, length1);
                    }
                    int rp = _readPos;
                    rp += req.length;
                    if (rp >= _buffer.Length)
                    {
                        rp -= _buffer.Length;
                    }
                    Interlocked.Exchange(ref _readPos, rp);
//Debug.Log("Read: " + req.handle.path + " " + _buffer.Length + " " + _writePos + " " + _readPos + " " + req.offset + " " + req.length + " -> " + length0 + " " + length1);
                }
            }
            catch (System.Exception e)
            {
                handle.Close();                 // 何かしくじったら閉じて終わらせる TODO: 真面目なエラー処理
                Debug.LogException(e);
            }
        }
Example #6
0
        public String addloopdaytime(int hour, int minute, int second, timeHandle handle)
        {
            day_time key = new day_time();

            key.hour   = hour;
            key.minute = minute;
            key.second = second;
            if (!adddaytimeHandle.ContainsKey(key))
            {
                adddaytimeHandle.Add(key, new List <HandleImpl>());
            }

            var impl = new HandleImpl(handle);
            var uuid = System.Guid.NewGuid().ToString();

            adddaytimeHandle[key].Add(impl);
            delimpldict.Add(uuid, impl);

            return(uuid);
        }