Here are the examples of the csharp api System.Threading.Tasks.TaskCompletionSource.SetResult(Packet) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
2 Examples
19
Source : KChannel.cs
with MIT License
from winddyhe
with MIT License
from winddyhe
public void HandleRecv(byte[] rDate, uint nTimeNow)
{
this.mKcp.Input(rDate);
// 加入update队列
this.GetService().AddToUpdate(this.Id);
while (true)
{
int n = mKcp.PeekSize();
if (n == 0)
{
this.OnError((int)SocketError.NetworkReset);
return;
}
int count = this.mKcp.Recv(this.mCacheBytes);
if (count <= 0)
{
return;
}
mLastRecvTime = nTimeNow;
// 收到的数据放入缓冲区
byte[] rSizeBuffer = BitConverter.GetBytes((ushort)count);
this.mRecvBuffer.Write(rSizeBuffer, 0, rSizeBuffer.Length);
this.mRecvBuffer.Write(mCacheBytes, 0, count);
if (this.mRecvTcs == null)
{
continue;
}
try
{
bool bIsOK = this.mParser.Parse();
if (!bIsOK)
{
continue;
}
Packet rPacket = this.mParser.GetPacket();
var rRecvTcs = this.mRecvTcs;
this.mRecvTcs = null;
rRecvTcs.SetResult(rPacket);
}
catch (Exception e)
{
this.OnError(NetworkErrorCode.ERR_PacketParserError);
var rRecvTcs = this.mRecvTcs;
this.mRecvTcs = null;
rRecvTcs.SetException(e);
}
}
}
19
Source : TChannel.cs
with MIT License
from winddyhe
with MIT License
from winddyhe
private async void StartRecv()
{
try
{
while (true)
{
NetworkStream rStream = this.mTcpClient.GetStream();
if (!rStream.CanRead)
{
return;
}
int n = await this.mRecvBuffer.ReadFromAsync(rStream);
if (n == 0)
{
this.OnError((int)SocketError.NetworkReset);
return;
}
// 如果没有recv调用
if (this.mRecvTcs == null)
{
continue;
}
try
{
bool bIsOK = this.mParser.Parse();
if (!bIsOK)
{
continue;
}
Packet rPacket = this.mParser.GetPacket();
var tcs = this.mRecvTcs;
this.mRecvTcs = null;
tcs.SetResult(rPacket);
}
catch (Exception e)
{
this.OnError(NetworkErrorCode.ERR_PacketParserError);
var tcs = this.mRecvTcs;
this.mRecvTcs = null;
tcs.SetException(e);
}
}
}
catch (IOException)
{
this.OnError((int)SocketError.SocketError);
}
catch (ObjectDisposedException)
{
this.OnError((int)SocketError.SocketError);
}
catch (Exception e)
{
Debug.LogError(e);
this.OnError((int)SocketError.SocketError);
}
}