コード例 #1
0
ファイル: topology.c プロジェクト: axn/bmx6
static int32_t topology_status_creator(struct status_handl *handl, void *data)
{
        struct avl_node *it = NULL;
        struct orig_node *on;
        uint32_t stsize = 0;
        uint32_t i = 0;
        struct topology_status *status = NULL;

        while (data ? (on = data) : (on = avl_iterate_item(&orig_tree, &it))) {

		topology_msgs = 0;
		topology_msg = NULL;
		uint32_t m = 0;
		process_description_tlvs(NULL, on, on->desc, TLV_OP_CUSTOM_TOPOLOGY, BMX_DSC_TLV_TOPOLOGY, NULL, NULL);

		for (m=0; topology_msg && m < topology_msgs; m++) {

			struct orig_node *non;
			struct avl_node *nan = NULL;
			while ((non = avl_iterate_item(&orig_tree, &nan)) && memcmp(&non->global_id.pkid, &topology_msg[m].pkid, sizeof(PKID_T)));

			if (non) {
				stsize += sizeof(struct topology_status);
				status = ((struct topology_status*) (handl->data = debugRealloc(handl->data, stsize, -300366)));

				memset(&status[i], 0, sizeof(struct topology_status));
				status[i].name = on->global_id.name;
				status[i].id = &on->global_id;
				status[i].primaryIp = on->primary_ip;
				status[i].blocked = on->blocked || non->blocked;
				status[i].lastDesc = (bmx_time - on->updated_timestamp) / 1000;
				status[i].txBw = fmetric_u8_to_umetric(topology_msg[m].txBw);
				status[i].rxBw = fmetric_u8_to_umetric(topology_msg[m].rxBw);
				status[i].txRate = topology_msg[m].txRate;
				status[i].rxRate = topology_msg[m].rxRate;
				status[i].neighName = non->global_id.name;
				status[i].neighId = &non->global_id;
				status[i].neighIp = non->primary_ip;

				i++;
			}
		}

                if(data)
                        break;

        }
        return stsize;
}
コード例 #2
0
ファイル: sms.c プロジェクト: agustim/bmx6
STATIC_FUNC
void json_inotify_event_hook(int fd)
{
        TRACE_FUNCTION_CALL;

        dbgf_track(DBGT_INFO, "detected changes in directory: %s", smsTx_dir);

        assertion(-501278, (fd > -1 && fd == extensions_fd));

        int ilen = 1024;
        char *ibuff = debugMalloc(ilen, -300375);
        int rcvd;
        int processed = 0;

        while ((rcvd = read(fd, ibuff, ilen)) == 0 || rcvd == EINVAL) {

                ibuff = debugRealloc(ibuff, (ilen = ilen * 2), -300376);
                assertion(-501279, (ilen <= (1024 * 16)));
        }

        if (rcvd > 0) {

                while (processed < rcvd) {

                        struct inotify_event *ievent = (struct inotify_event *) &ibuff[processed];

                        processed += (sizeof (struct inotify_event) +ievent->len);

                        if (ievent->mask & (IN_DELETE_SELF)) {
                                dbgf_sys(DBGT_ERR, "directory %s has been removed \n", smsTx_dir);
                                cleanup_all(-501290);
                        }
                }

        } else {
                dbgf_sys(DBGT_ERR, "read()=%d: %s \n", rcvd, strerror(errno));
        }

        debugFree(ibuff, -300377);

        check_for_changed_sms(NULL);
}