Beispiel #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);
            }
        }
        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);
            }
        }