Skip to content

Commit

Permalink
查找订阅系统主题短时间自动断开原因,该时间与sys_interval有关,若该时间
Browse files Browse the repository at this point in the history
内没有该主题的消息发布,则当server读到数据长度为0时,自动断开。(此处
处理可优化)若有消息发布,则可一直保持连接
  • Loading branch information
zengang committed Nov 6, 2014
1 parent 8fb3f12 commit b5657f1
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/net_mosq.c
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ int _mosquitto_packet_read(struct mosquitto *mosq)
if(!(mosq->bridge) && mosq->state == mosq_cs_new && (byte&0xF0) != CONNECT) return MOSQ_ERR_PROTOCOL;
#endif
}else{
if(read_length == 0) return MOSQ_ERR_CONN_LOST; /* EOF */
if(read_length == 0) return MOSQ_ERR_CONN_LOST; /* EOF*/
#ifdef WIN32
errno = WSAGetLastError();
#endif
Expand Down Expand Up @@ -887,7 +887,7 @@ int _mosquitto_packet_read(struct mosquitto *mosq)
mosq->in_packet.remaining_length += (byte & 127) * mosq->in_packet.remaining_mult;
mosq->in_packet.remaining_mult *= 128;
}else{
if(read_length == 0) return MOSQ_ERR_CONN_LOST; /* EOF */
if(read_length == 0) return MOSQ_ERR_CONN_LOST; /* EOF MOSQ_ERR_CONN_LOST的值为7,系统自动断开的情况都是从这里开始*/
#ifdef WIN32
errno = WSAGetLastError();
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ static void _config_init_reload(struct mqtt3_config *config)
config->retry_interval = 20;
config->store_clean_interval = 10;
//config->sys_interval = 900;
config->sys_interval = 10;
config->sys_interval = 40;
config->upgrade_outgoing_qos = false;
if(config->auth_options){
for(i=0; i<config->auth_option_count; i++){
Expand Down
5 changes: 3 additions & 2 deletions src/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ static void loop_handle_errors(struct mosquitto_db *db, struct pollfd *pollfds)
static void loop_handle_reads_writes(struct mosquitto_db *db, struct pollfd *pollfds)
{
int i;
int rc;

for(i=0; i<db->context_count; i++){
if(db->contexts[i] && db->contexts[i]->sock != INVALID_SOCKET){//判断是否有数据需要写
Expand All @@ -363,9 +364,9 @@ static void loop_handle_reads_writes(struct mosquitto_db *db, struct pollfd *pol
#else
if(pollfds[db->contexts[i]->pollfd_index].revents & POLLIN){
#endif
if(_mosquitto_packet_read(db, db->contexts[i])){
if(rc = _mosquitto_packet_read(db, db->contexts[i])){
do_disconnect(db, i);
printf("read error,disconnect!\n");
printf("read error,disconnect!rc=%d\n", rc);
}
printf("read data!\n");
}
Expand Down
Binary file removed src/loop.o
Binary file not shown.
Binary file removed src/mosquitto
Binary file not shown.

0 comments on commit b5657f1

Please sign in to comment.