📄 transnet.c
字号:
if (length);
if (!emaLock((EMAElement)host))
return;
session = host->firstSession;
/* reverse th elcoking order so the session is locked BEFORE the host */
hostNumOfLocks = emaPrepareForCallback((EMAElement)host);
if (!emaLock((EMAElement)session))
{
emaReturnFromCallback((EMAElement)host, hostNumOfLocks);
/* 2004.11.03, added. make sure we unlock the mutex */
emaUnlock((EMAElement)host);
return;
}
if (emaReturnFromCallback((EMAElement)host, hostNumOfLocks) != RV_TRUE)
{
emaUnlock((EMAElement)session);
/* 2004.11.03, added. make sure we unlock the mutex */
emaUnlock((EMAElement)host);
return;
}
/* retrieve the transport module global area */
transGlobals = (cmTransGlobals *)emaGetUserData((EMAElement)session);
/* check if we realy want this connection or we already opened one */
if (event == 0)
{
solveH245Conflict(host);
/* after solving the problem (or if there was no connecting host at all)
the host is in any case connecting now */
host->state = hostConnecting;
}
else
if (error)
{
RvLogError(&transGlobals->hLog, (&transGlobals->hLog,
"transH245AcceptHandler got error on event %d", event));
}
else
if (session->H245Connection != host)
{
RvLogError(&transGlobals->hLog, (&transGlobals->hLog,
"transH245AcceptHandler mismatched session and host %p %p",session->H245Connection, host));
}
else
/* treat the accept event of a H.245 TPKT connection */
if ( (event == RvSelectAccept) && (context) )
{
/* set the new local address of the host */
tpktGetAddresses(tpkt, &session->H245Connection->localAddress, NULL);
session->H245Connection->state = hostConnected;
/* set the H245 connection to point to the accepting socket */
session->H245Connection->hTpkt = tpkt;
session->H245Connection->h245Listen = NULL;
/* verify that tunneling is over */
session->tunnelingState = tunnNo;
session->parallelTunnelingState = parllNo;
/* try and send all the tunneled messages that weren't sent or acked yet */
session->H245Connection->firstMessage = session->firstMessage;
session->firstMessage = NULL;
/* set the receive event and change the handler routine */
tpktRecvNotify(tpkt, transH245Handler, context);
res = sendMessageOnHost(transGlobals, session->H245Connection);
if ( (res != cmTransOK) && (res != cmTransConnectionBusy) )
{
RvLogError(&transGlobals->hLog, (&transGlobals->hLog,
"transH245AcceptHandler Failed on send of ex-tunneled msgs for host %d(%p)",
emaGetIndex((EMAElement)session->H245Connection), session->H245Connection));
}
/* the H.245 connection is established, notify the user */
transReportConnect(session->H245Connection, NULL, RV_FALSE);
}
else
{
RvLogError(&transGlobals->hLog, (&transGlobals->hLog,
"transH245AcceptHandler got event %d (this cannot happen !!!)", event));
}
/* unlock and release the host and its session */
emaUnlock((EMAElement)session);
emaUnlock((EMAElement)host);
}
/**************************************************************************************
* transQ931Handler
*
* Purpose: The callback routine for a Q.931 connection
*
* Input: standard input of TPKT callback
*
*
**************************************************************************************/
void transQ931Handler(HTPKT tpkt,RvSelectEvents event,int length,int error,void*context)
{
cmTransHost *host = (cmTransHost *)context;
/* retrieve the transport module global area */
cmTransGlobals *transGlobals = (cmTransGlobals *)emaGetUserData((EMAElement)host);
if (emaLock((EMAElement)host))
{
if (error)
{
RvLogError(&transGlobals->hLog, (&transGlobals->hLog,
"transQ931Handler got error on event=%d error=%d", event, error));
/* in case of a connection error report it so the user may discard the session(s),
however if the host is in race with an annex E host, no report is needed */
if (event == RvSelectConnect)
{
if (transGlobals->sessionEventHandlers.cmEvTransConnectionOnSessionClosed)
{
cmTransSession *session = host->firstSession;
int hostNumOfLocks;
/* unlock the host so it won't be locked before a session lock */
hostNumOfLocks = emaPrepareForCallback((EMAElement)host);
while (emaLock((EMAElement)session))
{
int numOfLocks;
cmTransSession *previousSession;
HATRANSSESSION haTransSession = (HATRANSSESSION)emaGetApplicationHandle((EMAElement)session);
if ( (session->Q931Connection == host) && (session->annexEConnection) )
{
RvLogError(&transGlobals->hLog, (&transGlobals->hLog,
"transQ931Handler will no report this error on host (%p-%d) since annex E (%p-%d) may yet secceed",
host, emaGetIndex((EMAElement)host),
session->annexEConnection, emaGetIndex((EMAElement)session->annexEConnection)));
}
else
{
RvLogError(&transGlobals->hLog, (&transGlobals->hLog,
"cmEvTransConnectionOnSessionClosed(hsSession = %d(%p), haSessiont=%p, type=cmTransQ931Conn)",
emaGetIndex((EMAElement)session),session, haTransSession));
numOfLocks = emaPrepareForCallback((EMAElement)session);
transGlobals->sessionEventHandlers.cmEvTransConnectionOnSessionClosed(
(HSTRANSSESSION) session,
haTransSession,
cmTransQ931Conn);
emaReturnFromCallback((EMAElement)session, numOfLocks);
}
previousSession = session;
session = session->nextSession;
/* release the session */
emaUnlock((EMAElement)previousSession);
}
/* reinstate the host lock */
emaReturnFromCallback((EMAElement)host, hostNumOfLocks);
}
if ( (transGlobals->hostEventHandlers.cmEvTransHostClosed) && (host->reported) && (host->state != hostClosing) )
{
/* report the host close itself */
int hostNumOfLocks;
RvBool wasConnected = ( (host->state == hostConnected) ||
(host->state == hostBusy) );
HATRANSHOST haTransHost = (HATRANSHOST)emaGetApplicationHandle((EMAElement)host);
host->state = hostClosing;
RvLogInfo(&transGlobals->hLog, (&transGlobals->hLog,
"cmEvTransHostClosed(hsHost = %d(%p), haHost=%p, wasConnected = %d)",
emaGetIndex((EMAElement)host), host, haTransHost, wasConnected));
hostNumOfLocks = emaPrepareForCallback((EMAElement)host);
transGlobals->hostEventHandlers.cmEvTransHostClosed((HSTRANSHOST)host,
haTransHost,
wasConnected);
emaReturnFromCallback((EMAElement)host, hostNumOfLocks);
}
}
}
else
{
switch (event)
{
case RvSelectConnect:
{
TRANSERR res;
/* if the host is in Idle state it does not wait a connection,
probably it was Droped by TransDrop. */
if (host->state != hostIdle)
{
/* a connection was established, notify the user */
host->state = hostConnected;
/* set the new local address of the host */
tpktGetAddresses(host->hTpkt, &host->localAddress, NULL);
/* register a new callback */
tpktRecvNotify(tpkt, transQ931Handler, host);
transReportConnect(host, NULL, RV_TRUE);
/* check if we have a stored SETUP message (already sent on Annex E
connection) that needs to be sent */
if (host->firstMessage)
{
res = sendMessageOnHost(transGlobals, host);
if ( (res != cmTransOK) && (res != cmTransConnectionBusy) )
{
RvLogError(&transGlobals->hLog, (&transGlobals->hLog,
"transQ931Handler Failed on send for host %d(%p)",
emaGetIndex((EMAElement)host), host));
}
}
}
break;
}
case RvSelectAccept:
/* can't happen, treated by another callback */
{
break;
}
case RvSelectClose:
case RvSelectRead:
{
RvPvtNodeId pvtNode = -1;
int res;
void *hMsgContext;
int offset = 0;
RvBool sessionWasLocked = RV_FALSE;
cmTransSession *session = NULL;
HATRANSSESSION haTransSession = NULL;
/* try to read and decode a message */
res = decodeIncomingMessage(tpkt, &length, &offset, context,
&pvtNode, cmTransQ931Type, &hMsgContext);
/* set the read event on tpkt */
tpktRecvNotify(tpkt, transQ931Handler, host);
if (res>=0)
{
RvBool ok = RV_FALSE;
RvBool acceptedCall = RV_FALSE;
/* check that we can accept new messages on this host */
acceptedCall = canWeAcceptTheCall(transGlobals, host, pvtNode);
/* find the session of the call */
if (acceptedCall)
ok = findSessionByMessage(transGlobals,
host,
pvtNode,
(host->annexEUsageMode != cmTransNoAnnexE),
&session);
/* we have a decoded Q.931 message, process it */
if (ok)
{
int msgType;
int hostNumOfLocks;
/* if we found the session of the message, lock it and mark it */
if (session)
{
/* unlock the host so it won't be locked before the session */
hostNumOfLocks = emaPrepareForCallback((EMAElement)host);
sessionWasLocked = emaLock((EMAElement)session);
/* reinstate the host lock */
emaReturnFromCallback((EMAElement)host, hostNumOfLocks);
if (sessionWasLocked == RV_FALSE)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -