mirror of
				https://github.com/Telecominfraproject/wlan-cloud-owprov.git
				synced 2025-10-29 09:42:38 +00:00 
			
		
		
		
	Signed-off-by: stephb9959 <stephane.bourque@gmail.com>
This commit is contained in:
		| @@ -18,10 +18,11 @@ | ||||
| namespace OpenWifi { | ||||
|  | ||||
| 	void UI_WebSocketClientServer::NewClient(Poco::Net::WebSocket & WS, const std::string &Id, const std::string &UserName ) { | ||||
| 		std::lock_guard G(Mutex_); | ||||
|         auto Client = std::make_unique<UI_WebSocketClientInfo>(WS,Id, UserName); | ||||
|  | ||||
|         Clients_[Id] = std::move(Client); | ||||
|         std::lock_guard G(Mutex_); | ||||
|         auto Client = std::make_unique<UI_WebSocketClientInfo>(WS,Id, UserName); | ||||
|         auto ClientSocket = Client->WS_->impl()->sockfd(); | ||||
|         Clients_[ClientSocket] = std::move(Client); | ||||
|  | ||||
|         Client->WS_->setNoDelay(true); | ||||
|         Client->WS_->setKeepAlive(true); | ||||
| @@ -45,10 +46,11 @@ namespace OpenWifi { | ||||
| 		Processor_ = F; | ||||
| 	} | ||||
|  | ||||
| 	void UI_WebSocketClientServer::UnRegister(const std::string &Id) { | ||||
| /*	void UI_WebSocketClientServer::UnRegister(const std::string &Id) { | ||||
| 		std::lock_guard G(Mutex_); | ||||
| 		Clients_.erase(Id); | ||||
| 		// | ||||
| 	} | ||||
| */ | ||||
|  | ||||
| 	[[nodiscard]] inline bool SendToUser(const std::string &userName, const std::string &Payload); | ||||
| 	UI_WebSocketClientServer::UI_WebSocketClientServer() noexcept: | ||||
| @@ -104,6 +106,7 @@ namespace OpenWifi { | ||||
| 		} | ||||
| 	}; | ||||
|  | ||||
|     /* | ||||
| 	bool UI_WebSocketClientServer::Send(const std::string &Id, const std::string &Payload) { | ||||
| 		std::lock_guard G(Mutex_); | ||||
|  | ||||
| @@ -112,6 +115,7 @@ namespace OpenWifi { | ||||
| 			return It->second->WS_->sendFrame(Payload.c_str(),Payload.size()); | ||||
| 		return false; | ||||
| 	} | ||||
|      */ | ||||
|  | ||||
| 	bool UI_WebSocketClientServer::SendToUser(const std::string &UserName, const std::string &Payload) { | ||||
| 		std::lock_guard G(Mutex_); | ||||
| @@ -142,18 +146,13 @@ namespace OpenWifi { | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
|     UI_WebSocketClientServer::ClientList::iterator UI_WebSocketClientServer::FindWSClient( [[maybe_unused]]  std::lock_guard<std::recursive_mutex> &G, const Poco::Net::Socket &Socket) { | ||||
|         for(auto i = Clients_.begin();i!=Clients_.end();++i) { | ||||
|             if(*i->second->WS_ == Socket) { | ||||
|                 return i; | ||||
|             } | ||||
|         } | ||||
|         return end(Clients_); | ||||
|     UI_WebSocketClientServer::ClientList::iterator UI_WebSocketClientServer::FindWSClient( [[maybe_unused]]  std::lock_guard<std::recursive_mutex> &G, int ClientSocket) { | ||||
|         return Clients_.find(ClientSocket); | ||||
|     } | ||||
|  | ||||
|     void UI_WebSocketClientServer::OnSocketError([[maybe_unused]] const Poco::AutoPtr<Poco::Net::ErrorNotification> &pNf) { | ||||
|         std::lock_guard     G(LocalMutex_); | ||||
|         auto Client = FindWSClient(G,pNf->socket()); | ||||
|         auto Client = FindWSClient(G,pNf->socket().impl()->sockfd()); | ||||
|         if(Client==end(Clients_)) | ||||
|             return; | ||||
|         EndConnection(G,Client); | ||||
| @@ -168,9 +167,11 @@ namespace OpenWifi { | ||||
|         UI_WebSocketClientServer::ClientList::iterator Client; | ||||
|         std::lock_guard     G(LocalMutex_); | ||||
|  | ||||
|         pNf->socket().impl()->sockfd(); | ||||
|  | ||||
| 		try { | ||||
|  | ||||
|             Client = FindWSClient(G,pNf->socket()); | ||||
|             Client = FindWSClient(G,pNf->socket().impl()->sockfd()); | ||||
|             if( Client == end(Clients_)) | ||||
|                 return; | ||||
|  | ||||
| @@ -250,7 +251,7 @@ namespace OpenWifi { | ||||
|         ClientList::iterator Client; | ||||
|         std::lock_guard     G(LocalMutex_); | ||||
|         try { | ||||
|             Client = FindWSClient(G, pNf->socket()); | ||||
|             Client = FindWSClient(G, pNf->socket().impl()->sockfd()); | ||||
|             if (Client == end(Clients_)) | ||||
|                 return; | ||||
|             EndConnection(G, Client); | ||||
|   | ||||
| @@ -56,10 +56,10 @@ namespace OpenWifi { | ||||
| 		Poco::Net::SocketReactor & Reactor() { return Reactor_; } | ||||
| 		void NewClient(Poco::Net::WebSocket &WS, const std::string &Id, const std::string &UserName); | ||||
| 		void SetProcessor(UI_WebSocketClientProcessor *F); | ||||
| 		void UnRegister(const std::string &Id); | ||||
| 		// void UnRegister(const std::string &Id); | ||||
| 		[[nodiscard]] inline bool GeoCodeEnabled() const { return GeoCodeEnabled_; } | ||||
| 		[[nodiscard]] inline std::string GoogleApiKey() const { return GoogleApiKey_; } | ||||
| 		[[nodiscard]] bool Send(const std::string &Id, const std::string &Payload); | ||||
| 		// [[nodiscard]] bool Send(const std::string &Id, const std::string &Payload); | ||||
|  | ||||
| 		template <typename T> bool | ||||
| 		SendUserNotification(const std::string &userName, const WebSocketNotification<T> &Notification) { | ||||
| @@ -87,7 +87,7 @@ namespace OpenWifi { | ||||
| 		[[nodiscard]] bool SendToUser(const std::string &userName, const std::string &Payload); | ||||
| 		void SendToAll(const std::string &Payload); | ||||
|  | ||||
|         using ClientList = std::map<std::string,std::unique_ptr<UI_WebSocketClientInfo>>; | ||||
|         using ClientList = std::map<int,std::unique_ptr<UI_WebSocketClientInfo>>; | ||||
|     private: | ||||
| 		mutable std::atomic_bool Running_ = false; | ||||
| 		Poco::Thread 								Thr_; | ||||
| @@ -105,7 +105,7 @@ namespace OpenWifi { | ||||
|         void OnSocketShutdown(const Poco::AutoPtr<Poco::Net::ShutdownNotification> &pNf); | ||||
|         void OnSocketError(const Poco::AutoPtr<Poco::Net::ErrorNotification> &pNf); | ||||
|  | ||||
|         ClientList::iterator FindWSClient( std::lock_guard<std::recursive_mutex> &G, const Poco::Net::Socket & S); | ||||
|         ClientList::iterator FindWSClient( std::lock_guard<std::recursive_mutex> &G, int ClientSocket); | ||||
|  | ||||
|  | ||||
| 	}; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 stephb9959
					stephb9959