rvmegacostack.c

来自「h.248协议源码」· C语言 代码 · 共 1,213 行 · 第 1/3 页

C
1,213 行
字号
		{param: {n:data} {d:User data that will be passed to the callback.}}
	}
}
$*/
void rvMegacoStackRegisterRawSendCB(RvMegacoStack *stack, RvMegacoRawCB f, void *data)
{
	stack->rawSendCb = f;
	stack->rawSendData = data;
}


/*$
{function:
	{name: rvMegacoStackRegisterParseErrorCB}
	{class: RvMegacoStack}
	{include: rvmegacostack.h}
	{description:
		{p: Registers a callback that will be invoked for each parser error.}
	}
	{proto: void rvMegacoStackRegisterParseErrorCB(RvMegacoStack *stack, RvMegacoParseErrorCB f, void *data);}
	{params:
		{param: {n:stack} {d:The stack object.}}
		{param: {n:f} {d:The callback.}}
		{param: {n:data} {d:User data that will be passed to the callback.}}
	}
}
$*/
void rvMegacoStackRegisterParseErrorCB(RvMegacoStack *stack, RvMegacoParseErrorCB f, void *data)
{
	stack->parseErrorCb = f;
	stack->parseErrorData = data;
}


/*$
{function:
	{name: rvMegacoStackGetAuthenticationFailures}
	{class: RvMegacoStack}
	{include: rvmegacostack.h}
	{description:
		{p: Gets the number of authentication failures that have occurred on this stack.}
	}
	{proto: unsigned int rvMegacoStackGetAuthenticationFailures(const RvMegacoStack *stack);}
	{params:
		{param: {n:stack} {d:The stack object.}}
	}
	{returns: The number of authentication failures.}
}
$*/
unsigned int rvMegacoStackGetAuthenticationFailures(const RvMegacoStack *stack)
{
	return stack->authenticationFailures;
}


/*$
{function:
	{name: rvMegacoStackClearAuthenticationFailures}
	{class: RvMegacoStack}
	{include: rvmegacostack.h}
	{description:
		{p: Resets the count of authentication failures for this stack.}
	}
	{proto: void rvMegacoStackClearAuthenticationFailures(RvMegacoStack *stack);}
	{params:
		{param: {n:stack} {d:The stack object.}}
	}
}
$*/
void rvMegacoStackClearAuthenticationFailures(RvMegacoStack *stack)
{
	stack->authenticationFailures = 0;
}


/*$
{function:
	{name: rvMegacoStackGetParseErrors}
	{class: RvMegacoStack}
	{include: rvmegacostack.h}
	{description:
		{p: Gets the number of parse errors that have occurred on this stack.}
	}
	{proto: unsigned int rvMegacoStackGetParseErrors(const RvMegacoStack *stack);}
	{params:
		{param: {n:stack} {d:The stack object.}}
	}
	{returns: The number of parse errors.}
}
$*/
unsigned int rvMegacoStackGetParseErrors(const RvMegacoStack *stack)
{
	return stack->parseErrors;
}


/*$
{function:
	{name: rvMegacoStackClearParseErrors}
	{class: RvMegacoStack}
	{include: rvmegacostack.h}
	{description:
		{p: Resets the count of parse errors for this stack.}
	}
	{proto: void rvMegacoStackClearParseErrors(RvMegacoStack *stack);}
	{params:
		{param: {n:stack} {d:The stack object.}}
	}
}
$*/
void rvMegacoStackClearParseErrors(RvMegacoStack *stack)
{
	stack->parseErrors = 0;
}


/*$
{function:
	{name: rvMegacoStackSetSendDelay}
	{class: RvMegacoStack}
	{include: rvmegacostack.h}
	{description:
		{p: Sets the send delay for this stack. This is the amount of time
		the stack will wait before sending a transaction to allow other
		transactions to be sent in the same message.}
	}
	{proto: void rvMegacoStackSetSendDelay(RvMegacoStack *stack, unsigned int ms);}
	{params:
		{param: {n:stack} {d:The stack object.}}
		{param: {n:ms} {d:The send delay in milliseconds.}}
	}
}
$*/
void rvMegacoStackSetSendDelay(RvMegacoStack *stack, unsigned int ms)
{
	stack->sendDelay = 
		ms > RV_MEGACOSTACK_SENDDELAY_MAX ? RV_MEGACOSTACK_SENDDELAY_MAX :
#if RV_MEGACOSTACK_SENDDELAY_MIN > 0
		ms < RV_MEGACOSTACK_SENDDELAY_MIN ? RV_MEGACOSTACK_SENDDELAY_MIN : 
#endif
		ms;
}


