From 00dba6082e245d917cb7d6eed3c627211ff41cd7 Mon Sep 17 00:00:00 2001 From: wangzhengquan <wangzhengquan85@126.com> Date: 星期五, 25 九月 2020 15:53:21 +0800 Subject: [PATCH] update --- src/socket/include/dmod_socket.h | 43 ++++++++++++++++++++++++++++++++----------- 1 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/socket/include/dmod_socket.h b/src/socket/include/dmod_socket.h index 5e97e2a..ecf92e7 100644 --- a/src/socket/include/dmod_socket.h +++ b/src/socket/include/dmod_socket.h @@ -18,7 +18,7 @@ #define BUS_MAP_KEY 1 //typedef std::basic_string<char, std::char_traits<char>, SHM_STL_Allocator<char> > SHMString; typedef std::set<int, std::less<int>, SHM_STL_Allocator<int> > SHMKeySet; -typedef std::map<SHMString, SHMKeySet *, std::less<SHMString>, SHM_STL_Allocator<std::pair<SHMString, SHMKeySet *> > > SHMTopicSubMap; +typedef std::map<SHMString, SHMKeySet *, std::less<SHMString>, SHM_STL_Allocator<std::pair<const SHMString, SHMKeySet *> > > SHMTopicSubMap; enum socket_mod_t { @@ -38,6 +38,7 @@ // pthread_t recv_thread; // <涓婚锛� 璁㈤槄鑰�> SHMTopicSubMap *topic_sub_map; + std::set<int> *bus_set; private: inline int _recvfrom_(void **buf, int *size, int *port, struct timespec *timeout, int flags); @@ -45,10 +46,18 @@ void _proxy_pub( char *topic, size_t head_len, void *buf, size_t size, int port); void *run_pubsub_proxy(); int parse_pubsub_topic(char *str, size_t size, char **_action, char **_topic, size_t *head_len ); - int _sub_( void *topic, int size, int port, struct timespec *timeout, int flags); - int _pub_( void *topic, int topic_size, void *content, int content_size, int port, struct timespec *timeout, int flags); + int _sub_( char *topic, int size, int port, struct timespec *timeout, int flags); + int _pub_( char *topic, int topic_size, void *content, int content_size, int port, struct timespec *timeout, int flags); - static void foreach_subscripters(std::function<void(SHMKeySet *, SHMKeySet::iterator)> cb) ; + void _proxy_desub( char *topic, int port); + void _proxy_desub_all(int port); + int _desub_( char *topic, int size, int port, struct timespec *timeout, int flags); + + static void foreach_subscripters(std::function<void(SHMKeySet *, int)> cb); + static bool include_in_keys(int key, int keys[], size_t length); + static size_t remove_subscripters(int keys[], size_t length) ; +public: + static size_t remove_keys(int keys[], size_t length); public: DModSocket(); ~DModSocket(); @@ -110,12 +119,22 @@ * @size 涓婚闀垮害 * @port 鎬荤嚎绔彛 */ - int sub(void *topic, int size, int port); + int sub(char *topic, int size, int port); // 瓒呮椂杩斿洖銆� @sec 绉� 锛� @nsec 绾崇 - int sub_timeout(void *topic, int size, int port, struct timespec *timeout); - int sub_nowait(void *topic, int size, int port); + int sub_timeout(char *topic, int size, int port, struct timespec *timeout); + int sub_nowait(char *topic, int size, int port); + /** + * 鍙栨秷璁㈤槄鎸囧畾涓婚 + * @topic 涓婚,涓婚涓虹┖鏃跺彇娑堝叏閮ㄨ闃� + * @size 涓婚闀垮害 + * @port 鎬荤嚎绔彛 + */ + int desub( char *topic, int size, int port); + // 瓒呮椂杩斿洖銆� @sec 绉� 锛� @nsec 绾崇 + int desub_timeout(char *topic, int size, int port, struct timespec *timeout); + int desub_nowait(char *topic, int size, int port) ; /** * 鍙戝竷涓婚 @@ -123,16 +142,18 @@ * @content 涓婚鍐呭 * @port 鎬荤嚎绔彛 */ - int pub(void *topic, int topic_size, void *content, int content_size, int port); + int pub(char *topic, int topic_size, void *content, int content_size, int port); // 瓒呮椂杩斿洖銆� @sec 绉� 锛� @nsec 绾崇 - int pub_timeout(void *topic, int topic_size, void *content, int content_size, int port, struct timespec *timeout); - int pub_nowait(void *topic, int topic_size, void *content, int content_size, int port); + int pub_timeout(char *topic, int topic_size, void *content, int content_size, int port, struct timespec *timeout); + int pub_nowait(char *topic, int topic_size, void *content, int content_size, int port); /** * 鑾峰彇soket绔彛鍙� */ int get_port() ; + + }; -#endif \ No newline at end of file +#endif -- Gitblit v1.8.0