Skip to content

How to wait for a transmission's completion? #9

@serious-angel

Description

@serious-angel

Dear Developer,

Thank you for this project.
Although, for example, we have a code where:

... // Somehere in AsyncTCPClient's initialization
ReceivedCallback = (c, count) =>
{
    Console.WriteLine("2");
    response = c.ByteBuffer.Dequeue(count);
    if (responseLength + count <= int.MaxValue)
        responseLength += count;
    Console.WriteLine("3, responseLength = {0}", responseLength );
    return Task.CompletedTask;
}
...
ct1 = new CancellationTokenSource(1000); // 1000ms for a request timeout
t1 = this.asyncTCPClient.Send(new ArraySegment<byte>(data, 0, data.Length), ct1.Token);
if (ct1.IsCancellationRequested) // If connection or any answer timeout
{
    Console.WriteLine("Timeout");
}
else
{
    ct1 = new CancellationTokenSource(1000); // 1000ms for a response timeour
    Console.WriteLine("1");
    t1 = this.asyncTCPClient.WaitAsync(ct1.Token); // Wait for any response available
    Console.WriteLine("4, responseLength = {0}", responseLength);
}

And the output would be:

    1
    4, responseLength = 0 // It seems that WaitAsync does not wait while ByteBuffer dequeues.
    2
    3, responseLength = 41

Is it possible to force WaitAsync to wait while the full transaction would be completed?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions