Exemple #1
0
 public override void Create(SocketWrapperBase sock)
 {
     lock (m_syncRoot)
     {
         m_socket = ((HttpsSocket)sock).m_socket;
     }
 }
Exemple #2
0
        private void AcceptRequest(IAsyncResult result)
        {
            m_logProvider.LogRuntimeInfo(ZoneFlags.RequestListener, "+HttpRequestListener.AcceptRequest");

            try
            {
                // connected will be false if we've called for an explicit Stop to the server
                //TODO : check why the socket is not connected but it works
                //if ((Environment.OSVersion.Platform == PlatformID.WinCE) && (!m_serverSocket.Connected))
                //{
                //    // NOTE:
                //    // this appears to only be true under CE.  The desktop Connected state is false when the request is accepted.
                //    return;
                //}

                SocketWrapperBase listener = (SocketWrapperBase)result.AsyncState;
                if (listener.IsDisposed)
                {
                    return;
                }

                if (m_serverSocket.IsDisposed || m_shutDown)
                {
                    return;
                }

                SocketWrapperBase handler = listener.EndAccept(result);
                if ((handler == null) || (!handler.Connected))
                {
                    return;
                }

                RequestEventArgs e = new RequestEventArgs(handler);
                var orr            = OnReceiveRequest;
                if (orr != null)
                {
                    orr(this, e);
                }
            }
            catch (Exception ex)
            {
                string text = string.Format("HttpRequestListener.AcceptRequest threw {0}: {1}", ex.GetType().Name, ex.Message);
                m_logProvider.LogPadarnError(text, null);
            }
            finally
            {
                try
                {
                    m_serverSocket.BeginAccept(AcceptRequest, m_serverSocket);
                }
                catch (ObjectDisposedException)
                {
                    // this may occur on server shutdown - swallow it and move on
                }

                m_logProvider.LogRuntimeInfo(ZoneFlags.RequestListener, "-HttpRequestListener.AcceptRequest");
            }
        }
