• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ counter_inc函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中counter_inc函数的典型用法代码示例。如果您正苦于以下问题:C++ counter_inc函数的具体用法?C++ counter_inc怎么用?C++ counter_inc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了counter_inc函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: db_mysql_submit_query

/**
 * \brief Send a SQL query to the server.
 *
 * Send a SQL query to the database server. This methods tries to reconnect
 * to the server if the connection is gone and the auto_reconnect parameter is
 * enabled. It also issues a mysql_ping before the query to connect again after
 * a long waiting period because for some older mysql versions the auto reconnect
 * don't work sufficient. If auto_reconnect is enabled and the server supports it,
 * then the mysql_ping is probably not necessary, but its safer to do it in this
 * cases too.
 *
 * \param _h handle for the db
 * \param _s executed query
 * \return zero on success, negative value on failure
 */
static int db_mysql_submit_query(const db1_con_t* _h, const str* _s)
{
	time_t t;
	int i, code;

	if (!_h || !_s || !_s->s) {
		LM_ERR("invalid parameter value\n");
		return -1;
	}

	if (my_ping_interval) {
		t = time(0);
		if ((t - CON_TIMESTAMP(_h)) > my_ping_interval) {
			for (i=0; i < (db_mysql_auto_reconnect ? 3 : 1); i++) {
				if (mysql_ping(CON_CONNECTION(_h))) {
					LM_INFO("driver error on ping: %s\n", mysql_error(CON_CONNECTION(_h)));
					counter_inc(mysql_cnts_h.driver_err);
				} else {
					break;
				}
			}
		}
		/*
		 * We're doing later a query anyway that will reset the timout of the server,
		 * so it makes sense to set the timestamp value to the actual time in order
		 * to prevent unnecessary pings.
		 */
		CON_TIMESTAMP(_h) = t;
	}

	/* When a server connection is lost and a query is attempted, most of
	 * the time the query will return a CR_SERVER_LOST, then at the second
	 * attempt to execute it, the mysql lib will reconnect and succeed.
	 * However is a few cases, the first attempt returns CR_SERVER_GONE_ERROR
	 * the second CR_SERVER_LOST and only the third succeeds.
	 * Thus the 3 in the loop count. Increasing the loop count over this
	 * value shouldn't be needed, but it doesn't hurt either, since the loop
	 * will most of the time stop at the second or sometimes at the third
	 * iteration. In the case of CR_SERVER_GONE_ERROR and CR_SERVER_LOST the
	 * driver error counter is increased
	 */
	for (i=0; i < (db_mysql_auto_reconnect ? 3 : 1); i++) {
		if (mysql_real_query(CON_CONNECTION(_h), _s->s, _s->len) == 0) {
			return 0;
		}
		code = mysql_errno(CON_CONNECTION(_h));
		if (code!=CR_SERVER_GONE_ERROR && code!=CR_SERVER_LOST
				&& code!=CR_SSL_CONNECTION_ERROR && code!=CR_CONNECTION_ERROR
				&& code!=CR_CONN_HOST_ERROR && code!=CR_SERVER_LOST_EXTENDED) {
			break;
		}
		counter_inc(mysql_cnts_h.driver_err);
	}
	LM_ERR("driver error on query: %s (%d)\n", mysql_error(CON_CONNECTION(_h)),
			mysql_errno(CON_CONNECTION(_h)));
	return -2;
}
开发者ID:adubovikov,项目名称:kamailio,代码行数:72,代码来源:km_dbase.c


示例2: db_mysql_store_result

/**
 * Retrieve a result set
 * \param _h handle to the database
 * \param _r result set that should be retrieved
 * \return zero on success, negative value on failure
 */
