-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathacksender.cpp
More file actions
48 lines (36 loc) · 1004 Bytes
/
acksender.cpp
File metadata and controls
48 lines (36 loc) · 1004 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
This file is part of FlashMQ (https://www.flashmq.org)
Copyright (C) 2021-2023 Wiebe Cazemier
FlashMQ is free software: you can redistribute it and/or modify
it under the terms of The Open Software License 3.0 (OSL-3.0).
See LICENSE for license details.
*/
#include "acksender.h"
#include "mqttpacket.h"
#include "client.h"
AckSender::AckSender(uint8_t qos, uint16_t packetId, ProtocolVersion protocolVersion) :
qos(qos),
packetId(packetId),
protocolVersion(protocolVersion)
{
}
AckSender::~AckSender()
{
assert(sent);
}
void AckSender::sendNow(Client *client)
{
if (sent)
return;
this->sent = true;
if (qos == 0)
return;
const PacketType responseType = qos == 1 ? PacketType::PUBACK : PacketType::PUBREC;
PubResponse pubAck(this->protocolVersion, responseType, ackCode, packetId);
MqttPacket response(pubAck);
client->writeMqttPacket(response);
}
void AckSender::setAckCode(ReasonCodes ackCode)
{
this->ackCode = ackCode;
}