1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- using System;
- using System.Threading.Tasks;
- using Vinno.IUS.Common.IO;
- namespace Vinno.IUS.Common.Network.Channels
- {
- internal class OutputChannelProxy : ChannelProxy<OutputChannel>, IOutputChannelProxy
- {
- private bool _timeoutHappened;
- public OutputChannelProxy(OutputChannel channel, ChannelFactory<OutputChannel> factory) : base(channel, factory)
- {
- }
- /// <summary>
- /// Send buffer to remote.
- /// </summary>
- /// <param name="buffer">The buffer to send</param>
- /// <param name="timeout">Wait forever if the value is 0</param>
- /// <returns>The return buffer from remote.</returns>
- public IBuffer Send(IBuffer buffer, int timeout = 0)
- {
- return Channel.Send(buffer, timeout);
- }
- /// <summary>
- /// Send buffer to remote.
- /// </summary>
- /// <param name="buffer">The buffer to send</param>
- /// <param name="resultCallback">When receive a part of buffers, the callback will be called.</param>
- /// <param name="timeout">Wait forever if the value is 0</param>
- public void Send(IBuffer buffer, Func<IBuffer, bool> resultCallback, int timeout = 0)
- {
- Channel.Send(buffer, resultCallback, timeout);
- }
- /// <summary>
- /// Send buffer to remote by async way.
- /// </summary>
- /// <param name="buffer">The buffer to send</param>
- /// <param name="timeout">Wait forever if the value is 0</param>
- /// <returns>The return buffer from remote.</returns>
- public async Task<IBuffer> SendAsync(IBuffer buffer, int timeout = 0)
- {
- return await Channel.SendAsync(buffer, timeout).ConfigureAwait(false);
- }
- /// <summary>
- /// Send buffer to remote by asnyc way.
- /// </summary>
- /// <param name="buffer">The buffer to send</param>
- /// <param name="resultCallback">When receive a part of buffers, the callback will be called.</param>
- /// <param name="timeout">Wait forever if the value is 0</param>
- public async Task SendAsync(IBuffer buffer, Func<IBuffer, bool> resultCallback, int timeout = 0)
- {
- await Channel.SendAsync(buffer, resultCallback, timeout).ConfigureAwait(false);
- }
- protected override void DoDispose()
- {
- if (_timeoutHappened)
- {
- Channel.Close();
- }
- else
- {
- base.DoDispose();
- }
- }
- /// <summary>
- /// Indicate the channel was timeout
- /// </summary>
- /// <param name="channelId">The channelId</param>
- public void SetTimeoutExceptionFlag(out int channelId)
- {
- channelId = Channel.Id;
- _timeoutHappened = true;
- }
- }
- }
|