static int db_mysql_store_result(const db1_con_t* _h, db1_res_t** _r)
{
	int code;
	if ((!_h) || (!_r)) {
		LM_ERR("invalid parameter value\n");
		return -1;
	}

	*_r = db_mysql_new_result();
	if (*_r == 0) {
		LM_ERR("no memory left\n");
		return -2;
	}

	RES_RESULT(*_r) = mysql_store_result(CON_CONNECTION(_h));
	if (!RES_RESULT(*_r)) {
		if (mysql_field_count(CON_CONNECTION(_h)) == 0) {
			(*_r)->col.n = 0;
			(*_r)->n = 0;
			goto done;
		} else {
			LM_ERR("driver error: %s\n", mysql_error(CON_CONNECTION(_h)));
			code = mysql_errno(CON_CONNECTION(_h));
			if (code == CR_SERVER_GONE_ERROR || code == CR_SERVER_LOST) {
				counter_inc(mysql_cnts_h.driver_err);
			}
			db_mysql_free_result(_h, *_r);
			*_r = 0;
			return -3;
		}
	}

	if (db_mysql_convert_result(_h, *_r) < 0) {
		LM_ERR("error while converting result\n");
		LM_DBG("freeing result set at %p\n", _r);
		/* all mem on Kamailio API side is already freed by
		 * db_mysql_convert_result in case of error, but we also need
		 * to free the mem from the mysql lib side, internal pkg for it
		 * and *_r */
		db_mysql_free_result(_h, *_r);
		*_r = 0;
#if (MYSQL_VERSION_ID >= 40100)
		while( mysql_more_results(CON_CONNECTION(_h)) && mysql_next_result(CON_CONNECTION(_h)) == 0 ) {
			MYSQL_RES *res = mysql_store_result( CON_CONNECTION(_h) );
			mysql_free_result(res);
		}
#endif
		return -4;
	}

done:
#if (MYSQL_VERSION_ID >= 40100)
	while( mysql_more_results(CON_CONNECTION(_h)) && mysql_next_result(CON_CONNECTION(_h)) == 0 ) {
		MYSQL_RES *res = mysql_store_result( CON_CONNECTION(_h) );
		mysql_free_result(res);
	}
#endif

	return 0;
}
开发者ID:AndreyRybkin,项目名称:kamailio,代码行数:66,代码来源:km_dbase.c


示例3: cdp_trans_timer

/**
 * Timer callback for checking the transaction status.
 * @param now - time of call
 * @param ptr - generic pointer, passed to the transactional callbacks
 */
int cdp_trans_timer(time_t now, void* ptr)
{
    cdp_trans_t *x,*n;
    lock_get(trans_list->lock);
    x = trans_list->head;
    while(x)
    {
        if (now>x->expires) {
            counter_inc(cdp_cnts_h.timeout);		//Transaction has timed out waiting for response

            x->ans = 0;
            if (x->cb) {
                (x->cb)(1,*(x->ptr),0, (now - x->expires));
            }
            n = x->next;

            if (x->prev) x->prev->next = x->next;
            else trans_list->head = x->next;
            if (x->next) x->next->prev = x->prev;
            else trans_list->tail = x->prev;
            if (x->auto_drop) cdp_free_trans(x);

            x = n;
        } else
            x = x->next;
    }
    lock_release(trans_list->lock);
    return 1;
}
开发者ID:kelchy,项目名称:kamailio,代码行数:34,代码来源:transaction.c


示例4: rx_process_asr

/*
 * Called upon receipt of an ASR. Terminates the user session and returns the ASA.
 * Terminates the corresponding dialog
 * @param request - the received request
 * @returns 0 always because ASA will be generated by the State Machine
 *
 */
AAAMessage* rx_process_asr(AAAMessage *request) {
    AAASession* session;
    unsigned int code = 0;

    rx_authsessiondata_t* p_session_data = 0;

    if (!request || !request->sessionId) return 0;

    counter_inc(ims_qos_cnts_h.asrs);
    
    session = cdpb.AAAGetAuthSession(request->sessionId->data);

    if (!session) {
        LM_DBG("received an ASR but the session is already deleted\n");
        return 0;
    }
    
    code = rx_get_abort_cause(request);
    LM_DBG("abort-cause code is %u\n", code);

    LM_DBG("PCRF requested an ASR");


    p_session_data = (rx_authsessiondata_t*) session->u.auth.generic_data;
    if (p_session_data->subscribed_to_signaling_path_status) {
        LM_DBG("This is a subscription to signalling status\n");
    } else {
        LM_DBG("This is a normal media bearer -  bearer is releaed by CDP callbacks\n");
    }
    cdpb.AAASessionsUnlock(session->hash);
    return 0;
}
开发者ID:AlessioCasco,项目名称:kamailio,代码行数:39,代码来源:rx_asr.c


