[libfibre] make pseudo-parallel func calls work

(note: the legacy protocol itself doesn't support parallel function
calls so they are serialized by libfibre.)

Merge fix for binary libfibre-wasm.wasm file - chose version for cherry-picked commit
This commit is contained in:
Samuel Sadok
2021-04-14 22:40:17 -04:00
committed by PAJohnson
parent 9e122ee776
commit 8296a4aa69
6 changed files with 205 additions and 159 deletions
+2
View File
@@ -50,6 +50,8 @@ libfibre-all:
cp /tmp/libfibre-build/libfibre-macos-x86.dylib ../tools/odrive/pyfibre/fibre/
docker run -it -v "`pwd`/fibre-cpp":/build -v /tmp/libfibre-build:/build/build -w /build fibre-compiler configs/windows-amd64.config
cp /tmp/libfibre-build/libfibre-windows-amd64.dll ../tools/odrive/pyfibre/fibre/
docker run -it -v "`pwd`/fibre-cpp":/build -v /tmp/libfibre-build:/build/build -w /build fibre-compiler configs/wasm.config
cp /tmp/libfibre-build/libfibre-wasm.* ../GUI/fibre-js/
clean:
-rm -fR .dep $(BUILD_DIR)
+24 -27
View File
@@ -9,6 +9,7 @@
#include <fibre/async_stream.hpp>
#include <memory>
#include <stdlib.h>
#include <algorithm>
DEFINE_LOG_TOPIC(LEGACY_PROTOCOL);
USE_LOG_TOPIC(LEGACY_PROTOCOL);
@@ -218,16 +219,8 @@ void LegacyProtocolPacketBased::start_endpoint_operation(uint16_t endpoint_id, c
if (tx_handle_) {
FIBRE_LOG(D) << "Endpoint operation already in progress. Enqueuing this one.";
// A TX operation is already in progress
if (pending_operation_.has_value()) {
// Previous endpoint operation was not yet sent. We don't support
// enqueuing multiple endpoint operations while the first didn't send yet.
FIBRE_LOG(E) << "previous endpoint operation still not sent";
callback.invoke_and_clear({kStreamError, tx_buf.begin(), rx_buf.begin()});
} else {
// Control is returned to start_endpoint_operation once TX completes
pending_operation_ = op;
}
// A TX operation is already in progress. Enqueue this one.
pending_operations_.push_back(op);
return;
}
@@ -266,20 +259,24 @@ void LegacyProtocolPacketBased::cancel_endpoint_operation(EndpointOperationHandl
const uint8_t* tx_end = nullptr;
uint8_t* rx_end = nullptr;
if (pending_operation_.has_value() && pending_operation_->seqno == seqno) {
callback = pending_operation_->callback;
tx_end = pending_operation_->tx_buf.begin();
rx_end = pending_operation_->rx_buf.begin();
pending_operation_ = std::nullopt;
auto it0 = std::find_if(pending_operations_.begin(), pending_operations_.end(), [&](EndpointOperation& op) {
return op.seqno == seqno;
});
if (it0 != pending_operations_.end()) {
callback = it0->callback;
tx_end = it0->tx_buf.begin();
rx_end = it0->rx_buf.begin();
pending_operations_.erase(it0);
}
auto it = expected_acks_.find(seqno);
auto it1 = expected_acks_.find(seqno);
if (it != expected_acks_.end()) {
callback = it->second.callback;
tx_end = it->second.tx_buf.begin();
rx_end = it->second.rx_buf.begin();
expected_acks_.erase(it);
if (it1 != expected_acks_.end()) {
callback = it1->second.callback;
tx_end = it1->second.tx_buf.begin();
rx_end = it1->second.rx_buf.begin();
expected_acks_.erase(it1);
}
if (transmitting_op_ == handle) {
@@ -378,11 +375,11 @@ void LegacyProtocolPacketBased::on_write_finished(WriteResult result) {
#endif
#if FIBRE_ENABLE_CLIENT
if (pending_operation_.has_value()) {
if (pending_operations_.size() > 0) {
// There is a write operation pending from the client side (i.e. an
// outgoing remote endpoint operation).
EndpointOperation op = *pending_operation_;
pending_operation_ = std::nullopt;
EndpointOperation op = pending_operations_[0];
pending_operations_.erase(pending_operations_.begin());
start_endpoint_operation(op);
if (transmitting_op_) {
return;
@@ -530,10 +527,10 @@ void LegacyProtocolPacketBased::on_rx_tx_closed(StreamStatus status) {
#if FIBRE_ENABLE_CLIENT
// Cancel pending endpoint operation
if (pending_operation_.has_value()) {
pending_operation_->callback.invoke_and_clear({status, pending_operation_->tx_buf.begin(), pending_operation_->rx_buf.begin()});
pending_operation_ = std::nullopt;
for (auto& op: pending_operations_) {
op.callback.invoke_and_clear({status, op.tx_buf.begin(), op.rx_buf.begin()});
}
pending_operations_.clear();
// Cancel all ongoing endpoint operations
for (auto& item: expected_acks_) {
+2 -1
View File
@@ -7,6 +7,7 @@
#include "legacy_object_client.hpp"
#include <unordered_map>
#include <optional>
#include <queue>
#endif
namespace fibre {
@@ -135,7 +136,7 @@ private:
void start_endpoint_operation(EndpointOperation op);
uint16_t outbound_seq_no_ = 0;
std::optional<EndpointOperation> pending_operation_ = std::nullopt; // operation that is waiting for TX
std::vector<EndpointOperation> pending_operations_; // operations that are waiting for TX
EndpointOperationHandle transmitting_op_ = 0; // operation that is in TX
std::unordered_map<uint16_t, EndpointOperation> expected_acks_; // operations that are waiting for RX
#endif
+1 -1
View File
@@ -56,7 +56,7 @@ fibre::ChannelDiscoveryContext* from_c(LibFibreChannelDiscoveryCtx* ptr) {
}
static const struct LibFibreVersion libfibre_version = { 0, 1, 3 };
static const struct LibFibreVersion libfibre_version = { 0, 1, 4 };
class FIBRE_PRIVATE ExternalEventLoop final : public fibre::EventLoop {
public:
File diff suppressed because it is too large Load Diff
Binary file not shown.