/*$
{function:
	{name: rvMegacoStackSetInitialRetransTimeout}
	{class: RvMegacoStack}
	{include: rvmegacostack.h}
	{description:
		{p: Sets the initial retransmission timeout for the stack.
		This is the retransmission timeout that will be used when the stack
		has no round trip time information for a given remote entity.}
	}
	{proto: void rvMegacoStackSetInitialRetransTimeout(RvMegacoStack *stack, unsigned int ms);}
	{params:
		{param: {n:stack} {d:The stack object.}}
		{param: {n:ms} {d:The initial retransmission timeout in milliseconds.}}
	}
}
$*/
void rvMegacoStackSetInitialRetransTimeout(RvMegacoStack *stack, unsigned int ms)
{
	RvHrtime ns;
	ns = ms * RV_TIME_NSECPERMSEC;
	stack->timeoutLimits.initial = 
		ns > RV_MEGACOSTACK_INITRETRANSTIMEOUT_MAX ? RV_MEGACOSTACK_INITRETRANSTIMEOUT_MAX :
		ns < RV_MEGACOSTACK_INITRETRANSTIMEOUT_MIN ? RV_MEGACOSTACK_INITRETRANSTIMEOUT_MIN : ns;
}


/*$
{function:
	{name: rvMegacoStackSetMinRetransTimeout}
	{class: RvMegacoStack}
	{include: rvmegacostack.h}
	{description:
		{p: Sets the lower bound for the retransmission timeout.}
	}
	{proto: void rvMegacoStackSetMinRetransTimeout(RvMegacoStack *stack, unsigned int ms);}
	{params:
		{param: {n:stack} {d:The stack object.}}
		{param: {n:ms} {d:The minimum retransmission timeout in milliseconds.}}
	}
}
$*/
void rvMegacoStackSetMinRetransTimeout(RvMegacoStack *stack, unsigned int ms)
{
	ms *= RV_TIME_NSECPERMSEC;
	stack->timeoutLimits.min = 
		ms > RV_MEGACOSTACK_MINRETRANSTIMEOUT_MAX ? RV_MEGACOSTACK_MINRETRANSTIMEOUT_MAX :
		ms < RV_MEGACOSTACK_MINRETRANSTIMEOUT_MIN ? RV_MEGACOSTACK_MINRETRANSTIMEOUT_MIN : ms;
}


/*$
{function:
	{name: rvMegacoStackSetMaxRetransTimeout}
	{class: RvMegacoStack}
	{include: rvmegacostack.h}
	{description:
		{p: Sets the upper bound for the retransmission timeout.}
	}
	{proto: void rvMegacoStackSetMaxRetransTimeout(RvMegacoStack *stack, unsigned int ms);}
	{params:
		{param: {n:stack} {d:The stack object.}}
		{param: {n:ms} {d:The maximum retransmission timeout in milliseconds.}}
	}
}
$*/
void rvMegacoStackSetMaxRetransTimeout(RvMegacoStack *stack, unsigned int ms)
{
	RvHrtime ns;
	ns = ms * RV_TIME_NSECPERMSEC;
	stack->timeoutLimits.max = 
		ns > RV_MEGACOSTACK_MAXRETRANSTIMEOUT_MAX ? RV_MEGACOSTACK_MAXRETRANSTIMEOUT_MAX :
		ns < RV_MEGACOSTACK_MAXRETRANSTIMEOUT_MIN ? RV_MEGACOSTACK_MAXRETRANSTIMEOUT_MIN : ns;
}


/*$
{function:
	{name: rvMegacoStackSetRetransWindow}
	{class: RvMegacoStack}
	{include: rvmegacostack.h}
	{description:
		{p: Sets the maximum amount of time after the initial transmission of
		a message that a retransmission of that message will be attempted.}
	}
	{proto: void rvMegacoStackSetRetransWindow(RvMegacoStack *stack, unsigned int ms);}
	{params:
		{param: {n:stack} {d:The stack object.}}
		{param: {n:ms} {d:The retransmission window in milliseconds.}}
	}
}
$*/
void rvMegacoStackSetRetransWindow(RvMegacoStack *stack, unsigned int ms)
{
	RvHrtime ns;
	ns = ms * RV_TIME_NSECPERMSEC;
	stack->tMax = 
		ns > RV_MEGACOSTACK_TMAX_MAX ? RV_MEGACOSTACK_TMAX_MAX :
		ns < RV_MEGACOSTACK_TMAX_MIN ? RV_MEGACOSTACK_TMAX_MIN : ns;
}


