Example #1
0
        void StartRequest(Socket accepted, int reuses)
        {
            try {
                // The next line can throw (reusing and the client closed)
                Worker worker = webSource.CreateWorker(accepted, this);
                worker.SetReuseCount(reuses);
                if (worker.IsAsync)
                {
                    worker.Run(null);
                }
                else
                {
                    ThreadPool.QueueUserWorkItem(worker.Run);
                }
            } catch (Exception) {
                try {
                    if (accepted != null)
                    {
                        try {
                            if (accepted.Connected)
                            {
                                accepted.Shutdown(SocketShutdown.Both);
                            }
                        } catch {
                            // ignore
                        }

                        accepted.Close();
                    }
                } catch {
                    // ignore
                }
            }
        }
Example #2
0
        void StartRequest(Socket accepted, int reuses)
        {
            Worker worker = null;

            try {
                if (initialException != null)
                {
                    SendException(accepted, initialException);
                    initialException = null;
                    accepted.Close();
                    return;
                }

                // The next line can throw (reusing and the client closed)
                worker = webSource.CreateWorker(accepted, this);
                worker.SetReuseCount(reuses);
                if (false == worker.IsAsync)
                {
                    ThreadPool.QueueUserWorkItem(new WaitCallback(worker.Run));
                }
                else
                {
                    worker.Run(null);
                }
            } catch (Exception e) {
                try {
                    if (accepted != null)
                    {
                        try {
                            if (accepted.Connected)
                            {
                                accepted.Shutdown(SocketShutdown.Both);
                            }
                        } catch {
                            // ignore
                        }

                        accepted.Close();
                    }
                } catch {
                    // ignore
                }
            }
        }
        void StartRequest(Socket accepted, int reuses)
        {
            Worker worker = null;

            try {
                // The next line can throw (reusing and the client closed)
                worker = webSource.CreateWorker(accepted, this);
                worker.SetReuseCount(reuses);
                if (false == worker.IsAsync)
                {
                    ThreadPool.QueueUserWorkItem(new WaitCallback(worker.Run));
                }
                else
                {
                    worker.Run(null);
                }
            } catch (Exception) {
                try { accepted.Close(); } catch {}
            }
        }