private void OnCacheItemRemoved(string key, object value, CacheItemRemovedReason reason)
        {
            IntPtr        ptr;
            CachedContent content = (CachedContent)value;

            content._spinLock.AcquireWriterLock();
            try
            {
                ptr = content._stateItem;
                content._content   = null;
                content._stateItem = IntPtr.Zero;
            }
            finally
            {
                content._spinLock.ReleaseWriterLock();
            }
            UnsafeNativeMethods.STWNDDeleteStateItem(ptr);
            if ((content._extraFlags & 2) == 0)
            {
                switch (reason)
                {
                case CacheItemRemovedReason.Removed:
                    this.IncrementStateServiceCounter(StateServicePerfCounter.STATE_SERVICE_SESSIONS_ABANDONED);
                    break;

                case CacheItemRemovedReason.Expired:
                    this.IncrementStateServiceCounter(StateServicePerfCounter.STATE_SERVICE_SESSIONS_TIMED_OUT);
                    break;
                }
                this.DecrementStateServiceCounter(StateServicePerfCounter.STATE_SERVICE_SESSIONS_ACTIVE);
            }
        }
        private void ReportLocked(HttpContext context, CachedContent content)
        {
            HttpResponse response = context.Response;

            response.StatusCode = 0x1a7;
            DateTime time = DateTimeUtil.ConvertToLocalTime(content._utcLockDate);
            TimeSpan span = (TimeSpan)(DateTime.UtcNow - content._utcLockDate);
            long     num  = span.Ticks / 0x989680L;

            response.AppendHeader("LockDate", time.Ticks.ToString(CultureInfo.InvariantCulture));
            response.AppendHeader("LockAge", num.ToString(CultureInfo.InvariantCulture));
            response.AppendHeader("LockCookie", content._lockCookie.ToString(CultureInfo.InvariantCulture));
        }
Exemplo n.º 3
0
        internal /*public*/ void DoDelete(HttpContext context)
        {
            string        key           = CreateKey(context.Request);
            CacheInternal cacheInternal = HttpRuntime.CacheInternal;
            CachedContent content       = (CachedContent)cacheInternal.Get(key);

            /* If the item isn't there, we probably took too long to run. */
            if (content == null)
            {
                ReportNotFound(context);
                return;
            }

            int lockCookie;

            if (!GetOptionalNonNegativeInt32HeaderValue(context, StateHeaders.LOCKCOOKIE_NAME, out lockCookie))
            {
                return;
            }

            content._spinLock.AcquireWriterLock();
            try {
                if (content._content == null)
                {
                    ReportNotFound(context);
                    return;
                }

                /* Only remove the item if we are the owner */
                if (content._locked && (lockCookie == -1 || content._lockCookie != lockCookie))
                {
                    ReportLocked(context, content);
                    return;
                }

                /*
                 * If not locked, keep it locked until it is completely removed.
                 * Prevent overwriting when we drop the lock.
                 */
                content._locked     = true;
                content._lockCookie = 0;
            }
            finally {
                content._spinLock.ReleaseWriterLock();
            }


            cacheInternal.Remove(key);
        }
Exemplo n.º 4
0
        private void ReportLocked(HttpContext context, CachedContent content)
        {
            HttpResponse response;
            DateTime     localLockDate;
            long         lockAge;

            // Note that due to a


            response            = context.Response;
            response.StatusCode = 423;
            localLockDate       = DateTimeUtil.ConvertToLocalTime(content._utcLockDate);
            lockAge             = (DateTime.UtcNow - content._utcLockDate).Ticks / TimeSpan.TicksPerSecond;
            response.AppendHeader(StateHeaders.LOCKDATE_NAME_RAW, localLockDate.Ticks.ToString(CultureInfo.InvariantCulture));
            response.AppendHeader(StateHeaders.LOCKAGE_NAME_RAW, lockAge.ToString(CultureInfo.InvariantCulture));
            response.AppendHeader(StateHeaders.LOCKCOOKIE_NAME_RAW, content._lockCookie.ToString(CultureInfo.InvariantCulture));
        }