示例5: cop421_execute

unsigned int cop421_execute(unsigned int cycles)
{
	unsigned int completed_cycles;
	
	for (completed_cycles = 0; completed_cycles < cycles; completed_cycles++)
	{
		
		// Store current instruction
		cur_inst = coprom[PC];
		inst_pc = PC;
		// Do preinstruction stuff
		preinst();
		pc_inc();		

		if (!g_skip)
		{
			if (cur_inst == 0x23 || cur_inst == 0x33 || (cur_inst >= 0x60 && cur_inst <= 0x63) || (cur_inst >= 0x68 && cur_inst <= 0x6b))
			{
				cur_operand = coprom[PC];
				pc_inc();
				execute_two_byte();
				
				// TODO: two byte instructions take two clocks?
				completed_cycles++; 
				counter_inc();
				counter_inc();
			}
	
			else // If its one byte
			{
				counter_inc();
				execute_one_byte();
			}
		}
		else
		{
			g_skip = 0;
			if (cur_inst == 0x23 || cur_inst == 0x33 || (cur_inst >= 0x60 && cur_inst <= 0x63) || (cur_inst >= 0x68 && cur_inst <= 0x6b))
			{
				pc_inc();
			}
			completed_cycles--; // TODO: a skipped instruction doesn't take a clock cycle?
		}
	}

	return completed_cycles;
}
开发者ID:DavidGriffith,项目名称:daphne,代码行数:47,代码来源:cop.cpp


示例6: dlg_ontimeout

/*!
 * \brief Timer function that removes expired dialogs, run timeout route
 * \param tl dialog timer list
 */
void dlg_ontimeout(struct dlg_tl *tl) {
    struct dlg_cell *dlg;
    int new_state, old_state, unref;
    struct sip_msg *fmsg;

    /* get the dialog tl payload */
    dlg = ((struct dlg_cell*) ((char *) (tl) -
            (unsigned long) (&((struct dlg_cell*) 0)->tl)));

    if (dlg->toroute > 0 && dlg->toroute < main_rt.entries
            && main_rt.rlist[dlg->toroute] != NULL) {
        fmsg = faked_msg_next();
        if (exec_pre_script_cb(fmsg, REQUEST_CB_TYPE) > 0) {
            dlg_set_ctx_dialog(dlg);
            LM_DBG("executing route %d on timeout\n", dlg->toroute);
            set_route_type(REQUEST_ROUTE);
            run_top_route(main_rt.rlist[dlg->toroute], fmsg, 0);
            dlg_set_ctx_dialog(0);
            exec_post_script_cb(fmsg, REQUEST_CB_TYPE);
        }
    }

    if (dlg->state == DLG_STATE_CONFIRMED) {
        dlg_bye_all(dlg, NULL);
        unref_dlg(dlg, 1);
        return;
    }

    next_state_dlg(dlg, DLG_EVENT_REQBYE, &old_state, &new_state, &unref, 0);

    if (new_state == DLG_STATE_DELETED && old_state != DLG_STATE_DELETED) {
        LM_WARN("timeout for dlg with CallID '%.*s' and tags '%.*s'\n",
                dlg->callid.len, dlg->callid.s,
                dlg->from_tag.len, dlg->from_tag.s);

		/* dialog timeout */
		run_dlg_callbacks(DLGCB_EXPIRED, dlg, NULL, NULL, DLG_DIR_NONE, 0);
		unref_dlg(dlg, unref + 1);
		counter_add(dialog_ng_cnts_h.active, -1);
		counter_inc(dialog_ng_cnts_h.expired);
		counter_inc(dialog_ng_cnts_h.processed);
    } else {
        unref_dlg(dlg, 1);
    }

    return;
}
开发者ID:AlessioCasco,项目名称:kamailio,代码行数:51,代码来源:dlg_handlers.c


示例7: cnt_inc_f

