public HttpListenerRequestStream(HttpConnectionState connectionState, long contentLength, bool readChunked)
 {
     #if DEBUG
     if (HttpTraceHelper.InternalLog.TraceVerbose)
     {
         HttpTraceHelper.WriteLine("ListenerRequestStream#" + HttpTraceHelper.HashString(this) + "::.ctor() contentLength:" + contentLength.ToString() + " readChunked:" + readChunked.ToString());
     }
     #endif
     m_ConnectionState = connectionState;
     m_ContentLength = contentLength;
     m_LeftToRead = contentLength;
     m_ChunkParserState = ParseState.ChunkSize;
     m_ReadChunked = readChunked;
     m_MoreToRead = m_ConnectionState.Request.Uploading;
 }
        public HttpListenerRequestStream(HttpConnectionState connectionState, long contentLength, bool readChunked)
        {
#if DEBUG
            if (HttpTraceHelper.InternalLog.TraceVerbose)
            {
                HttpTraceHelper.WriteLine("ListenerRequestStream#" + HttpTraceHelper.HashString(this) +
                                          "::.ctor() contentLength:" + contentLength + " readChunked:" + readChunked);
            }
#endif
            _connectionState  = connectionState;
            _contentLength    = contentLength;
            _leftToRead       = contentLength;
            _chunkParserState = ParseState.ChunkSize;
            _readChunked      = readChunked;
            DataAvailable     = _connectionState.Request.Uploading;
        }
        public HttpListenerRequestStream(HttpConnectionState connectionState, long contentLength, bool readChunked)
        {
#if DEBUG
            if (HttpTraceHelper.InternalLog.TraceVerbose)
            {
                HttpTraceHelper.WriteLine("ListenerRequestStream#" + HttpTraceHelper.HashString(this) +
                                          "::.ctor() contentLength:" + contentLength + " readChunked:" + readChunked);
            }
#endif
            _connectionState = connectionState;
            _contentLength = contentLength;
            _leftToRead = contentLength;
            _chunkParserState = ParseState.ChunkSize;
            _readChunked = readChunked;
            DataAvailable = _connectionState.Request.Uploading;
        }
 public HttpListenerWebRequest(HttpConnectionState connectionState)
 {
     #if DEBUG
     if (HttpTraceHelper.InternalLog.TraceVerbose)
     {
         HttpTraceHelper.WriteLine("HttpListenerWebRequest#" + HttpTraceHelper.HashString(this) + "::.ctor()");
     }
     #endif
     m_ConnectionState = connectionState;
     #if DEBUG
     if (HttpTraceHelper.Socket.TraceVerbose)
     {
         HttpTraceHelper.WriteLine("HttpListenerWebRequest#" + HttpTraceHelper.HashString(this) + "::.ctor() calling Socket.get_RemoteEndPoint()");
     }
     #endif
     m_RemoteEndPoint = (IPEndPoint)(connectionState.ConnectionSocket.RemoteEndPoint);
 }
        public HttpListenerWebRequest(HttpConnectionState connectionState)
        {
#if DEBUG
            if (HttpTraceHelper.InternalLog.TraceVerbose)
            {
                HttpTraceHelper.WriteLine("HttpListenerWebRequest#" + HttpTraceHelper.HashString(this) + "::.ctor()");
            }
#endif
            _connectionState = connectionState;
#if DEBUG
            if (HttpTraceHelper.Socket.TraceVerbose)
            {
                HttpTraceHelper.WriteLine("HttpListenerWebRequest#" + HttpTraceHelper.HashString(this) +
                                          "::.ctor() calling Socket.get_RemoteEndPoint()");
            }
#endif
            RemoteEndPoint = (IPEndPoint)(connectionState.ConnectionSocket.RemoteEndPoint);
        }
Example #6
0
        private static void AcceptCallback(IAsyncResult asyncResult)
        {
            var httpWebListener = asyncResult.AsyncState as HttpWebListener;
            Socket acceptedSocket;
            try
            {
                acceptedSocket = httpWebListener._accepterSocket.EndAccept(asyncResult);
            }
            catch (Exception exception)
            {
            #if DEBUG
                if (HttpTraceHelper.ExceptionCaught.TraceVerbose)
                {
                    HttpTraceHelper.WriteLine("HttpWebListener#" + HttpTraceHelper.HashString(httpWebListener) +
                                              "::Accepter() caught exception in Socket.EndAccept(): " + exception);
                }
            #endif
                httpWebListener.Stop();
                return;
            }

            try
            {
                httpWebListener._accepterSocket.BeginAccept(_staticAcceptCallback, httpWebListener);
            }
            catch (Exception exception)
            {
            #if DEBUG
                if (HttpTraceHelper.ExceptionCaught.TraceVerbose)
                {
                    HttpTraceHelper.WriteLine("HttpWebListener#" + HttpTraceHelper.HashString(httpWebListener) +
                                              "::Accepter() caught exception in Socket.BeginAccept(): " + exception);
                }
            #endif
                httpWebListener.Stop();
                return;
            }

            var connectionState = new HttpConnectionState(acceptedSocket, 4096, httpWebListener);
            lock (httpWebListener._acceptedConnections)
            {
            #if DEBUG
                if (HttpTraceHelper.InternalLog.TraceVerbose)
                {
                    HttpTraceHelper.WriteLine("HttpWebListener#" + HttpTraceHelper.HashString(httpWebListener) +
                                              "::Accepter() calling Add()");
                }
            #endif
                try
                {
                    httpWebListener._acceptedConnections.Add(connectionState);
                }
                catch (Exception exception)
                {
            #if DEBUG
                    if (HttpTraceHelper.ExceptionCaught.TraceVerbose)
                    {
                        HttpTraceHelper.WriteLine("HttpWebListener#" + HttpTraceHelper.HashString(httpWebListener) +
                                                  "::Accepter() caught exception in ArrayList.Add(): " + exception);
                    }
            #endif
                    return;
                }
            }
            //
            // now kick off async reading
            //
            #if DEBUG
            if (HttpTraceHelper.InternalLog.TraceVerbose)
            {
                HttpTraceHelper.WriteLine("HttpWebListener#" + HttpTraceHelper.HashString(httpWebListener) +
                                          "::Accepter() calling BeginReceive()");
            }
            #endif
            connectionState.StartReceiving();
        }
Example #7
0
        private static void AcceptCallback(IAsyncResult asyncResult)
        {
            var    httpWebListener = asyncResult.AsyncState as HttpWebListener;
            Socket acceptedSocket;

            try
            {
                acceptedSocket = httpWebListener._accepterSocket.EndAccept(asyncResult);
            }
            catch (Exception exception)
            {
#if DEBUG
                if (HttpTraceHelper.ExceptionCaught.TraceVerbose)
                {
                    HttpTraceHelper.WriteLine("HttpWebListener#" + HttpTraceHelper.HashString(httpWebListener) +
                                              "::Accepter() caught exception in Socket.EndAccept(): " + exception);
                }
#endif
                httpWebListener.Stop();
                return;
            }

            try
            {
                httpWebListener._accepterSocket.BeginAccept(_staticAcceptCallback, httpWebListener);
            }
            catch (Exception exception)
            {
#if DEBUG
                if (HttpTraceHelper.ExceptionCaught.TraceVerbose)
                {
                    HttpTraceHelper.WriteLine("HttpWebListener#" + HttpTraceHelper.HashString(httpWebListener) +
                                              "::Accepter() caught exception in Socket.BeginAccept(): " + exception);
                }
#endif
                httpWebListener.Stop();
                return;
            }

            var connectionState = new HttpConnectionState(acceptedSocket, 4096, httpWebListener);
            lock (httpWebListener._acceptedConnections)
            {
#if DEBUG
                if (HttpTraceHelper.InternalLog.TraceVerbose)
                {
                    HttpTraceHelper.WriteLine("HttpWebListener#" + HttpTraceHelper.HashString(httpWebListener) +
                                              "::Accepter() calling Add()");
                }
#endif
                try
                {
                    httpWebListener._acceptedConnections.Add(connectionState);
                }
                catch (Exception exception)
                {
#if DEBUG
                    if (HttpTraceHelper.ExceptionCaught.TraceVerbose)
                    {
                        HttpTraceHelper.WriteLine("HttpWebListener#" + HttpTraceHelper.HashString(httpWebListener) +
                                                  "::Accepter() caught exception in ArrayList.Add(): " + exception);
                    }
#endif
                    return;
                }
            }
            //
            // now kick off async reading
            //
#if DEBUG
            if (HttpTraceHelper.InternalLog.TraceVerbose)
            {
                HttpTraceHelper.WriteLine("HttpWebListener#" + HttpTraceHelper.HashString(httpWebListener) +
                                          "::Accepter() calling BeginReceive()");
            }
#endif
            connectionState.StartReceiving();
        }