Exemplo n.º 5
0
        private void ReportLocked(HttpContext context, CachedContent content)
        {
            HttpResponse response;
            DateTime     localLockDate;
            long         lockAge;

            // Note that due to a bug in the RTM state server client,
            // we cannot add to body of the response when sending this
            // message, otherwise the client will leak memory.
            response            = context.Response;
            response.StatusCode = 423;
            localLockDate       = DateTimeUtil.ConvertToLocalTime(content._utcLockDate);
            lockAge             = (DateTime.UtcNow - content._utcLockDate).Ticks / TimeSpan.TicksPerSecond;
            response.AppendHeader(StateHeaders.LOCKDATE_NAME_RAW, localLockDate.Ticks.ToString(CultureInfo.InvariantCulture));
            response.AppendHeader(StateHeaders.LOCKAGE_NAME_RAW, lockAge.ToString(CultureInfo.InvariantCulture));
            response.AppendHeader(StateHeaders.LOCKCOOKIE_NAME_RAW, content._lockCookie.ToString(CultureInfo.InvariantCulture));
        }
        internal void DoDelete(HttpContext context)
        {
            string        key           = this.CreateKey(context.Request);
            CacheInternal cacheInternal = HttpRuntime.CacheInternal;
            CachedContent content       = (CachedContent)cacheInternal.Get(key);

            if (content == null)
            {
                this.ReportNotFound(context);
            }
            else
            {
                int num;
                if (this.GetOptionalNonNegativeInt32HeaderValue(context, "Http_LockCookie", out num))
                {
                    content._spinLock.AcquireWriterLock();
                    try
                    {
                        if (content._content == null)
                        {
                            this.ReportNotFound(context);
                            return;
                        }
                        if (content._locked && ((num == -1) || (content._lockCookie != num)))
                        {
                            this.ReportLocked(context, content);
                            return;
                        }
                        content._locked     = true;
                        content._lockCookie = 0;
                    }
                    finally
                    {
                        content._spinLock.ReleaseWriterLock();
                    }
                    cacheInternal.Remove(key);
                }
            }
        }
Exemplo n.º 7
0
        unsafe IntPtr FinishPut(HttpContext context)
        {
            HttpRequest  request  = context.Request;
            HttpResponse response = context.Response;
            Stream       requestStream;

            byte[]        buf;
            int           timeoutMinutes;
            TimeSpan      timeout;
            int           extraFlags;
            string        key;
            CachedContent content;
            CachedContent contentCurrent;
            int           lockCookie;
            int           lockCookieNew = 1;
            IntPtr        stateItem;
            CacheInternal cacheInternal = HttpRuntime.CacheInternal;

            /* create the content */
            requestStream = request.InputStream;
            int bufferSize = (int)(requestStream.Length - requestStream.Position);

            buf = new byte[bufferSize];
            requestStream.Read(buf, 0, buf.Length);

            fixed(byte *pBuf = buf)
            {
                // The ctor of StateHttpWorkerRequest convert the native pointer address
                // into an array of bytes, and in our we revert it back to an IntPtr
                stateItem = (IntPtr)(*((void **)pBuf));
            }

            /* get headers */
            if (!GetOptionalNonNegativeInt32HeaderValue(context, StateHeaders.TIMEOUT_NAME, out timeoutMinutes))
            {
                return(stateItem);
            }

            if (timeoutMinutes == -1)
            {
                timeoutMinutes = SessionStateModule.TIMEOUT_DEFAULT;
            }

            if (timeoutMinutes > SessionStateModule.MAX_CACHE_BASED_TIMEOUT_MINUTES)
            {
                ReportInvalidHeader(context, StateHeaders.TIMEOUT_NAME);
                return(stateItem);
            }

            timeout = new TimeSpan(0, timeoutMinutes, 0);

            bool found;

            if (!GetOptionalInt32HeaderValue(context, StateHeaders.EXTRAFLAGS_NAME, out extraFlags, out found))
            {
                return(stateItem);
            }

            if (!found)
            {
                extraFlags = 0;
            }

            /* lookup current value */
            key = CreateKey(request);
            CacheEntry entry = (CacheEntry)cacheInternal.Get(key, CacheGetOptions.ReturnCacheEntry);

            if (entry != null)
            {
                // DevDivBugs 146875: Expired Session State race condition
                // We make sure we do not overwrite an already existing item with an uninitialized item.
                if (((int)SessionStateItemFlags.Uninitialized & extraFlags) == 1)
                {
                    return(stateItem);
                }

                if (!GetOptionalNonNegativeInt32HeaderValue(context, StateHeaders.LOCKCOOKIE_NAME, out lockCookie))
                {
                    return(stateItem);
                }

                contentCurrent = (CachedContent)entry.Value;
                contentCurrent._spinLock.AcquireWriterLock();
                try {
                    if (contentCurrent._content == null)
                    {
                        ReportNotFound(context);
                        return(stateItem);
                    }

                    /* Only set the item if we are the owner */
                    if (contentCurrent._locked && (lockCookie == -1 || lockCookie != contentCurrent._lockCookie))
                    {
                        ReportLocked(context, contentCurrent);
                        return(stateItem);
                    }

                    if (entry.SlidingExpiration == timeout && contentCurrent._content != null)
                    {
                        /* delete the old state item */
                        IntPtr stateItemOld = contentCurrent._stateItem;

                        /* change the item in place */
                        contentCurrent._content   = buf;
                        contentCurrent._stateItem = stateItem;
                        contentCurrent._locked    = false;
                        return(stateItemOld);
                    }

                    /*
                     *  The timeout has changed.  In this case, we are removing the old item and
                     *  inserting a new one.
                     *  Update _extraFlags to ignore the cache item removed callback (this way,
                     *  we will not decrease the number of active sessions).
                     */
                    contentCurrent._extraFlags |= (int)SessionStateItemFlags.IgnoreCacheItemRemoved;

                    /*
                     * If not locked, keep it locked until it is completely replaced.
                     * Prevent overwriting when we drop the lock.
                     */
                    contentCurrent._locked     = true;
                    contentCurrent._lockCookie = 0;
                    lockCookieNew = lockCookie;
                }
                finally {
                    contentCurrent._spinLock.ReleaseWriterLock();
                }
            }

            content = new CachedContent(buf, stateItem, false, DateTime.MinValue, lockCookieNew, extraFlags);
            cacheInternal.UtcInsert(
                key, content, null, Cache.NoAbsoluteExpiration, timeout,
                CacheItemPriority.NotRemovable, _removedHandler);

            if (entry == null)
            {
                IncrementStateServiceCounter(StateServicePerfCounter.STATE_SERVICE_SESSIONS_TOTAL);
                IncrementStateServiceCounter(StateServicePerfCounter.STATE_SERVICE_SESSIONS_ACTIVE);
            }

            return(IntPtr.Zero);
        }