static int cnt_inc_f(struct sip_msg* msg, char* handle, char* bar)
{
	counter_handle_t h;
	
	h.id = (long)(void*)handle;
	counter_inc(h);
	return 1;
}
开发者ID:2pac,项目名称:kamailio,代码行数:8,代码来源:counters.c


示例8: ki_cnt_inc

static int ki_cnt_inc(sip_msg_t* msg, str *sname)
{
	char* name;
	char* grp;
	char* p;
	counter_handle_t h;

	cnt_op_handle_get();

	counter_inc(h);
	return 1;
}
开发者ID:adubovikov,项目名称:kamailio,代码行数:12,代码来源:counters.c


示例9: thread_wakeup_safe

//the "policy" here isn't strictly necessary (one can sleep when preemption is
//disabled), but _maybe_ this is what an API user might expect
void thread_wakeup_safe(Thread* thread, void* object)
{
    #ifdef COLLECT_HEAVY_THREAD_STATISTICS
    //we count at this point, because all other functions are too fuzzy
    //xxx only meaningful if not executed from an IRQ handler!
    counter_inc(&g_current_thread->wakeup_counter);
    #endif
    
    if (preemption_is_disabled())
        thread_wakeup_delayed(thread, object);
    else
        thread_wakeup_undelayed(thread, object);
}
开发者ID:wm4,项目名称:kernel,代码行数:15,代码来源:thread_sleep.c


示例10: subs_slot_add

/*!
 * \brief Add an element to an slot's linked list
 * \param _s hash slot
 * \param _r added record
 */
void subs_slot_add(hslot_sp_t* _s, struct ims_subscription_s* _r)
{
	if (_s->n == 0) {
		_s->first = _s->last = _r;
	} else {
		_r->prev = _s->last;
		_s->last->next = _r;
		_s->last = _r;
	}
	_s->n++;
        counter_inc(ul_scscf_cnts_h.active_subscriptions);
	_r->slot = _s;
}
开发者ID:4N7HR4X,项目名称:kamailio,代码行数:18,代码来源:hslot_sp.c


示例11: resume_on_termination_ccr

static void resume_on_termination_ccr(int is_timeout, void *param, AAAMessage *cca, long elapsed_msecs) {
    Ro_CCA_t *ro_cca_data = NULL;

    if (is_timeout) {
	counter_inc(ims_charging_cnts_h.ccr_timeouts);
	LM_ERR("Transaction timeout - did not get CCA\n");
	goto error;
    }

    counter_inc(ims_charging_cnts_h.ccr_replies_received);
    counter_add(ims_charging_cnts_h.ccr_response_time, elapsed_msecs);

    if (!cca) {
	LM_ERR("Error in termination CCR.\n");
	return;
    }

    ro_cca_data = Ro_parse_CCA_avps(cca);

    if (ro_cca_data == NULL) {
	LM_DBG("Could not parse CCA message response.\n");
	return;
    }

    if (ro_cca_data->resultcode != 2001) {
	LM_ERR("Got bad CCA result code for STOP record - [%d]\n", ro_cca_data->resultcode);
	goto error;
    } else {
	LM_DBG("Valid CCA response for STOP record\n");
    }

    counter_inc(ims_charging_cnts_h.successful_final_ccrs);

error:
    Ro_free_CCA(ro_cca_data);
    if (!is_timeout && cca) {
	cdpb.AAAFreeMessage(&cca);
    }
}
开发者ID:Gitlab11,项目名称:kamailio,代码行数:39,代码来源:ims_ro.c


示例12: thread_sleep

//set the current thread to sleep
//must respect the current preemption disable state (no windows!)
void thread_sleep(void* object)
{
    #ifdef COLLECT_HEAVY_THREAD_STATISTICS
    counter_inc(&g_current_thread->sleep_counter);
    #endif
    
    //preemption must be disabled
    //else there'll be a race condition in the _sleep/_wakeup mechanism
    assert(preemption_is_disabled());
    
    g_current_thread->state = THREAD_STATE_BLOCKED;
    g_current_thread->block_object = object;
    reschedule();
}
开发者ID:wm4,项目名称:kernel,代码行数:16,代码来源:thread_sleep.c


示例13: _sip_resolvehost

