/// <summary> /// Creates <see cref="ServerResponseContext"/> which contains specified required states. /// </summary> /// <param name="transport">The transport to be bound to the context.</param> /// <returns><see cref="ServerResponseContext"/> for the unit testing argument.</returns> public static ServerResponseContext CreateResponseContext(IContextBoundableTransport transport) { var result = new ServerResponseContext(); result.SetTransport(transport); return(result); }
internal ServerResponseContext GetResponseContext(IContextBoundableTransport transport, EndPoint remoteEndPoint, long sessionId, int messageId) { Contract.Requires(transport != null); Contract.Requires(remoteEndPoint != null); Contract.Ensures(Contract.Result <ServerResponseContext>() != null); var result = this.ResponseContextPool.Borrow(); result.MessageId = messageId; result.SessionId = sessionId; result.SetTransport(transport); result.RemoteEndPoint = remoteEndPoint; return(result); }
/// <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(BoundTransport == null); Contract.Ensures(BoundTransport != null); var oldBoundTransport = Interlocked.CompareExchange(ref boundTransport, transport, null); if (oldBoundTransport != null) { 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)); } SocketContext.Completed += transport.OnSocketOperationCompleted; }
internal ServerResponseContext GetResponseContext( IContextBoundableTransport transport, EndPoint remoteEndPoint, long sessionId, int messageId ) { Contract.Requires( transport != null ); Contract.Requires( remoteEndPoint != null ); Contract.Ensures( Contract.Result<ServerResponseContext>() != null ); var result = this.ResponseContextPool.Borrow(); result.MessageId = messageId; result.SessionId = sessionId; result.SetTransport( transport ); result.RemoteEndPoint = remoteEndPoint; return result; }
/// <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; }
/// <summary> /// Creates <see cref="ServerResponseContext"/> which contains specified required states. /// </summary> /// <param name="transport">The transport to be bound to the context.</param> /// <returns><see cref="ServerResponseContext"/> for the unit testing argument.</returns> public static ServerResponseContext CreateResponseContext( IContextBoundableTransport transport ) { var result = new ServerResponseContext(); result.SetTransport( transport ); return result; }