Skip to content
This repository was archived by the owner on Apr 18, 2024. It is now read-only.

Commit 9b98770

Browse files
committed
Fix problem related to control packet state transitions
Ref PR #62
1 parent 10de846 commit 9b98770

2 files changed

Lines changed: 18 additions & 24 deletions

File tree

include/common/internal/transport/h5_transport.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,27 +130,21 @@ class InitializedExitCriterias : public ExitCriterias
130130
public:
131131
bool syncConfigSent;
132132
bool syncConfigRspReceived;
133-
bool syncConfigReceived;
134-
bool syncConfigRspSent;
135133

136134
InitializedExitCriterias()
137135
: ExitCriterias(),
138136
syncConfigSent(false),
139-
syncConfigRspReceived(false),
140-
syncConfigReceived(false),
141-
syncConfigRspSent(false) {}
137+
syncConfigRspReceived(false) {}
142138

143139
bool isFullfilled() const override
144140
{
145-
return ioResourceError || close || (syncConfigSent && syncConfigRspReceived && syncConfigReceived && syncConfigRspSent);
141+
return ioResourceError || close || (syncConfigSent && syncConfigRspReceived);
146142
}
147143

148144
void reset() override
149145
{
150146
ExitCriterias::reset();
151147
syncConfigSent = false;
152-
syncConfigRspSent = false;
153-
syncConfigReceived = false;
154148
syncConfigRspReceived = false;
155149
};
156150

src/common/transport/h5_transport.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969

7070
// Constants use for state machine states UNINITIALIZED and INITIALIZED
7171
const auto NON_ACTIVE_STATE_TIMEOUT = std::chrono::milliseconds(250); // Duration to wait until resending a packet
72-
const uint8_t PACKET_RETRANSMISSIONS = 4; // Number of times to send reliable packets before giving in
72+
const uint8_t PACKET_RETRANSMISSIONS = 6; // Number of times to send reliable packets before giving in
7373

7474
// Other constants
7575
const auto OPEN_WAIT_TIMEOUT = std::chrono::milliseconds(2000); // Duration to wait for state ACTIVE after open is called
@@ -316,14 +316,14 @@ void H5Transport::processPacket(std::vector<uint8_t> &packet)
316316

317317
if (isSyncConfigPacket)
318318
{
319-
exit->syncConfigReceived = true;
320319
sendControlPacket(CONTROL_PKT_SYNC_CONFIG_RESPONSE);
321-
exit->syncConfigRspSent = true;
322320
syncWaitCondition.notify_all();
323321
}
324322

325-
if (isSyncPacket) {
323+
if (isSyncPacket)
324+
{
326325
sendControlPacket(CONTROL_PKT_SYNC_RESPONSE);
326+
syncWaitCondition.notify_all();
327327
}
328328
}
329329
else if (currentState == STATE_ACTIVE)
@@ -335,6 +335,11 @@ void H5Transport::processPacket(std::vector<uint8_t> &packet)
335335
exit->syncReceived = true;
336336
syncWaitCondition.notify_all();
337337
}
338+
339+
if (isSyncConfigPacket)
340+
{
341+
sendControlPacket(CONTROL_PKT_SYNC_CONFIG_RESPONSE);
342+
}
338343
}
339344
}
340345
else if (packet_type == VENDOR_SPECIFIC_PACKET)
@@ -522,11 +527,12 @@ void H5Transport::setupStateMachine()
522527
uint8_t syncRetransmission = PACKET_RETRANSMISSIONS;
523528
std::unique_lock<std::mutex> syncGuard(syncMutex);
524529

525-
while (!exit->isFullfilled() && syncRetransmission--)
530+
while (!exit->isFullfilled() && syncRetransmission > 0)
526531
{
527532
sendControlPacket(CONTROL_PKT_SYNC);
528533
exit->syncSent = true;
529534
syncWaitCondition.wait_for(syncGuard, NON_ACTIVE_STATE_TIMEOUT);
535+
syncRetransmission--;
530536
}
531537

532538
if (exit->isFullfilled())
@@ -548,22 +554,16 @@ void H5Transport::setupStateMachine()
548554
std::unique_lock<std::mutex> syncGuard(syncMutex);
549555

550556
// Send a package immediately
551-
sendControlPacket(CONTROL_PKT_SYNC_CONFIG);
552-
exit->syncConfigSent = true;
553557

554558
while (!exit->isFullfilled() && syncRetransmission > 0)
555559
{
556-
auto status = syncWaitCondition.wait_for(syncGuard, NON_ACTIVE_STATE_TIMEOUT);
557-
558-
if (status == std::cv_status::timeout)
559-
{
560-
sendControlPacket(CONTROL_PKT_SYNC_CONFIG);
561-
syncRetransmission--;
562-
}
560+
sendControlPacket(CONTROL_PKT_SYNC_CONFIG);
561+
exit->syncConfigSent = true;
562+
syncWaitCondition.wait_for(syncGuard, NON_ACTIVE_STATE_TIMEOUT);
563+
syncRetransmission--;
563564
}
564565

565-
if (exit->syncConfigSent && exit->syncConfigRspReceived
566-
&& exit->syncConfigReceived && exit->syncConfigRspSent)
566+
if (exit->syncConfigSent && exit->syncConfigRspReceived)
567567
{
568568
return STATE_ACTIVE;
569569
}

0 commit comments

Comments
 (0)