/* resolves a host name trying:
 * - NAPTR lookup if enabled, the address is not an ip and *proto==0 and 
 *   *port==0. The result of the NAPTR query will be used for a SRV lookup
 * - SRV lookup if the address is not an ip *port==0. The result of the SRV
 *   query will be used for an A/AAAA lookup.
 *  - normal A/AAAA lookup (either fallback from the above or if *port!=0
 *   and *proto!=0 or port==0 && proto==0)
 * when performing SRV lookup (*port==0) it will use *proto to look for
 * tcp or udp hosts, otherwise proto is unused; if proto==0 => no SRV lookup
 *
 * returns: hostent struct & *port filled with the port from the SRV record;
 *  0 on error
 */
struct hostent* _sip_resolvehost(str* name, unsigned short* port, char* proto)
{
	struct hostent* res = NULL;
#ifdef USE_NAPTR
	if (cfg_get(core, core_cfg, dns_try_naptr))
		res = naptr_sip_resolvehost(name, port, proto);
	else
#endif
	res = srv_sip_resolvehost(name, 0, port, proto, 0, 0);
	if( unlikely(!res) ){
		/* failed DNS request */
		counter_inc(dns_cnts_h.failed_dns_req);
	}
	return res;
}
开发者ID:miao606,项目名称:kamailio,代码行数:28,代码来源:resolve.c


示例14: mem_insert_impurecord

/*!
 * \brief Insert a new record into domain in memory
 * \param _d domain the record belongs to
 * \param _aor address of record
 * \param _r new created record
 * \return 0 on success, -1 on failure
 */
int mem_insert_impurecord(struct udomain* _d, str* public_identity, str* private_identity, int reg_state, int barring,
        ims_subscription** s, str* ccf1, str* ccf2, str* ecf1, str* ecf2,
        struct impurecord** _r) {
    int sl;

    if (new_impurecord(_d->name, public_identity, private_identity, reg_state, barring, s, ccf1, ccf2, ecf1,
            ecf2, _r) < 0) {
        LM_ERR("creating impurecord failed\n");
        return -1;
    }

    sl = ((*_r)->aorhash) & (_d->size - 1);
    slot_add(&_d->table[sl], *_r);
    counter_inc(ul_scscf_cnts_h.active_impus);

    LM_DBG("inserted new impurecord into memory [%.*s]\n", (*_r)->public_identity.len, (*_r)->public_identity.s);
    return 0;
}
开发者ID:Gitlab11,项目名称:kamailio,代码行数:25,代码来源:udomain.c


示例15: mem_insert_scontact

/*!
 * \brief Add a new contact in memory
 *
 * Add a new contact in memory, contacts are ordered by:
 * 1) q value, 2) descending modification time
 * \param _r record this contact belongs to
 * \param _c contact
 * \param _ci contact information
 * \return pointer to new created contact on success, 0 on failure
 */
ucontact_t* mem_insert_scontact(impurecord_t* _r, str* _c, ucontact_info_t* _ci) {
    ucontact_t* c;
    int sl;

    if ((c = new_ucontact(_r->domain, &_r->public_identity, _c, _ci)) == 0) {
        LM_ERR("failed to create new contact\n");
        return 0;
    }
    counter_inc(ul_scscf_cnts_h.active_contacts);

    LM_DBG("Created new contact in memory with AOR: [%.*s] and hash [%d]\n", _c->len, _c->s, c->sl);

    sl = (c->sl);
    lock_contact_slot_i(sl);
    contact_slot_add(&contact_list->slot[sl], c);
    unlock_contact_slot_i(sl);

    return c;
}
开发者ID:nakchak,项目名称:kamailio,代码行数:29,代码来源:impurecord.c


示例16: LongProcessing

void LongProcessing(void)
{
  int i, j;

  counter_start(10000);

  for (i = 0; i < 10000; i++)
  {
    for (j = 0; j < 10000; j++)
    {
      double x = fabs(sin(j * 100.) + cos(j * 100.));
      x = sqrt(x * x);
    }

    if (!counter_inc())
      break;
  }

  counter_stop();
}
开发者ID:svn2github,项目名称:iup-github,代码行数:20,代码来源:progressdlg.c


示例17: send_msg

