Skip to content

Commit

Permalink
搜索retain标记消息的内容,订阅端上线后如何收到被retain标记消息
Browse files Browse the repository at this point in the history
  • Loading branch information
Allanceng committed Dec 18, 2014
1 parent 8ffa179 commit 391ef43
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/net_mosq.c
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ int _mosquitto_packet_write(struct mosquitto *mosq)
while(mosq->current_out_packet){
packet = mosq->current_out_packet;

while(packet->to_process > 0){
while(packet->to_process > 0){//发送一个包,可能包很长,一次没有发完
write_length = _mosquitto_net_write(mosq, &(packet->payload[packet->pos]), packet->to_process);
if(write_length > 0){
#if defined(WITH_BROKER) && defined(WITH_SYS_TREE)
Expand Down
2 changes: 1 addition & 1 deletion src/read_handle_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ int mqtt3_handle_subscribe(struct mosquitto_db *db, struct mosquitto *context)
// printf("it's crutial to subclient%s\n", sub);
rc2 = mqtt3_sub_add(db, context, sub, qos, &db->subs);
if(rc2 == MOSQ_ERR_SUCCESS){
if(mqtt3_retain_queue(db, context, sub, qos)) rc = 1;
if(mqtt3_retain_queue(db, context, sub, qos)) rc = 1; //调用该函数保证刚上线的订阅端可以收到服务端储存的retain的消息
}else if(rc2 != -1){
rc = rc2;
}
Expand Down
4 changes: 2 additions & 2 deletions src/subs.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ static int _subs_process(struct mosquitto_db *db, struct _mosquitto_subhier *hie
db->persistence_changes++;
}
#endif
if(hier->retained){
if(hier->retained){ //如果非空,证明这里有上次存储的retain的消息,现在有新的消息需要retain,则替换旧的消息,故要做下面的减法
hier->retained->ref_count--;
/* FIXME - it would be nice to be able to remove the message from the store at this point if ref_count == 0 */
db->retained_count--;
// printf("hier->retained is not null,hier->retained->ref_count:%d,db->retained_count:%d\n", hier->retained->ref_count, db->retained_count);
//printf("hier->retained is not null,hier->retained->ref_count:%d,db->retained_count:%d\n", hier->retained->ref_count, db->retained_count);
}
if(stored->msg.payloadlen){
hier->retained = stored;
Expand Down

0 comments on commit 391ef43

Please sign in to comment.