Mosquitto-1.5.4源码,全局的数据结构

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/libaineu2004/article/details/84935291

/lib/mosquitto_internal.h

struct mosquitto { //结构体struct mosquito主要用于保存一个客户端连接的所有信息,例如用户名、密码、用户ID、向该客户端发送的消息等
    mosq_sock_t sock; /*服务器程序与该客户端连接通信所用的socket描述符*/
#ifndef WITH_BROKER
	mosq_sock_t sockpairR, sockpairW;
#endif
#if defined(__GLIBC__) && defined(WITH_ADNS)
	struct gaicb *adns; /* For getaddrinfo_a */
#endif
	enum mosquitto__protocol protocol;
    char *address; /*该客户端的IP地址*/
    char *id; /*该客户端登陆mosquitto程序时所提供的ID值,该值与其他的客户端不能重复*/
	char *username;
	char *password;
    uint16_t keepalive; /*该客户端需在此时间内向mosquitto服务器程序发送一条ping/pong消息*/
	uint16_t last_mid;
	enum mosquitto_client_state state;
    time_t last_msg_in; /*last_msg_in和last_msg_out用于记录上次收发消息的时间*/
	time_t next_msg_out;
	time_t ping_t;
	struct mosquitto__packet in_packet;
	struct mosquitto__packet *current_out_packet;
	struct mosquitto__packet *out_packet;
	struct mosquitto_message *will;
    ......

/src/mosquitto_broker_internal.h

struct mosquitto__subleaf { //firecat,leaf叶子,对某一topic的所有订阅者被组织成一个订阅列表,该订阅列表是一个双向链表,链表的每个节点都保存有一个订阅者
    struct mosquitto__subleaf *prev; /*前指针*/
    struct mosquitto__subleaf *next; /*后指针*/
    struct mosquitto *context; /*表示一个订阅客户端*/
    int qos; /* Qos Level */
};

struct mosquitto__subhier { //用来保存订阅树的所有节点(包括叶子节点和中间节点),mosquitto中对订阅树采用孩子-兄弟链表法的方式进行存储
	UT_hash_handle hh;
	struct mosquitto__subhier *parent;
    struct mosquitto__subhier *children; /*第一个孩子节点*/
    struct mosquitto__subleaf *subs; /*指向订阅列表*/
	struct mosquitto_msg_store *retained;
    mosquitto__topic_element_uhpa topic; /*订阅主题*/
	uint16_t topic_len;
};

struct mosquitto_db{ //结构体struct mosquitto_db是mosquitto对所有内部数据的统一管理结构,可以认为是其内部的一个内存数据库。
                     //它保存了所有的客户端,所有客户端的订阅关系等等
	dbid_t last_db_id;
    struct mosquitto__subhier *subs; /*订阅树的总树根*/
	struct mosquitto__unpwd *unpwd;
	struct mosquitto__unpwd *psk_id;
    struct mosquitto *contexts_by_id; /*所有的客户端都在此数组中保存*/
	struct mosquitto *contexts_by_sock;
	struct mosquitto *contexts_for_free;
#ifdef WITH_BRIDGE
	struct mosquitto **bridges;
#endif
    struct clientid__index_hash *clientid_index_hash; /*用于保存一个hash表,该hash表可通过客户端的ID快速找到该客户端在数组contexts中的索引*/
	struct mosquitto_msg_store *msg_store;
	struct mosquitto_msg_store_load *msg_store_load;
#ifdef WITH_BRIDGE
	int bridge_count;
#endif
	int msg_store_count;
	unsigned long msg_store_bytes;
	char *config_file;
    struct mosquitto__config *config; /*保存所有配置信息*/
	int auth_plugin_count;
	bool verbose;
#ifdef WITH_SYS_TREE
	int subscription_count;
	int retained_count;
#endif
	int persistence_changes;
	struct mosquitto *ll_for_free;
#ifdef WITH_EPOLL
	int epollfd;
#endif
};

猜你喜欢

转载自blog.csdn.net/libaineu2004/article/details/84935291