THRIFT-4673 IAsyncResult not supported by layered transports (buffered/framed)

Client: C#
Patch: Jens Geyer

This closes #1634
This commit is contained in:
Jens Geyer 2018-11-23 01:44:02 +01:00
parent 7abb7d5fbc
commit fc52c3ccee
2 changed files with 44 additions and 4 deletions

View File

@ -81,7 +81,7 @@ namespace Thrift.Transport
inputBuffer.Capacity = bufSize; inputBuffer.Capacity = bufSize;
while (true) while (true)
{ {
int got = inputBuffer.Read(buf, off, len); int got = inputBuffer.Read(buf, off, len);
if (got > 0) if (got > 0)
return got; return got;
@ -129,9 +129,8 @@ namespace Thrift.Transport
} }
} }
public override void Flush() private void InternalFlush()
{ {
CheckNotDisposed();
if (!IsOpen) if (!IsOpen)
throw new TTransportException(TTransportException.ExceptionType.NotOpen); throw new TTransportException(TTransportException.ExceptionType.NotOpen);
if (outputBuffer.Length > 0) if (outputBuffer.Length > 0)
@ -139,9 +138,31 @@ namespace Thrift.Transport
transport.Write(outputBuffer.GetBuffer(), 0, (int)outputBuffer.Length); transport.Write(outputBuffer.GetBuffer(), 0, (int)outputBuffer.Length);
outputBuffer.SetLength(0); outputBuffer.SetLength(0);
} }
}
public override void Flush()
{
CheckNotDisposed();
InternalFlush();
transport.Flush(); transport.Flush();
} }
public override IAsyncResult BeginFlush(AsyncCallback callback, object state)
{
CheckNotDisposed();
InternalFlush();
return transport.BeginFlush( callback, state);
}
public override void EndFlush(IAsyncResult asyncResult)
{
transport.EndFlush( asyncResult);
}
protected void CheckNotDisposed() protected void CheckNotDisposed()
{ {
if (_IsDisposed) if (_IsDisposed)

View File

@ -108,7 +108,7 @@ namespace Thrift.Transport
writeBuffer.Write(buf, off, len); writeBuffer.Write(buf, off, len);
} }
public override void Flush() private void InternalFlush()
{ {
CheckNotDisposed(); CheckNotDisposed();
if (!IsOpen) if (!IsOpen)
@ -126,10 +126,29 @@ namespace Thrift.Transport
transport.Write(buf, 0, len); transport.Write(buf, 0, len);
InitWriteBuffer(); InitWriteBuffer();
}
public override void Flush()
{
CheckNotDisposed();
InternalFlush();
transport.Flush(); transport.Flush();
} }
public override IAsyncResult BeginFlush(AsyncCallback callback, object state)
{
CheckNotDisposed();
InternalFlush();
return transport.BeginFlush( callback, state);
}
public override void EndFlush(IAsyncResult asyncResult)
{
transport.EndFlush( asyncResult);
}
private void InitWriteBuffer() private void InitWriteBuffer()
{ {
// Reserve space for message header to be put right before sending it out // Reserve space for message header to be put right before sending it out