aboutsummaryrefslogtreecommitdiffstats
path: root/libtransport/src/protocols/protocol.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libtransport/src/protocols/protocol.cc')
-rw-r--r--libtransport/src/protocols/protocol.cc34
1 files changed, 20 insertions, 14 deletions
diff --git a/libtransport/src/protocols/protocol.cc b/libtransport/src/protocols/protocol.cc
index 8463f84f9..451fef80d 100644
--- a/libtransport/src/protocols/protocol.cc
+++ b/libtransport/src/protocols/protocol.cc
@@ -14,7 +14,6 @@
*/
#include <hicn/transport/interfaces/socket_consumer.h>
-
#include <implementation/socket_consumer.h>
#include <protocols/protocol.h>
@@ -49,12 +48,6 @@ int TransportProtocol::start() {
// If the protocol is already running, return otherwise set as running
if (is_running_) return -1;
- // Reset the protocol state machine
- reset();
-
- // Set it is the first time we schedule an interest
- is_first_ = true;
-
// Get all callbacks references before starting
socket_->getSocketOption(ConsumerCallbacksOptions::INTEREST_RETRANSMISSION,
&on_interest_retransmission_);
@@ -74,7 +67,13 @@ int TransportProtocol::start() {
&verification_failed_callback_);
socket_->getSocketOption(ConsumerCallbacksOptions::READ_CALLBACK,
&on_payload_);
+ socket_->getSocketOption(GeneralTransportOptions::ASYNC_MODE, is_async_);
+ // Set it is the first time we schedule an interest
+ is_first_ = true;
+
+ // Reset the protocol state machine
+ reset();
// Schedule next interests
scheduleNextInterests();
@@ -83,18 +82,25 @@ int TransportProtocol::start() {
// Set the protocol as running
is_running_ = true;
- // Start Event loop
- portal_->runEventsLoop();
+ if (!is_async_) {
+ // Start Event loop
+ portal_->runEventsLoop();
- // Not running anymore
- is_running_ = false;
+ // Not running anymore
+ is_running_ = false;
+ }
return 0;
}
void TransportProtocol::stop() {
is_running_ = false;
- portal_->stopEventsLoop();
+
+ if (!is_async_) {
+ portal_->stopEventsLoop();
+ } else {
+ portal_->clear();
+ }
}
void TransportProtocol::resume() {
@@ -110,6 +116,8 @@ void TransportProtocol::resume() {
}
void TransportProtocol::onContentReassembled(std::error_code ec) {
+ stop();
+
if (!on_payload_) {
throw errors::RuntimeException(
"The read callback must be installed in the transport before "
@@ -122,8 +130,6 @@ void TransportProtocol::onContentReassembled(std::error_code ec) {
} else {
on_payload_->readError(ec);
}
-
- stop();
}
} // end namespace protocol