TcpWorkerProcess.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / SMSvcHost / System / ServiceModel / Activation / TcpWorkerProcess.cs / 1 / TcpWorkerProcess.cs

                            //------------------------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------------------------

namespace System.ServiceModel.Activation 
{
    using System; 
    using System.Diagnostics; 
    using System.Globalization;
    using System.ServiceModel; 
    using System.Net.Sockets;
    using System.ServiceModel.Channels;
    using System.ServiceModel.Diagnostics;
    using System.ServiceModel.Activation.Diagnostics; 
    using EventLogCategory = System.ServiceModel.Diagnostics.EventLogCategory;
    using EventLogEventId = System.ServiceModel.Diagnostics.EventLogEventId; 
 
    class TcpWorkerProcess : WorkerProcess
    { 
        protected override DuplicateContext DuplicateConnection(ListenerSessionConnection session)
        {
            bool success = false;
            SocketInformation dupedSocket = default(SocketInformation); 
            try
            { 
                dupedSocket = (SocketInformation)session.Connection.DuplicateAndClose(this.ProcessId); 
                success = true;
            } 
#pragma warning suppress 56500 // covered by FxCOP
            catch (Exception exception)
            {
                if (DiagnosticUtility.IsFatal(exception)) 
                {
                    throw; 
                } 

                // this normally happens if: 
                // A) we don't have rights to duplicate handles to the WorkerProcess NativeErrorCode == 10022
                // B) we fail to duplicate handle because the WorkerProcess is exiting/exited NativeErrorCode == 10024
                // - in the self hosted case: report error to the client
                // - in the web hosted case: roundrobin to the next available WorkerProcess (if this WorkerProcess is down?) 
#if DEBUG
                if (exception is SocketException) 
                { 
                    Debug.Print("TcpWorkerProcess.DuplicateConnection() failed duplicating socket for processId: " + this.ProcessId + " errorCode:" + ((SocketException)exception).NativeErrorCode + " exception:" + exception.Message);
                } 
#endif
                if (DiagnosticUtility.ShouldTraceError)
                {
                    ListenerTraceUtility.TraceEvent(TraceEventType.Error, TraceCode.MessageQueueDuplicatedSocketError, this, exception); 
                }
            } 
 
            if (success)
            { 
                if (DiagnosticUtility.ShouldTraceInformation)
                {
                    ListenerTraceUtility.TraceEvent(TraceEventType.Information, TraceCode.MessageQueueDuplicatedSocket, this);
                } 

                return new TcpDuplicateContext(dupedSocket, session.Via, session.Data); 
            } 

            return null; 
        }

        protected override void OnDispatchSuccess()
        { 
            ListenerPerfCounters.IncrementConnectionsDispatchedTcp();
        } 
 
        protected override TransportType TransportType
        { 
            get
            {
                return TransportType.Tcp;
            } 
        }
    } 
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.


                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK