sympthom / Valley.Net.Bindings

3 stars 3 forks source link

TCP OnCompleted ends with socket listening #2

Open flodmotorgrodan opened 2 years ago

flodmotorgrodan commented 2 years ago

After each OnCompleted event, the state.ReceiveAsync(e) is called to signal continued socket receive.

After a packet is successfully deserialized, continuing using the connection for another SendAsync() without closing, will result in OnComplete reissuing listening on the socket already listening.

It that case it looks like there are then multiple listening tasks competing to entertain the same OnComplete event, each with fragments of data.

Maybe better skip listening after a complete package and instead have the next Send command resume it?

On each send there is a new OrderedAsyncState(). Maybe the state instance can be reused for the next SendAsync if connection is still open? It has a Clear() function that could be used to reset it for the next challenge.