diff --git a/gui/webdisplay/inc/ROOT/TWebWindow.hxx b/gui/webdisplay/inc/ROOT/TWebWindow.hxx index 6e87753f5d577ede518db8b57d5283af7ee09e69..c01336e2826781374f12c1d9f7bc20d862863254 100644 --- a/gui/webdisplay/inc/ROOT/TWebWindow.hxx +++ b/gui/webdisplay/inc/ROOT/TWebWindow.hxx @@ -17,7 +17,7 @@ #define ROOT7_TWebWindow #include <memory> -#include <list> +#include <vector> #include <string> #include <functional> @@ -49,15 +49,13 @@ class TWebWindow { private: struct WebConn { - unsigned fWSId{0}; ///<! websocket id - unsigned fConnId{0}; ///<! connection id (unique inside the window) - int fReady{0}; ///<! 0 - not ready, 1..9 - interim, 10 - done - int fRecvCount{0}; ///<! number of received packets, should return back with next sending - int fSendCredits{0}; ///<! how many send operation can be performed without confirmation from other side - int fClientCredits{ - 0}; ///<! last received information about credits on client side, helps to resubmit credits back to client - std::list<std::string> - fQueue; ///<! small output queue for data which should be send via the connection (including channel) + unsigned fWSId{0}; ///<! websocket id + unsigned fConnId{0}; ///<! connection id (unique inside the window) + int fReady{0}; ///<! 0 - not ready, 1..9 - interim, 10 - done + int fRecvCount{0}; ///<! number of received packets, should return back with next sending + int fSendCredits{0}; ///<! how many send operation can be performed without confirmation from other side + int fClientCredits{0}; ///<! number of credits received from client + std::vector<std::string> fQueue; ///<! output queue (already includes channel) WebWindowDataCallback_t fCallBack; ///<! additional data callback for extra channels WebConn() = default; }; @@ -70,7 +68,7 @@ private: std::unique_ptr<TWebWindowWSHandler> fWSHandler; ///<! specialize websocket handler for all incoming connections bool fShown{false}; ///<! true when window was shown at least once unsigned fConnCnt{0}; ///<! counter of new connections to assign ids - std::list<WebConn> fConn; ///<! list of all accepted connections + std::vector<WebConn> fConn; ///<! list of all accepted connections unsigned fConnLimit{1}; ///<! number of allowed active connections static const unsigned fMaxQueueLength{10}; ///<! maximal number of queue entries WebWindowDataCallback_t fDataCallback; ///<! main callback when data over channel 1 is arrived @@ -135,9 +133,9 @@ public: void SetConnLimit(unsigned lmt = 0) { fConnLimit = lmt; } /// Returns current number of active clients connections - unsigned NumConnections() const { return fConn.size(); } + int NumConnections() const { return fConn.size(); } - unsigned GetConnectionId(unsigned num = 0) const; + unsigned GetConnectionId(int num = 0) const; void CloseConnections(); diff --git a/gui/webdisplay/src/TWebWindow.cxx b/gui/webdisplay/src/TWebWindow.cxx index 765d784490532e8b6579d9f5985df4a23460f317..a3cd6242cb0a5d36d7c0eea22fde7550cc0a01c1 100644 --- a/gui/webdisplay/src/TWebWindow.cxx +++ b/gui/webdisplay/src/TWebWindow.cxx @@ -198,7 +198,7 @@ bool ROOT::Experimental::TWebWindow::ProcessWS(THttpCallArg &arg) assert(arg.IsMethod("WS_DATA") && "WS_DATA request expected!"); - assert(conn != 0 && "Get websocket data without valid connection - ignore!!!"); + assert(conn && "Get websocket data without valid connection - ignore!!!"); if (arg.GetPostDataLength() <= 0) return true; @@ -207,18 +207,18 @@ bool ROOT::Experimental::TWebWindow::ProcessWS(THttpCallArg &arg) // this is task for the implemented windows const char *buf = (const char *)arg.GetPostData(); - char *str_end = 0; + char *str_end = nullptr; printf("Get portion of data %d %.30s\n", (int)arg.GetPostDataLength(), buf); unsigned long ackn_oper = std::strtoul(buf, &str_end, 10); - assert(str_end != 0 && *str_end == ':' && "missing number of acknowledged operations"); + assert(str_end && *str_end == ':' && "missing number of acknowledged operations"); unsigned long can_send = std::strtoul(str_end + 1, &str_end, 10); - assert(str_end != 0 && *str_end == ':' && "missing can_send counter"); + assert(str_end && *str_end == ':' && "missing can_send counter"); unsigned long nchannel = std::strtoul(str_end + 1, &str_end, 10); - assert(str_end != 0 && *str_end == ':' && "missing channel number"); + assert(str_end && *str_end == ':' && "missing channel number"); unsigned processed_len = (str_end + 1 - buf); @@ -312,7 +312,7 @@ void ROOT::Experimental::TWebWindow::CheckDataToSend(bool only_once) if (iter->fQueue.size() > 0) { SendDataViaConnection(*iter, -1, iter->fQueue.front()); - iter->fQueue.pop_front(); + iter->fQueue.erase(iter->fQueue.begin()); isany = true; } else if ((iter->fClientCredits < 3) && (iter->fRecvCount > 1)) { // give more credits to the client @@ -347,12 +347,10 @@ std::string ROOT::Experimental::TWebWindow::RelativeAddr(std::shared_ptr<TWebWin /// returns connection for specified connection number /// Total number of connections can be retrieved with NumConnections() method -unsigned ROOT::Experimental::TWebWindow::GetConnectionId(unsigned num) const +unsigned ROOT::Experimental::TWebWindow::GetConnectionId(int num) const { - for (auto iter = fConn.begin(); iter != fConn.end(); ++iter) { - if (num-- == 0) return iter->fConnId; - } - return 0; + auto iter = fConn.begin() + num; + return iter->fConnId; } ///////////////////////////////////////////////////////////////////////////////////