static int send_msg(msg_data_t *msg, struct remote_ip_t * rip , int work_idx , int file_fd )
{
	int	ret;
	int	left_len = 0;

	left_len = sizeof(msg_data_t) + ntohl(msg->datalen);

retry_head:
	ret = write(rip->sockfd[work_idx], /*msg->data*/ (char*)msg, left_len);
	if(ret <= 0){
		perror("write fail\n");
		printf("fd %d\n" , rip->sockfd[work_idx]);
		return ret;
	}

	left_len -= ret;
	if(left_len > 0)
		goto retry_head;
	snd_msg_cnt++;
	counter_inc(&send_success_cnt);
	//printf("handler block id %d cnt %d\n" , ntohl(msg->blockid) , counter_read(&send_success_cnt));
	return 1;
}
开发者ID:getmoon,项目名称:vmsync,代码行数:23,代码来源:work_handler.c


示例18: db_mysql_new_connection

/*! \brief
 * Create a new connection structure,
 * open the MySQL connection and set reference count to 1
 */
struct my_con* db_mysql_new_connection(const struct db_id* id)
{
	struct my_con* ptr;
	char *host, *grp, *egrp;

	if (!id) {
		LM_ERR("invalid parameter value\n");
		return 0;
	}

	ptr = (struct my_con*)pkg_malloc(sizeof(struct my_con));
	if (!ptr) {
		LM_ERR("no private memory left\n");
		return 0;
	}

	egrp = 0;
	memset(ptr, 0, sizeof(struct my_con));
	ptr->ref = 1;
	
	ptr->con = (MYSQL*)pkg_malloc(sizeof(MYSQL));
	if (!ptr->con) {
		LM_ERR("no private memory left\n");
		goto err;
	}

	mysql_init(ptr->con);

	if (id->host[0] == '[' && (egrp = strchr(id->host, ']')) != NULL) {
		grp = id->host + 1;
		*egrp = '\0';
		host = egrp;
		if (host != id->host + strlen(id->host)-1) {
			host += 1; // host found after closing bracket
		}
		else {
			// let mysql read host info from my.cnf
			// (defaults to "localhost")
			host = NULL;
		}
		// read [client] and [<grp>] sections in the order
		// given in my.cnf
		mysql_options(ptr->con, MYSQL_READ_DEFAULT_GROUP, grp);
	}
	else {
		host = id->host;
	}

	if (id->port) {
		LM_DBG("opening connection: mysql://xxxx:[email protected]%s:%d/%s\n", ZSW(host),
			id->port, ZSW(id->database));
	} else {
		LM_DBG("opening connection: mysql://xxxx:[email protected]%s/%s\n", ZSW(host),
			ZSW(id->database));
	}

	// set connect, read and write timeout, the value counts three times
	mysql_options(ptr->con, MYSQL_OPT_CONNECT_TIMEOUT, (const char *)&db_mysql_timeout_interval);
	mysql_options(ptr->con, MYSQL_OPT_READ_TIMEOUT, (const char *)&db_mysql_timeout_interval);
	mysql_options(ptr->con, MYSQL_OPT_WRITE_TIMEOUT, (const char *)&db_mysql_timeout_interval);

#if (MYSQL_VERSION_ID >= 40100)
	if (!mysql_real_connect(ptr->con, host, id->username, id->password,
				id->database, id->port, 0, CLIENT_MULTI_STATEMENTS)) {
#else
	if (!mysql_real_connect(ptr->con, host, id->username, id->password,
				id->database, id->port, 0, 0)) {
#endif
		LM_ERR("driver error: %s\n", mysql_error(ptr->con));
		/* increase error counter */
		counter_inc(mysql_cnts_h.driver_err);
		mysql_close(ptr->con);
		goto err;
	}
	/* force reconnection if enabled */
	if (db_mysql_auto_reconnect)
		ptr->con->reconnect = 1;
	else 
		ptr->con->reconnect = 0;

	LM_DBG("connection type is %s\n", mysql_get_host_info(ptr->con));
	LM_DBG("protocol version is %d\n", mysql_get_proto_info(ptr->con));
	LM_DBG("server version is %s\n", mysql_get_server_info(ptr->con));

	ptr->timestamp = time(0);
	ptr->id = (struct db_id*)id;
	if(egrp) *egrp = ']';
	return ptr;

 err:
	if (ptr && ptr->con) pkg_free(ptr->con);
	if (ptr) pkg_free(ptr);
	if(egrp) *egrp = ']';
	return 0;
}

//.........这里部分代码省略.........
开发者ID:SipCoSystems,项目名称:hush,代码行数:101,代码来源:km_my_con.c


示例19: ro_session_ontimeout


//.........这里部分代码省略.........

    if (!ro_session) {
        LM_ERR("Can't find a session. This is bad");
        return;
    }

    LM_DBG("event-type=%d", ro_session->event_type);

    //	if (!ro_session->active) {
    //		LM_ALERT("Looks like this session was terminated while requesting more units");
    //		goto exit;
    //		return;
    //	}


    if(ro_session->is_final_allocation) {
        now = get_current_time_micro();
        used_secs = now - ro_session->last_event_timestamp;
        if((ro_session->reserved_secs - used_secs) > 0) {
            update_ro_timer(&ro_session->ro_tl, (ro_session->reserved_secs - used_secs));
            return;
        }
        else {
            ro_session->event_type = no_more_credit;
        }
    }

    switch (ro_session->event_type) {
        case answered:
            now = get_current_time_micro();
            used_secs = rint((now - ro_session->last_event_timestamp) / (float) 1000000);
            call_time = rint((now - ro_session->start_time) / (float) 1000000);

			if ((used_secs + ro_session->billed) < (call_time)) {
				adjustment = call_time - (used_secs + ro_session->billed);
				LM_DBG("Making adjustment for Ro interim timer by adding %d seconds\n", adjustment);
				used_secs += adjustment;
			}
			
            counter_add(ims_charging_cnts_h.billed_secs, used_secs);

            if (ro_session->callid.s != NULL && ro_session->ro_session_id.s != NULL) {
                LM_DBG("Found a session to re-apply for timing [%.*s] and user is [%.*s]\n",
                        ro_session->ro_session_id.len,
                        ro_session->ro_session_id.s,
                        ro_session->asserted_identity.len,
                        ro_session->asserted_identity.s);

                LM_DBG("Call session has been active for %i seconds. The last reserved secs was [%i] and the last event was [%i seconds] ago",
                        (unsigned int) call_time,
                        (unsigned int) ro_session->reserved_secs,
                        (unsigned int) used_secs);

                LM_DBG("Call session [p=%p]: we will now make a request for another [%i] of credit with a usage of [%i] seconds from the last bundle.\n",
                        ro_session,
                        interim_request_credits/* new reservation request amount */,
                        (unsigned int) used_secs/* charged seconds from previous reservation */);

                // Apply for more credit.
                //
                // The function call will return immediately and we will receive the reply asynchronously via a callback
				ro_session->billed += used_secs;
                send_ccr_interim(ro_session, (unsigned int) used_secs, interim_request_credits);
                return;
            } else {
                LM_ERR("Hmmm, the session we have either doesn't have all the data or something else has gone wrong.\n");
                /* put the timer back so the call will be killed according to previous timeout. */
                ro_session->event_type = unknown_error;
                int ret = insert_ro_timer(&ro_session->ro_tl,
                        (ro_session->reserved_secs - used_secs) / 1000000);
                if (ret != 0) {
                    LM_CRIT("unable to insert timer for Ro Session [%.*s]\n",
                            ro_session->ro_session_id.len, ro_session->ro_session_id.s);
                } else {
                    ref_ro_session(ro_session, 1, 0);
                    return;
                }
                LM_ERR("Immediately killing call due to unknown error\n");
            }
            break;
        case delayed_delete:
            destroy_ro_session(ro_session);
            return;
        case pending:
            /* call is not answered yet. No point asking more credit. Just wait for dialog to progress somehow */
            return;
        default:
            LM_ERR("Diameter call session - event [%d]\n", ro_session->event_type);

            if (ro_session->event_type == no_more_credit)
                LM_INFO("Call/session must be ended - no more funds.\n");
            else if (ro_session->event_type == unknown_error)
                LM_ERR("last event caused an error. We will now tear down this session.\n");
    }

