mirror of
https://github.com/sochix/TLSharp.git
synced 2025-12-05 23:52:00 +01:00
Core: make MtProtoSender.GenerateSequence() thread-safe
Even if you're not supposed to use multiple threads with TLSharp, it might be worth it to try to make this sequence increment in a thread-safe way. Race conditions are always bad even if you know you are not supposed to use something in a certain way... @Laituex was having a ErrCode=32 'msg_seqno too low' problem and this is the first thing we looked at (even if he swore that he was not using different threads to access the telegram network)
This commit is contained in:
parent
a79362ea24
commit
881bdd27a5
|
|
@ -34,7 +34,9 @@ namespace TLSharp.Core.Network
|
|||
|
||||
private int GenerateSequence(bool confirmed)
|
||||
{
|
||||
return confirmed ? session.Sequence++ * 2 + 1 : session.Sequence * 2;
|
||||
lock (session.Lock) {
|
||||
return confirmed ? session.Sequence++ * 2 + 1 : session.Sequence * 2;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Send(TeleSharp.TL.TLMethod request, CancellationToken token = default(CancellationToken))
|
||||
|
|
|
|||
|
|
@ -72,6 +72,8 @@ namespace TLSharp.Core
|
|||
|
||||
public class Session
|
||||
{
|
||||
internal object Lock = new object ();
|
||||
|
||||
private const string defaultConnectionAddress = "149.154.175.100";//"149.154.167.50";
|
||||
|
||||
private const int defaultConnectionPort = 443;
|
||||
|
|
|
|||
Loading…
Reference in a new issue