Exemple #3
0
        private void ProcessRequestWorker(object parm)
        {
            SocketWrapperBase sock = (SocketWrapperBase)parm;
            var et = Environment.TickCount;

            try
            {
                var client = (sock.RemoteEndPoint as IPEndPoint).Address;

                lock (m_clients)
                {
                    if (!m_clients.Contains(client))
                    {
                        if (m_clients.Count >= m_maxConnections)
                        {
                            var errorHandler = new DefaultWorkerRequest(sock, m_logProvider);
                            HttpRuntime.ProcessError(errorHandler, HttpErrorCode.Forbidden, "Maximum Connections Exceeded");
                            return;
                        }
                        else
                        {
                            m_clients.Add(client);
                        }
                    }
                }

                ThreadPool.QueueUserWorkItem(delegate
                {
                    try
                    {
                        HttpWorkerRequest wr = new AsyncWorkerRequest(sock, m_logProvider);
                        HttpRuntime.ProcessRequest(wr, m_logProvider);
                    }
                    catch (Exception ex)
                    {
                        string text = string.Format("HttpRuntime.ProcessRequest thread threw {0}: {1}", ex.GetType().Name, ex.Message);
                        m_logProvider.LogPadarnError(text, null);
                    }
                    finally
                    {
                        lock (m_clients)
                        {
                            m_clients.Remove(client);
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                string text = string.Format("HttpRequestListener.ProcessRequest threw {0}: {1}", ex.GetType().Name, ex.Message);
                m_logProvider.LogPadarnError(text, null);
            }
            finally
            {
                et = Environment.TickCount - et;
            }
        }
Exemple #4
0
        /// <summary>
        /// Create an instance of the listener on the specified port.
        /// </summary>
        /// <param name="port">The port to listen on for incoming requests.</param>
        /// <param name="maxConnections">The maximum number of clients that can concurrently connect to listener.</param>
        /// <param name="localIP"></param>
        public HttpRequestListener(IPAddress localIP, int port, int maxConnections, ILogProvider logProvider)
        {
            m_logProvider = logProvider;

            if (port <= 0)
            {
                throw new ArgumentException("port");
            }
            if (maxConnections <= 0)
            {
                throw new ArgumentException("maxConnections");
            }

            m_logProvider.LogRuntimeInfo(ZoneFlags.RequestListener | ZoneFlags.Startup, string.Format("Creating HttpRequestListener at {0}:{1} Max connections = {2}", localIP, port, maxConnections));

            m_maxConnections = maxConnections;
            m_port           = port;

            IPEndPoint localEndpoint = new IPEndPoint(localIP, m_port);

            if (ServerConfig.GetConfig().UseSsl == true)
            {
                m_logProvider.LogRuntimeInfo(ZoneFlags.RequestListener | ZoneFlags.Startup, "SSL Enabled");
                m_serverSocket = new HttpsSocket(m_logProvider);
            }
            else
            {
                m_logProvider.LogRuntimeInfo(ZoneFlags.RequestListener | ZoneFlags.Startup, "SSL Disabled");
                m_serverSocket = new HttpSocket();
            }
            m_serverSocket.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            try
            {
                m_logProvider.LogRuntimeInfo(ZoneFlags.RequestListener | ZoneFlags.Startup, string.Format("Binding to {0}:{1}", localEndpoint.Address, localEndpoint.Port));
                m_serverSocket.Bind(localEndpoint);
            }
            catch (Exception ex)
            {
                m_logProvider.LogRuntimeInfo(ZoneFlags.RequestListener | ZoneFlags.Startup, string.Format("Failed to binding to {0}:{1}: {2}", localEndpoint.Address, localEndpoint.Port, ex.Message));
                throw;
            }

            OnReceiveRequest += ProcessRequest;
        }
 public override void Create(OpenNETCF.Web.Server.SocketWrapperBase sock)
 {
     throw new System.NotImplementedException();
 }
Exemple #6
0
 //
 // Summary:
 //     Initializes a new instance of the System.Net.Sockets.NetworkStream class
 //     for the specified System.Net.Sockets.Socket with the specified System.Net.Sockets.Socket
 //     ownership.
 //
 // Parameters:
 //   socket:
 //     The System.Net.Sockets.Socket that the System.Net.Sockets.NetworkStream will
 //     use to send and receive data.
 //
 //   ownsSocket:
 //     true to indicate that the System.Net.Sockets.NetworkStream will take ownership
 //     of the System.Net.Sockets.Socket; otherwise, false.
 //
 // Exceptions:
 //   System.ArgumentNullException:
 //     socket is null.
 //
 //   System.IO.IOException:
 //     socket is not connected.-or- The value of the System.Net.Sockets.Socket.SocketType
 //     property of socket is not System.Net.Sockets.SocketType.Stream.-or- socket
 //     is in a nonblocking state.
 public NetworkStreamWrapperBase(SocketWrapperBase socket, bool ownsSocket)
 {
 }
Exemple #7
0
 public override void Create(SocketWrapperBase sock)
 {
     m_socket = ((SecureSocket)sock).m_socket;
 }
Exemple #8
0
 // Summary:
 //     Creates a new instance of the System.Net.Sockets.NetworkStream class for
 //     the specified System.Net.Sockets.Socket.
 //
 // Parameters:
 //   socket:
 //     The System.Net.Sockets.Socket that the System.Net.Sockets.NetworkStream will
 //     use to send and receive data.
 //
 // Exceptions:
 //   System.ArgumentNullException:
 //     socket is null.
 //
 //   System.IO.IOException:
 //     socket is not connected.-or- The System.Net.Sockets.Socket.SocketType property
 //     of socket is not System.Net.Sockets.SocketType.Stream.-or- socket is in a
 //     nonblocking state.
 public NetworkStreamWrapperBase(SocketWrapperBase socket)
 {
 }
Exemple #9
0
 //
 // Summary:
 //     Creates a new instance of the System.Net.Sockets.NetworkStream class for
 //     the specified System.Net.Sockets.Socket with the specified access rights
 //     and the specified System.Net.Sockets.Socket ownership.
 //
 // Parameters:
 //   socket:
 //     The System.Net.Sockets.Socket that the System.Net.Sockets.NetworkStream will
 //     use to send and receive data.
 //
 //   access:
 //     A bitwise combination of the System.IO.FileAccess values that specifies the
 //     type of access given to the System.Net.Sockets.NetworkStream over the provided
 //     System.Net.Sockets.Socket.
 //
 //   ownsSocket:
 //     true to indicate that the System.Net.Sockets.NetworkStream will take ownership
 //     of the System.Net.Sockets.Socket; otherwise, false.
 //
 // Exceptions:
 //   System.ArgumentNullException:
 //     socket is null.
 //
 //   System.IO.IOException:
 //     socket is not connected.-or- The System.Net.Sockets.Socket.SocketType property
 //     of socket is not System.Net.Sockets.SocketType.Stream.-or- socket is in a
 //     nonblocking state.
 public NetworkStreamWrapperBase(SocketWrapperBase socket, FileAccess access, bool ownsSocket)
 {
 }
Exemple #10
0
 //
 // Summary:
 //     Creates a new instance of the System.Net.Sockets.NetworkStream class for
 //     the specified System.Net.Sockets.Socket with the specified access rights.
 //
 // Parameters:
 //   socket:
 //     The System.Net.Sockets.Socket that the System.Net.Sockets.NetworkStream will
 //     use to send and receive data.
 //
 //   access:
 //     A bitwise combination of the System.IO.FileAccess values that specify the
 //     type of access given to the System.Net.Sockets.NetworkStream over the provided
 //     System.Net.Sockets.Socket.
 //
 // Exceptions:
 //   System.ArgumentNullException:
 //     socket is null.
 //
 //   System.IO.IOException:
 //     socket is not connected.-or- The System.Net.Sockets.Socket.SocketType property
 //     of socket is not System.Net.Sockets.SocketType.Stream.-or- socket is in a
 //     nonblocking state.
 public NetworkStreamWrapperBase(SocketWrapperBase socket, FileAccess access)
 {
 }
Exemple #11
0
 public RequestEventArgs(SocketWrapperBase socket)
 {
     m_socket = socket;
     m_stream = socket.CreateNetworkStream();
 }
Exemple #12
0
 public abstract void Create(SocketWrapperBase sock);