Example #1
0
void sender_poll_msgs(void* s)
{
    sender_t* me = s;
    msg_t* m;

    while ((m = llqueue_poll(me->inbox)))
    {
        switch (m->type)
        {
        case RAFT_MSG_APPENDENTRIES:
            raft_recv_appendentries(me->raft, m->sender, m->data);
            break;
        case RAFT_MSG_APPENDENTRIES_RESPONSE:
            raft_recv_appendentries_response(me->raft, m->sender, m->data);
            break;
        case RAFT_MSG_REQUESTVOTE:
            raft_recv_requestvote(me->raft, m->sender, m->data);
            break;
        case RAFT_MSG_REQUESTVOTE_RESPONSE:
            raft_recv_requestvote_response(me->raft, m->sender, m->data);
            break;
        case RAFT_MSG_ENTRY:
            raft_recv_entry(me->raft, m->sender, m->data);
            break;
        case RAFT_MSG_ENTRY_RESPONSE:
            //raft_recv_entry_response(me->raft, m->sender, m->data);
            break;

        }
    }
}
Example #2
0
static void zg_write_cb(EV_P_ ev_io *w, int revents)  //send by queue
{
	int rc=-1;
	EV_ALL *cev = (EV_ALL *)(((char *)w) - offsetof (EV_ALL, zg_writew));

	unsigned char *buf_ptr_item;
	send_queue_item_st *item;

	item = llqueue_poll(cev->zigbee_client.send_queue);
	buf_ptr_item = item->sendbuf;
	int sendlen = item->buflen;
	rc = ev_write(cev->zigbee_client.my_socket, buf_ptr_item, sendlen);

	if (rc <0)
	{
		log_printf(LOG_ERROR, "zg_write_cb,send msg to zigbee middleware failed\n");
		//TODO: ERROR HANDLE
	}
	else
	{
		//send success
		log_printf(LOG_NOTICE, "[Send2ZW]: %s, %d\n", buf_ptr_item, sendlen);
	}
	free(buf_ptr_item); //must free
	free(item); //must free
	int q_count = llqueue_count(cev->zigbee_client.send_queue);
	log_printf(LOG_NOTICE, "[ZigbeeSendQueueCount]=%d\n", q_count);
	if(q_count <=0)
	{
		log_printf(LOG_NOTICE, "[StopZigbeeSendWatcher]send queue empty!\n");
		ev_io_stop(cev->mainloop, &cev->zg_writew);
	}
}
Example #3
0
void* sender_poll_msg_data(void* s)
{
    sender_t* me = s;
    msg_t* msg;

    msg = llqueue_poll(me->outbox);
    return NULL != msg ? msg->data : NULL;
}
Example #4
0
static void mqtt_write_cb(EV_P_ ev_io *w, int revents)
{
	EV_ALL *cev = (EV_ALL *)(((char *)w) - offsetof (EV_ALL, mt_writew));
	int rc = FAILURE,
        sent = 0;

	unsigned char *buf_ptr_item;
	send_queue_item_st *item;

	item = llqueue_poll(cev->client.send_queue);
	buf_ptr_item = item->sendbuf;
	int length = item->buflen;

    while (sent < length)
    {
        rc = linux_write_ev(cev->client.ipstack, &buf_ptr_item[sent], length);
        if (rc < 0)  // there was an error writing the data
            break;
        sent += rc;
    }
    if (sent == length)
    {
    	//record the fact that we have successfully sent the packet
    	if(cev->client.keepAliveInterval >0) {
//    		cev->mt_pingw.repeat = cev->client.keepAliveInterval-1; //可以重新设超时时间
    		ev_timer_again(cev->mainloop, &cev->mt_pingw); //重新计时发ping包
    		log_printf(LOG_NOTICE, "reset mqtt ping timer,interval is %d\n", PING_INTERVAL);
    	}
    	log_printf(LOG_NOTICE, "[Send2Mqtt]: %s, %d\n", buf_ptr_item, length);
        rc = SUCCESS;
    }
    else
    {
    	log_printf(LOG_ERROR, "mqtt_write_cb failed\n");
        rc = FAILURE;
    }

    //队列数据取出发送之后,需要释放
	free(buf_ptr_item); //must free
	free(item); //must free
	int q_count = llqueue_count(cev->client.send_queue);
	log_printf(LOG_NOTICE, "[MqttSendQueueCount]=%d\n", q_count);
	if(q_count <=0)
	{
		log_printf(LOG_NOTICE, "[StopMqttSendWatcher]send queue empty!\n");
		ev_io_stop(cev->mainloop, &cev->mt_writew);
	}
	//

    if(rc != SUCCESS)
    {
    	log_printf(LOG_ERROR, "mqtt_write_cb failed,[ReConnectMqtt]\n");
		MQTTReConnect(&cev->client);
    }
}