From e62f20e44513646ab1b3c87d4d5dfaf2446b95d2 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Sun, 4 Jul 2021 12:09:16 -0700 Subject: [PATCH] fixup onCreate with multiple Sources --- src/pvxs/source.h | 7 ++++++- src/serverchan.cpp | 24 +++++++++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/pvxs/source.h b/src/pvxs/source.h index 8f04ce1..70805c5 100644 --- a/src/pvxs/source.h +++ b/src/pvxs/source.h @@ -219,7 +219,12 @@ struct PVXS_API Source { * * This Channel name may not be one which was seen or claimed by onSearch(). * - * Callee will either do nothing, or std::move() the ChannelControl and call ChannelControl::setHandler() + * Callee may: + * + * - Do nothing, allowing some other Source with higher/later order a chance to create. + * - Call ChannelControl::close() to explicitly reject the channel. + * - std::move() the op and/or call ChannelControl::setHandler() to accept the new channel. + * - std::move() the op and allow ChannelControl to be destroyed to implicitly reject the channel. */ virtual void onCreate(std::unique_ptr&& op) =0; diff --git a/src/serverchan.cpp b/src/serverchan.cpp index 02d3c93..2acfd9c 100644 --- a/src/serverchan.cpp +++ b/src/serverchan.cpp @@ -302,12 +302,26 @@ void ServerConn::handle_CREATE_CHANNEL() for(auto& pair : iface->server->sources) { try { pair.second->onCreate(std::move(op)); - if(!op || chan->onOp || chan->onClose || chan->state!=ServerChan::Creating) { - claimed = chan->state==ServerChan::Creating; - log_debug_printf(serversearch, "Client %s %s channel to %s through %s\n", peerName.c_str(), - claimed?"accepted":"rejected", name.c_str(), pair.first.second.c_str()); - break; + const char* msg = nullptr; + + if(chan->state!=ServerChan::Creating) { + msg = "rejected"; + + } else if(chan->onOp || chan->onRPC || chan->onSubscribe || chan->onClose) { + msg = "accepted"; + claimed = true; + + } else if(!op) { + msg = "discarded"; } + + log_debug_printf(serversearch, "Client %s %s channel to %s through %s\n", + peerName.c_str(), + msg ? msg : "ignored", + name.c_str(), pair.first.second.c_str()); + + if(msg) + break; }catch(std::exception& e){ log_exc_printf(serversearch, "Client %s Unhandled error in onCreate %s,%d %s : %s\n", peerName.c_str(), pair.first.second.c_str(), pair.first.first,