Exemplo n.º 8
0
        unsafe IntPtr FinishPut(HttpContext context) {
            HttpRequest         request = context.Request;   
            HttpResponse        response = context.Response; 
            Stream              requestStream;               
            byte[]              buf;                         
            int                 timeoutMinutes;
            TimeSpan            timeout;
            int                 extraFlags;
            string              key;                         
            CachedContent       content;
            CachedContent       contentCurrent;
            int                 lockCookie;
            int                 lockCookieNew = 1;
            IntPtr              stateItem;
            CacheInternal       cacheInternal = HttpRuntime.CacheInternal;

            /* create the content */
            requestStream = request.InputStream;
            int bufferSize = (int)(requestStream.Length - requestStream.Position);
            buf = new byte[bufferSize];
            requestStream.Read(buf, 0 , buf.Length);

            fixed (byte * pBuf = buf) {
                // The ctor of StateHttpWorkerRequest convert the native pointer address
                // into an array of bytes, and in our we revert it back to an IntPtr
                stateItem = (IntPtr)(*((void **)pBuf));
            }

            /* get headers */
            if (!GetOptionalNonNegativeInt32HeaderValue(context, StateHeaders.TIMEOUT_NAME, out timeoutMinutes)) {
                return stateItem;
            }

            if (timeoutMinutes == -1) {
                timeoutMinutes = SessionStateModule.TIMEOUT_DEFAULT;
            }

            if (timeoutMinutes > SessionStateModule.MAX_CACHE_BASED_TIMEOUT_MINUTES) {
                ReportInvalidHeader(context, StateHeaders.TIMEOUT_NAME);
                return stateItem;
            }

            timeout = new TimeSpan(0, timeoutMinutes, 0);

            bool found;
            if (!GetOptionalInt32HeaderValue(context, StateHeaders.EXTRAFLAGS_NAME, out extraFlags, out found)) {
                return stateItem;
            }

            if (!found) {
                extraFlags = 0;
            }

            /* lookup current value */
            key = CreateKey(request);
            CacheEntry entry = (CacheEntry) cacheInternal.Get(key, CacheGetOptions.ReturnCacheEntry);
            if (entry != null) {
                // DevDivBugs 146875: Expired Session State race condition
                // We make sure we do not overwrite an already existing item with an uninitialized item.
                if (((int)SessionStateItemFlags.Uninitialized & extraFlags) == 1) {
                    return stateItem;
                }
                
                if (!GetOptionalNonNegativeInt32HeaderValue(context, StateHeaders.LOCKCOOKIE_NAME, out lockCookie)) {
                    return stateItem;
                }

                contentCurrent = (CachedContent) entry.Value;
                contentCurrent._spinLock.AcquireWriterLock();
                try {
                    if (contentCurrent._content == null) {
                        ReportNotFound(context);
                        return stateItem;
                    }

                    /* Only set the item if we are the owner */
                    if (contentCurrent._locked && (lockCookie == -1 || lockCookie != contentCurrent._lockCookie)) {
                        ReportLocked(context, contentCurrent);
                        return stateItem;
                    }

                    if (entry.SlidingExpiration == timeout && contentCurrent._content != null) {
                        /* delete the old state item */
                        IntPtr stateItemOld = contentCurrent._stateItem;

                        /* change the item in place */
                        contentCurrent._content = buf;
                        contentCurrent._stateItem = stateItem;
                        contentCurrent._locked = false;
                        return stateItemOld;
                    }

                    /*
                        The timeout has changed.  In this case, we are removing the old item and
                        inserting a new one.
                        Update _extraFlags to ignore the cache item removed callback (this way,
                        we will not decrease the number of active sessions).
                     */
                    contentCurrent._extraFlags |= (int)SessionStateItemFlags.IgnoreCacheItemRemoved;

                    /*
                     * If not locked, keep it locked until it is completely replaced.
                     * Prevent overwriting when we drop the lock.
                     */
                    contentCurrent._locked = true;
                    contentCurrent._lockCookie = 0;
                    lockCookieNew = lockCookie;
                }
                finally {
                    contentCurrent._spinLock.ReleaseWriterLock();
                }
            }

            content = new CachedContent(buf, stateItem, false, DateTime.MinValue, lockCookieNew, extraFlags);
            cacheInternal.UtcInsert(
                    key, content, null, Cache.NoAbsoluteExpiration, timeout,
                    CacheItemPriority.NotRemovable, _removedHandler);

            if (entry == null) {
                IncrementStateServiceCounter(StateServicePerfCounter.STATE_SERVICE_SESSIONS_TOTAL);
                IncrementStateServiceCounter(StateServicePerfCounter.STATE_SERVICE_SESSIONS_ACTIVE);
            }

            return IntPtr.Zero;
        }
