public ClientSessionContext( ITransportReceiveHandler transportReceiveHandler, RpcClientOptions options, RpcSocketAsyncEventArgs socketContext ) { if ( transportReceiveHandler == null ) { throw new ArgumentNullException( "transportReceiveHandler" ); } if ( options == null ) { throw new ArgumentNullException( "options" ); } if ( socketContext == null ) { throw new ArgumentNullException( "socketContext" ); } Contract.EndContractBlock(); this._transportReceiveHandler = transportReceiveHandler; this._options = options; this._socketContext = socketContext; }
protected override bool AcceptAsyncCore( RpcSocketAsyncEventArgs e ) { if ( this._isConnected ) { throw new InvalidOperationException("Socket is connected to remote endpoint."); } if ( !this._isListening ) { throw new InvalidOperationException( "Socket does not listen to remote connection request." ); } throw new NotImplementedException(); }
protected override sealed BufferFeeding FeedMore( int? requestedLength, RpcSocketAsyncEventArgs context ) { Contract.Assume( context != null ); Contract.Assume( context.UserToken is ReceivingContext ); var receivingContext = ( ReceivingContext )context.UserToken; Contract.Assert( receivingContext.SocketContext != null ); Contract.Assert( receivingContext.SocketContext.ConnectSocket != null ); Contract.Assert( receivingContext.SocketContext.ConnectSocket.RemoteEndPoint != null ); // TODO: Buffer recycling var newBuffer = receivingContext.ReceivingBuffer.Reallocate( requestedLength ?? ( receivingContext.SessionContext.Options.BufferSegmentCount ?? 1 ) * ( receivingContext.SessionContext.Options.BufferSegmentSize ?? GCChunkBuffer.DefaultSegmentSize ), receivingContext ); Contract.Assert( newBuffer.Count > 0 ); Contract.Assert( newBuffer.All( item => item.Count > 0 ) ); receivingContext.SocketContext.BufferList = newBuffer; if ( receivingContext.SocketContext.ConnectSocket.Available > 0 ) { return new BufferFeeding( context.ConnectSocket.Receive( context ), newBuffer ); } else { receivingContext.SessionContext.IsInContinuousRetrieval = true; receivingContext.SessionContext.RetrievalWaitHandle.Reset(); // TODO: timeout receivingContext.SessionContext.RetrievalWaitHandle.Wait( receivingContext.CancellationToken ); return new BufferFeeding( ( receivingContext.SocketContext.BytesTransferred > receivingContext.ReceivingBuffer.Chunks.TotalLength ) ? receivingContext.ReceivingBuffer.Chunks.TotalLength : receivingContext.SocketContext.BytesTransferred, newBuffer ); } }
/// <summary> /// Receive data from specified remote endpoint asynchronously. /// </summary> /// <param name="e">Context information.</param> /// <returns> /// If operation has been completed synchronously then FALSE. /// </returns> /// <remarks> /// This method delegates to <see cref="Socket.ReceiveFromAsync"/>. /// </remarks> protected override sealed bool ReceiveFromAsyncCore( RpcSocketAsyncEventArgs e ) { return this._socket.ReceiveFromAsync( e ); }
/// <summary> /// Receive data from connected remote endpoint synchronously. /// </summary> /// <param name="e">Context information.</param> /// <returns> /// Transferred bytes length. /// </returns> /// <exception cref="SocketException"> /// Some socket error is ocurred. /// </exception> /// <remarks> /// This method delegates to <see cref="Socket.ReceiveAsync"/>. /// </remarks> protected override sealed int ReceiveCore( RpcSocketAsyncEventArgs e ) { return this._socket.Receive( e.BufferList, e.SocketFlags ); }
/// <summary> /// Send data to specified remote endpoint asynchronously. /// </summary> /// <param name="e">Context information.</param> /// <returns> /// If operation has been completed synchronously then FALSE. /// </returns> /// <seealso cref="Socket.SendToAsync"/>. protected abstract bool SendToAsyncCore( RpcSocketAsyncEventArgs e );
/// <summary> /// Receive data from specified remote endpoint asynchronously. /// </summary> /// <param name="e">Context information.</param> /// <returns> /// If operation has been completed synchronously then FALSE. /// </returns> /// <seealso cref="Socket.ReceiveFromAsync"/>. protected abstract bool ReceiveFromAsyncCore( RpcSocketAsyncEventArgs e );
/// <summary> /// Receive data from connected remote endpoint synchronously. /// </summary> /// <param name="e">Context information.</param> /// <returns> /// Transferred bytes length. /// </returns> /// <exception cref="SocketException"> /// Some socket error is ocurred. /// </exception> /// <seealso cref="Socket.ReceiveAsync"/>. protected abstract int ReceiveCore( RpcSocketAsyncEventArgs e );
/// <summary> /// Connect remote endpoint asynchronously. /// </summary> /// <param name="e">Context information.</param> /// <returns> /// If operation has been completed synchronously then FALSE. /// </returns> /// <seealso cref="Socket.ConnectAsync(SocketAsyncEventArgs)"/>. protected abstract bool ConnectAsyncCore( RpcSocketAsyncEventArgs e );
/// <summary> /// Send data to specified remote endpoint asynchronously. /// </summary> /// <param name="e">Context information.</param> /// <returns> /// If operation has been completed synchronously then FALSE. /// </returns> /// <exception cref="ArgumentNullException"> /// <paramref name="e"/> is null. /// </exception> /// <seealso cref="Socket.SendToAsync"/>. public bool SendToAsync( RpcSocketAsyncEventArgs e ) { if ( e == null ) { throw new ArgumentNullException( "e" ); } Contract.EndContractBlock(); return this.SendToAsyncCore( e ); }
/// <summary> /// Receive data from connected remote endpoint synchronously. /// </summary> /// <param name="e">Context information.</param> /// <returns> /// Transferred bytes length. /// </returns> /// <exception cref="ArgumentNullException"> /// <paramref name="e"/> is null. /// </exception> /// <exception cref="SocketException"> /// Some socket error is ocurred. /// </exception> /// <seealso cref="Socket.ReceiveAsync"/>. public int Receive( RpcSocketAsyncEventArgs e ) { if ( e == null ) { throw new ArgumentNullException( "e" ); } Contract.EndContractBlock(); return this.ReceiveCore( e ); }
protected override int ReceiveCore( RpcSocketAsyncEventArgs e ) { throw new NotImplementedException(); }
protected override bool ConnectAsyncCore( RpcSocketAsyncEventArgs e ) { throw new NotImplementedException(); }
/// <summary> /// Send data to connected remote endpoint asynchronously. /// </summary> /// <param name="e">Context information.</param> /// <returns> /// If operation has been completed synchronously then FALSE. /// </returns> /// <remarks> /// This method delegates to <see cref="Socket.SendAsync"/>. /// </remarks> protected override sealed bool SendAsyncCore( RpcSocketAsyncEventArgs e ) { Contract.Assume( e.BufferList != null ); Contract.Assume( e.BufferList.Count > 0, e.BufferList.Count.ToString() ); Contract.Assume( ( e as SocketAsyncEventArgs ).ConnectSocket == this._socket ); Contract.Assume( e.RemoteEndPoint != null ); return this._socket.SendAsync( e ); }
/// <summary> /// Accept connection request from remote endpoint asynchronously. /// </summary> /// <param name="e">Context information.</param> /// <returns> /// If operation has been completed synchronously then FALSE. /// </returns> /// <seealso cref="Socket.AcceptAsync"/>. protected abstract bool AcceptAsyncCore( RpcSocketAsyncEventArgs e );
/// <summary> /// Send data to specified remote endpoint asynchronously. /// </summary> /// <param name="e">Context information.</param> /// <returns> /// If operation has been completed synchronously then FALSE. /// </returns> /// <remarks> /// This method delegates to <see cref="Socket.SendToAsync"/>. /// </remarks> protected override sealed bool SendToAsyncCore( RpcSocketAsyncEventArgs e ) { return this._socket.SendToAsync( e ); }
public AsyncConnectClientMock( Socket socket, RpcSocketAsyncEventArgs context ) { this.Socket = new SimpleRpcSocket( socket ); this.SocketContext = context; }