📄 transnet.c
字号:
return;
}
/* mark the host as incoming one */
host->incoming = RV_TRUE;
/* register a new callback */
tpktRecvNotify(tpkt, transQ931Handler, host);
/* lock and mark the host before reporting it */
emaLock((EMAElement)host);
host->state = hostConnected;
transReportConnect(host, NULL, RV_FALSE);
emaUnlock((EMAElement)host);
}
else
{
RvLogError(&transGlobals->hLog, (&transGlobals->hLog,
"transQ931AcceptHandler got event %d (this cannot happen !!!)", event));
}
}
/**************************************************************************************
* transH245Handler
*
* Purpose: The callback routine for a H245 connection
*
* Input: standard input of TPKT callback
*
**************************************************************************************/
void transH245Handler(HTPKT tpkt,RvSelectEvents event,int length,int error,void*context)
{
cmTransHost *host = (cmTransHost *)context;
cmTransSession *session;
cmTransGlobals *transGlobals;
int sessNumOfLocks, hostNumOfLocks;
if (!emaLock((EMAElement)host))
return;
session = host->firstSession;
/* reverse the lcoking order so the session is locked BEFORE the host */
hostNumOfLocks = emaPrepareForCallback((EMAElement)host);
if (!emaLock((EMAElement)session))
{
emaReturnFromCallback((EMAElement)host, hostNumOfLocks);
return;
}
if (emaReturnFromCallback((EMAElement)host, hostNumOfLocks) != RV_TRUE)
{
emaUnlock((EMAElement)session);
return;
}
{
/* retrieve the transport module global area */
transGlobals = (cmTransGlobals *)emaGetUserData((EMAElement)session);
if (error)
{
RvLogError(&transGlobals->hLog, (&transGlobals->hLog,
"transH245Handler got error on event %d", event));
/* in case of a connection error report it so the user may discard the session */
if (event == RvSelectConnect)
{
if (transGlobals->sessionEventHandlers.cmEvTransConnectionOnSessionClosed)
{
HATRANSSESSION haTransSession = (HATRANSSESSION)emaGetApplicationHandle((EMAElement)session);
RvLogInfo(&transGlobals->hLog, (&transGlobals->hLog,
"cmEvTransConnectionOnSessionClosed(hsSession = %d(%p), haSessiont=%p, type=cmTransH245Conn)",
emaGetIndex((EMAElement)session),session,haTransSession));
hostNumOfLocks = emaPrepareForCallback((EMAElement)host);
sessNumOfLocks = emaPrepareForCallback((EMAElement)session);
transGlobals->sessionEventHandlers.cmEvTransConnectionOnSessionClosed(
(HSTRANSSESSION) session,
haTransSession,
cmTransH245Conn);
emaReturnFromCallback((EMAElement)session, sessNumOfLocks);
emaReturnFromCallback((EMAElement)host, hostNumOfLocks);
}
/* report the host close itself */
if ( (transGlobals->hostEventHandlers.cmEvTransHostClosed) && (host->reported) && (host->state != hostClosing) )
{
int numOfLocks;
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));
numOfLocks = emaPrepareForCallback((EMAElement)host);
transGlobals->hostEventHandlers.cmEvTransHostClosed((HSTRANSHOST)host,
haTransHost,
wasConnected);
emaReturnFromCallback((EMAElement)host, numOfLocks);
}
}
}
else
{
switch (event)
{
case RvSelectConnect:
{
TRANSERR res;
RvBool reportConnection = RV_TRUE;
if (host->hTpkt != tpkt)
break;
/* all ok we can use that connection */
host->state = hostConnected;
/* set the recieve event */
tpktRecvNotify(tpkt, transH245Handler, context);
/* close the listennning process if there was one */
if (host->h245Listen)
{
tpktClose(host->h245Listen);
host->h245Listen = NULL;
}
/* set the new local address of the host */
tpktGetAddresses(host->hTpkt, &host->localAddress, NULL);
if ((host->dummyHost) && (host->remoteAddress.port != 0) )
{
/* we connected a dummy host. no need to report the connection, but it is no longer dummy */
host->dummyHost = RV_FALSE;
/* and if anyone asks, we reported */
host->firstSession->reportedH245Connect = RV_TRUE;
reportConnection = RV_FALSE;
}
/* try and send all the tunneled messages that weren't sent or acked yet */
host->firstMessage = session->firstMessage;
session->firstMessage = NULL;
res = sendMessageOnHost(transGlobals, host);
if ( (res != cmTransOK) && (res != cmTransConnectionBusy) )
{
RvLogError(&transGlobals->hLog, (&transGlobals->hLog,
"transH245Handler Failed on sending ex-tunneled msgs for host %d(%p)",
emaGetIndex((EMAElement)host), host));
}
/* the H.245 connection is established, notify the user */
if(reportConnection)
transReportConnect(host, NULL, RV_TRUE);
break;
}
case RvSelectAccept:
/* can't happen, treated by another callback */
{
break;
}
case RvSelectClose:
case RvSelectRead:
{
int pvtNode = -1;
int res;
void *hMsgContext;
int offset = 0;
do
{
/* try to read and decode a message */
res = decodeIncomingMessage(tpkt, &length, &offset, context,
&pvtNode, cmTransH245Type, &hMsgContext);
/* set the read event on tpkt */
tpktRecvNotify(tpkt, transH245Handler, host);
if (res>=0)
{
HATRANSSESSION haTransSession = (HATRANSSESSION)emaGetApplicationHandle((EMAElement)session);
/* report the message to the user */
if ( (transGlobals->sessionEventHandlers.cmEvTransNewMessage) &&
(!emaWasDeleted((EMAElement)session)) )
{
RvLogInfo(&transGlobals->hLog, (&transGlobals->hLog,
"cmEvTransNewMessage(hsSession = %d(%p), haSession=%p, type=cmTransH245Type, pvtNode=%d)",
emaGetIndex((EMAElement)session), session, haTransSession, pvtNode));
sessNumOfLocks = emaPrepareForCallback((EMAElement)session);
hostNumOfLocks = emaPrepareForCallback((EMAElement)host);
transGlobals->sessionEventHandlers.cmEvTransNewMessage(
(HSTRANSSESSION) session,
(HATRANSSESSION) haTransSession,
cmTransH245Type,
pvtNode,
hMsgContext);
emaReturnFromCallback((EMAElement)session, sessNumOfLocks);
emaReturnFromCallback((EMAElement)host, hostNumOfLocks);
}
/* get rid of the decoded message */
pvtDelete(transGlobals->hPvt, pvtNode);
}
} while ( (length > 0) && (!emaWasDeleted((EMAElement)session)) );
if ( (event == RvSelectClose) && (!emaWasDeleted((EMAElement)host)) &&
(host->state != hostClosing) && (host->state != hostClosed) )
{
if ( (transGlobals->hostEventHandlers.cmEvTransHostClosed) && (host->reported) )
{
RvBool wasConnected = ( (host->state == hostConnected) ||
(host->state == hostBusy) );
HATRANSHOST haTransHost = (HATRANSHOST)emaGetApplicationHandle((EMAElement)host);
int numOfLocks;
host->state = hostClosing;
RvLogInfo(&transGlobals->hLog, (&transGlobals->hLog,
"cmEvTransHostClosed(hsHost = %d(%p), haHost=%p, wasConnected = %d)",
emaGetIndex((EMAElement)host), host, haTransHost, wasConnected));
numOfLocks = emaPrepareForCallback((EMAElement)host);
transGlobals->hostEventHandlers.cmEvTransHostClosed((HSTRANSHOST)host,
haTransHost,
wasConnected);
emaReturnFromCallback((EMAElement)host, numOfLocks);
}
else
{
if (!emaWasDeleted((EMAElement)host))
{
host->state = hostClosed;
transHostClose((HSTRANSHOST)host, RV_TRUE);
}
}
}
break;
}
case RvSelectWrite:
{
TRANSERR res;
/* the last send was completed */
/* remove the message from the pool */
extractMessageFromPool(transGlobals, host, RV_FALSE);
/* mark the host as not busy and try sending the remaining messages */
host->state = hostConnected;
res = sendMessageOnHost(transGlobals, host);
if ( (res != cmTransOK) && (res != cmTransConnectionBusy) )
{
RvLogError(&transGlobals->hLog, (&transGlobals->hLog,
"transH245Handler Failed on send for host %d(%p)",
emaGetIndex((EMAElement)host), host));
}
break;
}
}
}
/* unlock the host and its session */
emaUnlock((EMAElement)host);
emaUnlock((EMAElement)session);
}
}
/**************************************************************************************
* transH245AcceptHandler
*
* Purpose: The callback routine for the socket that listens for incoming H.245 request
*
* Input: standard input of TPKT callback
*
**************************************************************************************/
void transH245AcceptHandler(HTPKT tpkt,RvSelectEvents event,int length,int error,void*context)
{
cmTransHost *host = (cmTransHost *)context;
cmTransSession *session;
cmTransGlobals *transGlobals;
TRANSERR res;
int hostNumOfLocks;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -