@@ -108,9 +108,11 @@ NetCommandResults NetMTUCommand::onReceive(std::unique_ptr<ProtocolPacket>& pack
108
108
case States::WAITING_RESPONSE:
109
109
if (packet->retrieveHeaderId ().value () == NET_INTERNAL_ID_MTU_ASK_RESPONSE)
110
110
{
111
+ std::unique_ptr packetOwned{std::move (packet)};
112
+
111
113
// Extract the target MTU
112
114
uint16_t targetMTU;
113
- if (rules::RValid<uint16_t >({packet ->packet (), &targetMTU}).end () || !packet ->endReached ())
115
+ if (rules::RValid<uint16_t >({packetOwned ->packet (), &targetMTU}).end () || !packetOwned ->endReached ())
114
116
{
115
117
// Invalid packet
116
118
std::cout << " MTU: Invalid packet" << std::endl;
@@ -168,6 +170,8 @@ NetCommandResults NetMTUCommand::onReceive(std::unique_ptr<ProtocolPacket>& pack
168
170
case States::WAITING:
169
171
if (packet->retrieveHeaderId ().value () == NET_INTERNAL_ID_MTU_TEST_RESPONSE)
170
172
{
173
+ packet.reset ();
174
+
171
175
this ->g_currentMTU = this ->g_targetMTU ;
172
176
173
177
if (this ->g_tryCount == 0 || this ->g_currentMTU == this ->g_maximumMTU )
@@ -187,7 +191,6 @@ NetCommandResults NetMTUCommand::onReceive(std::unique_ptr<ProtocolPacket>& pack
187
191
188
192
this ->_g_timeout = std::chrono::milliseconds::zero ();
189
193
this ->g_state = States::DISCOVER;
190
- break ;
191
194
}
192
195
break ;
193
196
default :
@@ -396,10 +399,12 @@ NetCommandResults NetConnectCommand::onReceive(std::unique_ptr<ProtocolPacket>&
396
399
return NetCommandResults::WORKING;
397
400
}
398
401
402
+ std::unique_ptr packetOwned{std::move (packet)};
403
+
399
404
std::cout << " receiving handshake response" << std::endl;
400
405
401
406
std::string handshake;
402
- if (rules::RValid<std::string>({packet ->packet (), &handshake}).end () || !packet ->endReached ())
407
+ if (rules::RValid<std::string>({packetOwned ->packet (), &handshake}).end () || !packetOwned ->endReached ())
403
408
{
404
409
std::cout << " handshake failed" << std::endl;
405
410
client.getStatus ().setNetworkStatus (ClientStatus::NetworkStatus::DISCONNECTED);
@@ -430,10 +435,13 @@ NetCommandResults NetConnectCommand::onReceive(std::unique_ptr<ProtocolPacket>&
430
435
return NetCommandResults::WORKING;
431
436
}
432
437
438
+ std::unique_ptr packetOwned{std::move (packet)};
439
+
433
440
auto & info = client.getCryptInfo ();
434
441
435
- auto const readPos = packet->getReadPos ();
436
- BIO_write (static_cast <BIO*>(info._rbio ), packet->getData () + readPos, packet->getDataSize () - readPos);
442
+ auto const readPos = packetOwned->getReadPos ();
443
+ BIO_write (static_cast <BIO*>(info._rbio ), packetOwned->getData () + readPos,
444
+ packetOwned->getDataSize () - readPos);
437
445
438
446
std::cout << " Crypt: received some data" << std::endl;
439
447
0 commit comments