Exemplo n.º 9
0
        private void ReportLocked(HttpContext context, CachedContent content) {
            HttpResponse    response;
            DateTime        localLockDate;
            long            lockAge;

            // Note that due to a bug in the RTM state server client, 
            // we cannot add to body of the response when sending this
            // message, otherwise the client will leak memory.
            response = context.Response;
            response.StatusCode = 423;
            localLockDate = DateTimeUtil.ConvertToLocalTime(content._utcLockDate);
            lockAge = (DateTime.UtcNow - content._utcLockDate).Ticks / TimeSpan.TicksPerSecond;
            response.AppendHeader(StateHeaders.LOCKDATE_NAME_RAW, localLockDate.Ticks.ToString(CultureInfo.InvariantCulture));
            response.AppendHeader(StateHeaders.LOCKAGE_NAME_RAW, lockAge.ToString(CultureInfo.InvariantCulture));
            response.AppendHeader(StateHeaders.LOCKCOOKIE_NAME_RAW, content._lockCookie.ToString(CultureInfo.InvariantCulture));
        }
        internal void DoGet(HttpContext context)
        {
            HttpRequest  request  = context.Request;
            HttpResponse response = context.Response;
            string       key      = this.CreateKey(request);
            CacheEntry   entry    = (CacheEntry)HttpRuntime.CacheInternal.Get(key, CacheGetOptions.ReturnCacheEntry);

            if (entry == null)
            {
                this.ReportNotFound(context);
            }
            else
            {
                string        str     = request.Headers["Http_Exclusive"];
                CachedContent content = (CachedContent)entry.Value;
                content._spinLock.AcquireWriterLock();
                try
                {
                    if (content._content == null)
                    {
                        this.ReportNotFound(context);
                    }
                    else
                    {
                        int comparand = content._extraFlags;
                        if (((comparand & 1) != 0) && (comparand == Interlocked.CompareExchange(ref content._extraFlags, comparand & -2, comparand)))
                        {
                            this.ReportActionFlags(context, 1);
                        }
                        if (str == "release")
                        {
                            int num;
                            if (this.GetRequiredNonNegativeInt32HeaderValue(context, "Http_LockCookie", out num))
                            {
                                if (content._locked)
                                {
                                    if (num == content._lockCookie)
                                    {
                                        content._locked = false;
                                    }
                                    else
                                    {
                                        this.ReportLocked(context, content);
                                    }
                                }
                                else
                                {
                                    context.Response.StatusCode = 200;
                                }
                            }
                        }
                        else if (content._locked)
                        {
                            this.ReportLocked(context, content);
                        }
                        else
                        {
                            if (str == "acquire")
                            {
                                content._locked      = true;
                                content._utcLockDate = DateTime.UtcNow;
                                content._lockCookie++;
                                response.AppendHeader("LockCookie", content._lockCookie.ToString(CultureInfo.InvariantCulture));
                            }
                            response.AppendHeader("Timeout", ((int)(entry.SlidingExpiration.Ticks / 0x23c34600L)).ToString(CultureInfo.InvariantCulture));
                            Stream outputStream = response.OutputStream;
                            byte[] buffer       = content._content;
                            outputStream.Write(buffer, 0, buffer.Length);
                            response.Flush();
                        }
                    }
                }
                finally
                {
                    content._spinLock.ReleaseWriterLock();
                }
            }
        }
        private unsafe IntPtr FinishPut(HttpContext context)
        {
            int           num;
            int           num2;
            IntPtr        ptr;
            bool          flag;
            HttpRequest   request       = context.Request;
            HttpResponse  response      = context.Response;
            int           lockCookie    = 1;
            CacheInternal cacheInternal = HttpRuntime.CacheInternal;
            Stream        inputStream   = request.InputStream;
            int           num5          = (int)(inputStream.Length - inputStream.Position);

            byte[] buffer = new byte[num5];
            inputStream.Read(buffer, 0, buffer.Length);
            fixed(byte *numRef = buffer)
            {
                ptr = *((IntPtr *)numRef);
            }

            if (!this.GetOptionalNonNegativeInt32HeaderValue(context, "Http_Timeout", out num))
            {
                return(ptr);
            }
            if (num == -1)
            {
                num = 20;
            }
            if (num > 0x80520)
            {
                this.ReportInvalidHeader(context, "Http_Timeout");
                return(ptr);
            }
            TimeSpan slidingExpiration = new TimeSpan(0, num, 0);

            if (!this.GetOptionalInt32HeaderValue(context, "Http_ExtraFlags", out num2, out flag))
            {
                return(ptr);
            }
            if (!flag)
            {
                num2 = 0;
            }
            string     key   = this.CreateKey(request);
            CacheEntry entry = (CacheEntry)cacheInternal.Get(key, CacheGetOptions.ReturnCacheEntry);

            if (entry != null)
            {
                int num3;
                if ((1 & num2) == 1)
                {
                    return(ptr);
                }
                if (!this.GetOptionalNonNegativeInt32HeaderValue(context, "Http_LockCookie", out num3))
                {
                    return(ptr);
                }
                CachedContent content2 = (CachedContent)entry.Value;
                content2._spinLock.AcquireWriterLock();
                try
                {
                    if (content2._content == null)
                    {
                        this.ReportNotFound(context);
                        return(ptr);
                    }
                    if (content2._locked && ((num3 == -1) || (num3 != content2._lockCookie)))
                    {
                        this.ReportLocked(context, content2);
                        return(ptr);
                    }
                    if ((entry.SlidingExpiration == slidingExpiration) && (content2._content != null))
                    {
                        IntPtr ptr2 = content2._stateItem;
                        content2._content   = buffer;
                        content2._stateItem = ptr;
                        content2._locked    = false;
                        return(ptr2);
                    }
                    content2._extraFlags |= 2;
                    content2._locked      = true;
                    content2._lockCookie  = 0;
                    lockCookie            = num3;
                }
                finally
                {
                    content2._spinLock.ReleaseWriterLock();
                }
            }
            CachedContent content = new CachedContent(buffer, ptr, false, DateTime.MinValue, lockCookie, num2);

            cacheInternal.UtcInsert(key, content, null, Cache.NoAbsoluteExpiration, slidingExpiration, CacheItemPriority.NotRemovable, this._removedHandler);
            if (entry == null)
            {
                this.IncrementStateServiceCounter(StateServicePerfCounter.STATE_SERVICE_SESSIONS_TOTAL);
                this.IncrementStateServiceCounter(StateServicePerfCounter.STATE_SERVICE_SESSIONS_ACTIVE);
            }
            return(IntPtr.Zero);
        }
Exemplo n.º 12
0
        unsafe IntPtr FinishPut(HttpContext context)
        {
            HttpRequest  request  = context.Request;
            HttpResponse response = context.Response;
            Stream       requestStream;

            byte[]        buf;
            int           timeoutMinutes;
            TimeSpan      timeout;
            string        key;
            CachedContent content;
            CachedContent contentCurrent;
            int           lockCookie;
            IntPtr        stateItem;
            CacheInternal cacheInternal = HttpRuntime.CacheInternal;

            /* create the content */
            requestStream = request.InputStream;
            int bufferSize = (int)(requestStream.Length - requestStream.Position);

            buf = new byte[bufferSize];
            requestStream.Read(buf, 0, buf.Length);

            fixed(byte *pBuf = buf)
            {
                stateItem = (IntPtr)(*((void **)pBuf));
            }

            /* get headers */
            if (!GetOptionalNonNegativeInt32HeaderValue(context, StateHeaders.TIMEOUT_NAME, out timeoutMinutes))
            {
                return(stateItem);
            }

            if (timeoutMinutes == -1)
            {
                timeoutMinutes = SessionStateModule.TIMEOUT_DEFAULT;
            }

            timeout = new TimeSpan(0, timeoutMinutes, 0);

            /* lookup current value */
            key = CreateKey(request);
            CacheEntry entry = (CacheEntry)cacheInternal.Get(key, CacheGetOptions.ReturnCacheEntry);

            if (entry != null)
            {
                if (!GetOptionalNonNegativeInt32HeaderValue(context, StateHeaders.LOCKCOOKIE_NAME, out lockCookie))
                {
                    return(stateItem);
                }

                contentCurrent = (CachedContent)entry.Value;
                contentCurrent._spinLock.AcquireWriterLock();
                try {
                    if (contentCurrent._content == null)
                    {
                        ReportNotFound(context);
                        return(stateItem);
                    }

                    /* Only set the item if we are the owner */
                    if (contentCurrent._locked && (lockCookie == -1 || lockCookie != contentCurrent._lockCookie))
                    {
                        ReportLocked(context, contentCurrent);
                        return(stateItem);
                    }

                    if (entry.SlidingExpiration == timeout && contentCurrent._content != null)
                    {
                        /* delete the old state item */
                        IntPtr stateItemOld = contentCurrent._stateItem;

                        /* change the item in place */
                        contentCurrent._content   = buf;
                        contentCurrent._stateItem = stateItem;
                        contentCurrent._locked    = false;
                        return(stateItemOld);
                    }

                    /*
                     * If not locked, keep it locked until it is completely replaced.
                     * Prevent overwriting when we drop the lock.
                     */
                    contentCurrent._locked     = true;
                    contentCurrent._lockCookie = 0;
                }
                finally {
                    contentCurrent._spinLock.ReleaseWriterLock();
                }
            }

            content = new CachedContent(buf, stateItem, false, DateTime.MinValue, 1);
            cacheInternal.UtcInsert(
                key, content, null, Cache.NoAbsoluteExpiration, timeout,
                CacheItemPriority.NotRemovable, _removedHandler);

            if (entry == null)
            {
                IncrementGlobalCounter(GlobalPerfCounter.STATE_SERVER_SESSIONS_TOTAL);
                IncrementGlobalCounter(GlobalPerfCounter.STATE_SERVER_SESSIONS_ACTIVE);
            }

            return(IntPtr.Zero);
        }
 private void ReportLocked(HttpContext context, CachedContent content)
 {
     HttpResponse response = context.Response;
     response.StatusCode = 0x1a7;
     DateTime time = DateTimeUtil.ConvertToLocalTime(content._utcLockDate);
     TimeSpan span = (TimeSpan) (DateTime.UtcNow - content._utcLockDate);
     long num = span.Ticks / 0x989680L;
     response.AppendHeader("LockDate", time.Ticks.ToString(CultureInfo.InvariantCulture));
     response.AppendHeader("LockAge", num.ToString(CultureInfo.InvariantCulture));
     response.AppendHeader("LockCookie", content._lockCookie.ToString(CultureInfo.InvariantCulture));
 }
 private unsafe IntPtr FinishPut(HttpContext context)
 {
     int num;
     int num2;
     IntPtr ptr;
     bool flag;
     HttpRequest request = context.Request;
     HttpResponse response = context.Response;
     int lockCookie = 1;
     CacheInternal cacheInternal = HttpRuntime.CacheInternal;
     Stream inputStream = request.InputStream;
     int num5 = (int) (inputStream.Length - inputStream.Position);
     byte[] buffer = new byte[num5];
     inputStream.Read(buffer, 0, buffer.Length);
     fixed (byte* numRef = buffer)
     {
         ptr = *((IntPtr*) numRef);
     }
     if (!this.GetOptionalNonNegativeInt32HeaderValue(context, "Http_Timeout", out num))
     {
         return ptr;
     }
     if (num == -1)
     {
         num = 20;
     }
     if (num > 0x80520)
     {
         this.ReportInvalidHeader(context, "Http_Timeout");
         return ptr;
     }
     TimeSpan slidingExpiration = new TimeSpan(0, num, 0);
     if (!this.GetOptionalInt32HeaderValue(context, "Http_ExtraFlags", out num2, out flag))
     {
         return ptr;
     }
     if (!flag)
     {
         num2 = 0;
     }
     string key = this.CreateKey(request);
     CacheEntry entry = (CacheEntry) cacheInternal.Get(key, CacheGetOptions.ReturnCacheEntry);
     if (entry != null)
     {
         int num3;
         if ((1 & num2) == 1)
         {
             return ptr;
         }
         if (!this.GetOptionalNonNegativeInt32HeaderValue(context, "Http_LockCookie", out num3))
         {
             return ptr;
         }
         CachedContent content2 = (CachedContent) entry.Value;
         content2._spinLock.AcquireWriterLock();
         try
         {
             if (content2._content == null)
             {
                 this.ReportNotFound(context);
                 return ptr;
             }
             if (content2._locked && ((num3 == -1) || (num3 != content2._lockCookie)))
             {
                 this.ReportLocked(context, content2);
                 return ptr;
             }
             if ((entry.SlidingExpiration == slidingExpiration) && (content2._content != null))
             {
                 IntPtr ptr2 = content2._stateItem;
                 content2._content = buffer;
                 content2._stateItem = ptr;
                 content2._locked = false;
                 return ptr2;
             }
             content2._extraFlags |= 2;
             content2._locked = true;
             content2._lockCookie = 0;
             lockCookie = num3;
         }
         finally
         {
             content2._spinLock.ReleaseWriterLock();
         }
     }
     CachedContent content = new CachedContent(buffer, ptr, false, DateTime.MinValue, lockCookie, num2);
     cacheInternal.UtcInsert(key, content, null, Cache.NoAbsoluteExpiration, slidingExpiration, CacheItemPriority.NotRemovable, this._removedHandler);
     if (entry == null)
     {
         this.IncrementStateServiceCounter(StateServicePerfCounter.STATE_SERVICE_SESSIONS_TOTAL);
         this.IncrementStateServiceCounter(StateServicePerfCounter.STATE_SERVICE_SESSIONS_ACTIVE);
     }
     return IntPtr.Zero;
 }
Exemplo n.º 15
0
        private void ReportLocked(HttpContext context, CachedContent content) {
            HttpResponse    response;
            DateTime        localLockDate;
            long            lockAge;

            // Note that due to a 


            response = context.Response;
            response.StatusCode = 423;
            localLockDate = DateTimeUtil.ConvertToLocalTime(content._utcLockDate);
            lockAge = (DateTime.UtcNow - content._utcLockDate).Ticks / TimeSpan.TicksPerSecond;
            response.AppendHeader(StateHeaders.LOCKDATE_NAME_RAW, localLockDate.Ticks.ToString(CultureInfo.InvariantCulture));
            response.AppendHeader(StateHeaders.LOCKAGE_NAME_RAW, lockAge.ToString(CultureInfo.InvariantCulture));
            response.AppendHeader(StateHeaders.LOCKCOOKIE_NAME_RAW, content._lockCookie.ToString(CultureInfo.InvariantCulture));
        }