コード例 #1
0
        internal UdpChannelListener(UdpTransportBindingElement udpTransportBindingElement, BindingContext context)
            : base(context.Binding)
        {
            Fx.Assert(udpTransportBindingElement != null, "udpTransportBindingElement can't be null");
            Fx.Assert(context != null, "BindingContext parameter can't be null");

            this.udpTransportBindingElement = udpTransportBindingElement;
            this.cleanedUp = 0;

            this.duplicateDetector = null;

            if (udpTransportBindingElement.DuplicateMessageHistoryLength > 0)
            {
                this.duplicateDetector = new DuplicateMessageDetector(udpTransportBindingElement.DuplicateMessageHistoryLength);
            }

            this.onChannelClosed = new EventHandler(OnChannelClosed);

            // We should only throw this exception if the user specified realistic MaxReceivedMessageSize less than or equal to max message size over UDP.
            // If the user specified something bigger like Long.MaxValue, we shouldn't stop them.
            if (this.udpTransportBindingElement.MaxReceivedMessageSize <= UdpConstants.MaxMessageSizeOverIPv4 &&
                this.udpTransportBindingElement.SocketReceiveBufferSize < this.udpTransportBindingElement.MaxReceivedMessageSize)
            {
                throw FxTrace.Exception.ArgumentOutOfRange("SocketReceiveBufferSize", this.udpTransportBindingElement.SocketReceiveBufferSize,
                                                           SR.Property1LessThanOrEqualToProperty2("MaxReceivedMessageSize", this.udpTransportBindingElement.MaxReceivedMessageSize,
                                                                                                  "SocketReceiveBufferSize", this.udpTransportBindingElement.SocketReceiveBufferSize));
            }


            int maxBufferSize = (int)Math.Min(udpTransportBindingElement.MaxReceivedMessageSize, UdpConstants.MaxMessageSizeOverIPv4);

            this.bufferManager = BufferManager.CreateBufferManager(udpTransportBindingElement.MaxBufferPoolSize, maxBufferSize);

            this.messageEncoderFactory = UdpUtility.GetEncoder(context);

            UdpUtility.ValidateDuplicateDetectionAndRetransmittionSupport(this.messageEncoderFactory, this.udpTransportBindingElement.RetransmissionSettings.Enabled, this.udpTransportBindingElement.DuplicateMessageHistoryLength > 0);

            InitUri(context);

            //Note: because we are binding the sockets in InitSockets, we can start receiving data immediately.
            //If there is a delay between the Building of the listener and the call to Open, stale data could build up
            //inside the Winsock buffer.  We have decided that making sure the port is updated correctly in the listen uri
            //(e.g. in the ListenUriMode.Unique case) before leaving the build step is more important than the
            //potential for stale data.
            InitSockets(context.ListenUriMode == ListenUriMode.Unique);

            Fx.Assert(!this.listenUri.IsDefaultPort, "Listen Uri's port should never be the default port: " + this.listenUri);
        }
コード例 #2
0
        protected override void OnOpening()
        {
            base.OnOpening();

            // This check is necessary to avoid that the HostNameComparisonMode from the IIS listener address
            // is copied in an ASP-Net hosted environment when the IIS hosted service acts as client of another destination service
            // (for example using WSDualHttpBinding in a routing service)
            if (this.HostedVirtualPath != null)
            {
                // Copy the HostNameComparisonMode if necessary
                BaseUriWithWildcard baseAddress = AspNetEnvironment.Current.GetBaseUri(this.Scheme, this.Uri);
                if (baseAddress != null)
                {
                    this.hostNameComparisonMode = baseAddress.HostNameComparisonMode;
                }
            }

            this.bufferManager = BufferManager.CreateBufferManager(MaxBufferPoolSize, GetMaxBufferSize());
        }
コード例 #3
0
 protected override void OnOpening()
 {
     base.OnOpening();
     this.bufferManager = BufferManager.CreateBufferManager(MaxBufferPoolSize, GetMaxBufferSize());
 }