예제 #1
0
        private async Task Incoming(HttpListenerContext context)
        {
            try
            {
                _tracingHttpServerSource.TraceEvent(TraceEventType.Verbose, TRACEEVENT_RECEIVED);
                Interlocked.Increment(ref _requestCount);

                HttpClientImpl client = new HttpClientImpl(context)
                {
                    StartTicks = _timer.ElapsedTicks
                };

                var currentActive = Interlocked.Increment(ref _activeCount);
                var maxActive     = Interlocked.Read(ref _maxActive);
                maxActive = Math.Max(currentActive, maxActive);
                Interlocked.Exchange(ref _maxActive, maxActive); // it is possible to overwrite a higher value on a different thread but it's good enough

                byte[] buffer = new byte[1024];
                int    read   = 0;

                ChunkBase root = null;

                if (Path.GetExtension(context.Request.RawUrl) == "")
                {
                    client.Context.Response.ContentType = "application/json";
                    root = new RESTChunk(this);
                }
                else if (context.Request.RawUrl.EndsWith(".page"))
                {
                    client.Context.Response.ContentType = "text/html";
                    root = new PageChunk(this, null);
                }
                else
                {
                    client.Context.Response.ContentType = "application/octet";
                    root = new FileChunk(this);
                }

                await root.Send(client, null);

                client.StopTicks = _timer.ElapsedTicks;

                Interlocked.Add(ref _tickCount, client.TimetoLastByte);
            }
            catch (Exception ex)
            {
                _tracingHttpServerSource.TraceData(TraceEventType.Error, TRACEEVENT_ERROR, ex);
            }
            finally
            {
                Interlocked.Increment(ref _requestCompleteCount);
                Interlocked.Decrement(ref _activeCount);
            }
        }
예제 #2
0
        /// <summary>
        ///     Allocates a single page of size <see cref="PAGE_SIZE" /> near the provided address.
        ///     Attempts to allocate the page within the +-1GB region of the hinted address.
        /// </summary>
        /// <param name="hint">Address near which to attempt to allocate the page.</param>
        /// <returns>Address to the allocated page.</returns>
        public virtual IntPtr Allocate(IntPtr hint)
        {
            foreach (var allocatedChunk in allocatedChunks)
            {
                // Small shortcut to speed up page lookup
                if (allocatedChunk.UsedPages == PAGES_PER_UNIT)
                {
                    continue;
                }
                for (var i = 0; i < allocatedChunk.Pages.Length; i++)
                {
                    if (allocatedChunk.Pages[i])
                    {
                        continue;
                    }
                    var pageAddr = allocatedChunk.GetPage(i);
                    if (!IsInRelJmpRange(hint, pageAddr))
                    {
                        continue;
                    }
                    allocatedChunk.Pages[i] = true;
                    allocatedChunk.UsedPages++;
                    return(pageAddr);
                }
            }

            var chunk = new PageChunk
            {
                BaseAddress = AllocateChunk(hint)
            };

            allocatedChunks.Add(chunk);
            chunk.Pages[0] = true;
            chunk.UsedPages++;
            return(chunk.BaseAddress);
        }