/// <summary>
        ///		Sets the bound <see cref="IContextBoundableTransport"/>.
        /// </summary>
        /// <param name="transport">The <see cref="IContextBoundableTransport"/>.</param>
        internal virtual void SetTransport(IContextBoundableTransport transport)
        {
            Contract.Requires(transport != null);
            Contract.Requires(this.BoundTransport == null);
            Contract.Ensures(this.BoundTransport != null);

            var oldBoundTransport = Interlocked.CompareExchange(ref this._boundTransport, transport, null);

            if (oldBoundTransport != null)
            {
#if !SILVERLIGHT
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, "This context is already bounded to '{0}'(Socket: 0x{1:X}).", transport.GetType(), transport.BoundSocket == null ? IntPtr.Zero : transport.BoundSocket.Handle));
#else
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, "This context is already bounded to '{0}'(Socket: 0x{1:X}).", transport.GetType(), transport.BoundSocket == null ? 0 : transport.BoundSocket.GetHashCode()));
#endif
            }

            this.SocketContext.Completed += transport.OnSocketOperationCompleted;
        }
示例#2
0
		/// <summary>
		///		Sets the bound <see cref="IContextBoundableTransport"/>.
		/// </summary>
		/// <param name="transport">The <see cref="IContextBoundableTransport"/>.</param>
		internal virtual void SetTransport( IContextBoundableTransport transport )
		{
			Contract.Requires( transport != null );
			Contract.Requires( this.BoundTransport == null );
			Contract.Ensures( this.BoundTransport != null );

			var oldBoundTransport = Interlocked.CompareExchange( ref this._boundTransport, transport, null );
			if ( oldBoundTransport != null )
			{
#if !SILVERLIGHT
				throw new InvalidOperationException( String.Format( CultureInfo.CurrentCulture, "This context is already bounded to '{0}'(Socket: 0x{1:X}).", transport.GetType(), transport.BoundSocket == null ? IntPtr.Zero : transport.BoundSocket.Handle ) );
#else
				throw new InvalidOperationException( String.Format( CultureInfo.CurrentCulture, "This context is already bounded to '{0}'(Socket: 0x{1:X}).", transport.GetType(), transport.BoundSocket == null ? 0 : transport.BoundSocket.GetHashCode() ) );
#endif
			}

			this.SocketContext.Completed += transport.OnSocketOperationCompleted;
		}