/*$
{function:
	{name: rvMegacoStackSetMaxPacketSize}
	{class: RvMegacoStack}
	{include: rvmegacostack.h}
	{description:
		{p: Sets the maximum size of an outbound packet.}
	}
	{proto: void rvMegacoStackSetMaxPacketSize(RvMegacoStack *stack, size_t packetSize);}
	{params:
		{param: {n:stack} {d:The stack object.}}
		{param: {n:packetSize} {d:The maximum packet size in bytes.}}
	}
	{notes:
		{note: This parameter limits the size of an outgoing packet
		when bundling multiple transactions into one message. However, a single
		transaction exceeding the maximum packet size will always be sent.}
	}
}
$*/
void rvMegacoStackSetMaxPacketSize(RvMegacoStack *stack, size_t packetSize)
{
	if(packetSize <= RV_UDP_MAXLENGTH && packetSize <= RV_TPKT_MAXLENGTH)
		stack->maxPacketSize = packetSize;
}


/*$
{function:
	{name: rvMegacoStackGetSendDelay}
	{class: RvMegacoStack}
	{include: rvmegacostack.h}
	{description:
		{p: Gets the send delay for this stack. This is the amount of time
		the stack will wait before sending a transaction to allow other
		transactions to be sent in the same message.}
	}
	{proto: unsigned int rvMegacoStackGetSendDelay(RvMegacoStack *stack);}
	{params:
		{param: {n:stack} {d:The stack object.}}
	}
	{returns: The send delay in milliseconds.}
}
$*/
unsigned int rvMegacoStackGetSendDelay(RvMegacoStack *stack)
{
	return stack->sendDelay;
}


/*$
{function:
	{name: rvMegacoStackGetInitialRetransTimeout}
	{class: RvMegacoStack}
	{include: rvmegacostack.h}
	{description:
		{p: Gets the initial retransmission timeout for the stack.
		This is the retransmission timeout that will be used when the stack
		has no round trip time information for a given remote entity.}
	}
	{proto: unsigned int rvMegacoStackGetInitialRetransTimeout(const RvMegacoStack *stack);}
	{params:
		{param: {n:stack} {d:The stack object.}}
	}
	{returns: The initial retransmission timeout in milliseconds.}
}
$*/
unsigned int rvMegacoStackGetInitialRetransTimeout(const RvMegacoStack *stack)
{
	return (unsigned int)(stack->timeoutLimits.initial / RV_TIME_NSECPERMSEC); 
}


/*$
{function:
	{name: rvMegacoStackGetMinRetransTimeout}
	{class: RvMegacoStack}
	{include: rvmegacostack.h}
	{description:
		{p: Gets the lower bound for the retransmission timeout.}
	}
	{proto: unsigned int rvMegacoStackGetMinRetransTimeout(const RvMegacoStack *stack);}
	{params:
		{param: {n:stack} {d:The stack object.}}
	}
	{returns: The minimum retransmission timeout in milliseconds.}
}
$*/
unsigned int rvMegacoStackGetMinRetransTimeout(const RvMegacoStack *stack)
{
	return (unsigned int)(stack->timeoutLimits.min / RV_TIME_NSECPERMSEC); 
}


/*$
{function:
	{name: rvMegacoStackGetMaxRetransTimeout}
	{class: RvMegacoStack}
	{include: rvmegacostack.h}
	{description:
		{p: Gets the upper bound for the retransmission timeout.}
	}
	{proto: unsigned int rvMegacoStackGetMaxRetransTimeout(const RvMegacoStack *stack);}
	{params:
		{param: {n:stack} {d:The stack object.}}
	}
	{returns: The maximum retransmission timeout in milliseconds.}
}
$*/
unsigned int rvMegacoStackGetMaxRetransTimeout(const RvMegacoStack *stack)
{
	return (unsigned int)(stack->timeoutLimits.max / RV_TIME_NSECPERMSEC); 
}


/*$
{function:
	{name: rvMegacoStackGetRetransWindow}
	{class: RvMegacoStack}
	{include: rvmegacostack.h}
	{description:
		{p: Gets the maximum amount of time after the initial transmission of
		a message that a retransmission of that message will be attempted.}
	}
	{proto: unsigned int rvMegacoStackGetRetransWindow(const RvMegacoStack *stack);}
	{params:
		{param: {n:stack} {d:The stack object.}}
	}
	{returns: The retransmission window in milliseconds.}
}
$*/
unsigned int rvMegacoStackGetRetransWindow(const RvMegacoStack *stack)
{
	return (unsigned int)(stack->tMax / RV_TIME_NSECPERMSEC); 
}


/*$
{function:
	{name: rvMegacoStackGetMaxPacketSize}
	{class: RvMegacoStack}
	{include: rvmegacostack.h}
	{description:
		{p: Gets the maximum size of an outbound packet.}
	}
	{proto: size_t rvMegacoStackGetMaxPacketSize(const RvMegacoStack *stack);}
	{params:
		{param: {n:stack} {d:The stack object.}}
	}
	{returns: The maximum size of an outbound packet in bytes.}
}
$*/
size_t rvMegacoStackGetMaxPacketSize(const RvMegacoStack *stack)
{
	return stack->maxPacketSize;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?