    counter_inc(ims_charging_cnts_h.killed_calls);

    dlgb.lookup_terminate_dlg(ro_session->dlg_h_entry, ro_session->dlg_h_id, &default_out_of_credit_hdrs);
    return;
}
开发者ID:krys1976,项目名称:kamailio,代码行数:101,代码来源:ro_timer.c


示例20: db_mysql_fetch_result

/**
 * \brief Gets a partial result set, fetch rows from a result
 *
 * Gets a partial result set, fetch a number of rows from a database result.
 * This function initialize the given result structure on the first run, and
 * fetches the nrows number of rows. On subsequenting runs, it uses the
 * existing result and fetches more rows, until it reaches the end of the
 * result set. Because of this the result needs to be null in the first
 * invocation of the function. If the number of wanted rows is zero, the
 * function returns anything with a result of zero.
 * \param _h structure representing the database connection
 * \param _r pointer to a structure representing the result
 * \param nrows number of fetched rows
 * \return zero on success, negative value on failure
 */
int db_mysql_fetch_result(const db1_con_t* _h, db1_res_t** _r, const int nrows)
{
	int rows, i, code;

	if (!_h || !_r || nrows < 0) {
		LM_ERR("Invalid parameter value\n");
		return -1;
	}

	/* exit if the fetch count is zero */
	if (nrows == 0) {
		db_free_result(*_r);
		*_r = 0;
		return 0;
	}

	if(*_r==0) {
		/* Allocate a new result structure */
		*_r = db_new_result();
		if (*_r == 0) {
			LM_ERR("no memory left\n");
			return -2;
		}

		CON_RESULT(_h) = mysql_store_result(CON_CONNECTION(_h));
		if (!CON_RESULT(_h)) {
			if (mysql_field_count(CON_CONNECTION(_h)) == 0) {
				(*_r)->col.n = 0;
				(*_r)->n = 0;
				return 0;
			} else {
				LM_ERR("driver error: %s\n", mysql_error(CON_CONNECTION(_h)));
				code = mysql_errno(CON_CONNECTION(_h));
				if (code == CR_SERVER_GONE_ERROR || code == CR_SERVER_LOST) {
					counter_inc(mysql_cnts_h.driver_err);
				}
				db_free_result(*_r);
				*_r = 0;
				return -3;
			}
		}
		if (db_mysql_get_columns(_h, *_r) < 0) {
			LM_ERR("error while getting column names\n");
			return -4;
		}

		RES_NUM_ROWS(*_r) = mysql_num_rows(CON_RESULT(_h));
		if (!RES_NUM_ROWS(*_r)) {
			LM_DBG("no rows returned from the query\n");
			RES_ROWS(*_r) = 0;
			return 0;
		}

	} else {
		/* free old rows */
		if(RES_ROWS(*_r)!=0)
			db_free_rows(*_r);
		RES_ROWS(*_r) = 0;
		RES_ROW_N(*_r) = 0;
	}

	/* determine the number of rows remaining to be processed */
	rows = RES_NUM_ROWS(*_r) - RES_LAST_ROW(*_r);

	/* If there aren't any more rows left to process, exit */
	if(rows<=0)
		return 0;

	/* if the fetch count is less than the remaining rows to process                 */
	/* set the number of rows to process (during this call) equal to the fetch count */
	if(nrows < rows)
		rows = nrows;

	RES_ROW_N(*_r) = rows;

	LM_DBG("converting row %d of %d count %d\n", RES_LAST_ROW(*_r),
			RES_NUM_ROWS(*_r), RES_ROW_N(*_r));

	RES_ROWS(*_r) = (struct db_row*)pkg_malloc(sizeof(db_row_t) * rows);
	if (!RES_ROWS(*_r)) {
		LM_ERR("no memory left\n");
		return -5;
	}

	for(i = 0; i < rows; i++) {
//.........这里部分代码省略.........
开发者ID:mehulsbhatt,项目名称:voip-foip,代码行数:101,代码来源:km_dbase.c



注:本文中的counter_inc函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ countof函数代码示例发布时间:2022-05-30
下一篇:
C++ counter_arch_bp函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap