コード例 #1
0
ファイル: mock_send_functions.c プロジェクト: fatman2021/raft
int __append_msg(
    sender_t* me,
    void* data,
    int type,
    int len,
    int peer,
    raft_server_t* raft
)
{
    msg_t* m;
    m = malloc(sizeof(msg_t));
    m->type = type;
    m->len = len;
    m->data = malloc(len);
    m->sender = raft_get_nodeid(raft);
    memcpy(m->data,data,len);
    llqueue_offer(me->outbox,m);

    if (__nsenders > peer)
    {
        llqueue_offer(__senders[peer]->inbox, m);
    }

    return 1;
}
コード例 #2
0
ファイル: mock_send_functions.c プロジェクト: fatman2021/raft
int sender_send(raft_server_t* raft,
                void* udata,
                int peer,
                raft_message_type_e type,
                const unsigned char* data,
                int len)
{
    sender_t* me = udata;
    msg_t* m;

    m = malloc(sizeof(msg_t));
    m->type = type;
    m->len = len;
    m->data = malloc(len);
    m->sender = raft_get_nodeid(raft);
    memcpy(m->data,data,len);
    llqueue_offer(me->outbox,m);

    if (__nsenders > peer)
    {
        llqueue_offer(__senders[peer]->inbox, m);
    }

    return 0;
}
コード例 #3
0
ファイル: ev_wrap.c プロジェクト: yanlunyao/SmartStoreGateway
/*
 * description: send msg to zigbee middleware
 * sendbuf: the msg , need contain '\0' in the tail
 * sendbuflen: msg length
 * */
void ev_send_msg_2_zigbees(EV_ALL* cev, const unsigned char *sendbuf, int sendbuflen) //add send queue
{
	if(cev->zigbee_client.isconnected ==socket_notconnect)
	{
		log_printf(LOG_ERROR, "[ZigbeeClientIsClosed]\n");
		return;
	}

	send_queue_item_st *item;
	item = malloc(sizeof(send_queue_item_st));//important, must be free , 队列发送完成后需要释放
	unsigned char *buf_ptr_item = malloc(sendbuflen); //important, must be free , 队列发送完成后需要释放
	//snprintf((char *)buf_ptr_item, sendbuflen, "%s", (char *)sendbuf);
//	char* buf_ptr_item = (char *)sendbuf;
	memcpy(buf_ptr_item, sendbuf,sendbuflen );
	item->sendbuf = buf_ptr_item;
	item->buflen = sendbuflen;

	llqueue_offer(cev->zigbee_client.send_queue, item);  //入队列

	int q_count = llqueue_count(cev->zigbee_client.send_queue);

	log_printf(LOG_NOTICE, "[ZigbeeSendQueueCount]=%d\n", q_count);

	if(llqueue_count(cev->zigbee_client.send_queue)==1)
	{
//		ev_io_set(&cev->zg_writew, cev->zigbee_client.my_socket, EV_WRITE);
		ev_io_start(cev->mainloop, &cev->zg_writew);
	}
}
コード例 #4
0
ファイル: ev_wrap.c プロジェクト: yanlunyao/SmartStoreGateway
void ev_send_msg_2_mqtts(EV_ALL* cev, const unsigned char *sendbuf, int sendbuflen) //new queue send
{
	send_queue_item_st *item;

	item = malloc(sizeof(send_queue_item_st));//important, must be free , 队列发送完成后需要释放
	unsigned char *buf_ptr_item = malloc(sendbuflen); //important, must be free , 队列发送完成后需要释放
	memcpy(buf_ptr_item, sendbuf, sendbuflen);

	item->sendbuf = buf_ptr_item;
	item->buflen = sendbuflen;

	llqueue_offer(cev->client.send_queue, item);  //入队列

	int q_count = llqueue_count(cev->client.send_queue);

	log_printf(LOG_NOTICE, "[MqttSendQueueCount]=%d\n", q_count);

	if(llqueue_count(cev->client.send_queue)==1)
	{
		ev_io_start(cev->mainloop, &cev->mt_writew);
	}
}