25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

33 lines
698 B

  1. namespace MQTTnet.Client
  2. {
  3. public class MqttPacketIdentifierProvider
  4. {
  5. private readonly object _syncRoot = new object();
  6. private ushort _value;
  7. public void Reset()
  8. {
  9. lock (_syncRoot)
  10. {
  11. _value = 0;
  12. }
  13. }
  14. public ushort GetNewPacketIdentifier()
  15. {
  16. lock (_syncRoot)
  17. {
  18. _value++;
  19. if (_value == 0)
  20. {
  21. // As per official MQTT documentation the package identifier should never be 0.
  22. _value = 1;
  23. }
  24. return _value;
  25. }
  26. }
  27. }
  28. }