Exemplo n.º 1
0
void recoverConnection(RsslReactor *pReactor, RsslReactorChannel *pChannel, NIChannelCommand *pCommand)
{
	time_t currentTime;
	RsslErrorInfo rsslErrorInfo;
	RsslUInt i;
	time(&currentTime);
	pCommand->reconnect = RSSL_TRUE;

	if (pChannel->socketId != REACTOR_INVALID_SOCKET)
	{
		FD_CLR(pChannel->socketId, &readFds);
		FD_CLR(pChannel->socketId, &exceptFds);
	}

	if (rsslReactorCloseChannel(pReactor, pChannel, &rsslErrorInfo) != RSSL_RET_SUCCESS)
	{
		printf("rsslReactorCloseChannel() failed: %s\n", rsslErrorInfo.rsslError.text);
	}
	rsslClearRDMLoginRefresh(&pCommand->loginRefresh);
	pCommand->loginRefreshBuffer.data = pCommand->loginRefreshArray;
	pCommand->loginRefreshBuffer.length = LOGIN_ARRAY_LENGTH;

	for(i = 0; i < pCommand->marketPriceItemCount; i++)
	{
		pCommand->marketPriceItemInfo[i].IsRefreshComplete = RSSL_FALSE;
	}

	for(i = 0; i < pCommand->marketByOrderItemCount; i++)
	{
		pCommand->marketByOrderItemInfo[i].IsRefreshComplete = RSSL_FALSE;
	}

	pCommand->startWrite = RSSL_FALSE;

}
Exemplo n.º 2
0
/* 
 * Closes a channel in the RsslReactor
 */
void closeConnection(RsslReactor *pReactor, RsslReactorChannel *pChannel, ChannelStorage *pCommand)
{
	RsslErrorInfo rsslErrorInfo;

	if (pChannel->socketId != REACTOR_INVALID_SOCKET)
	{
		FD_CLR(pChannel->socketId, &readFds);
		FD_CLR(pChannel->socketId, &exceptFds);
	}

	if (rsslReactorCloseChannel(pReactor, pChannel, &rsslErrorInfo) != RSSL_RET_SUCCESS)
	{
		printf("rsslReactorCloseChannel() failed: %s\n", rsslErrorInfo.rsslError.text);
	}

	pCommand->reactorChannelReady = RSSL_FALSE;
	clearChannelStorage(pCommand);
}
Exemplo n.º 3
0
static void handleRuntime()
{
	RsslErrorInfo error;
	time_t currentTime = 0;
	RsslRet	retval = 0;

	/* get current time */
	time(&currentTime); 

	if(chnlCommand.reconnect == RSSL_TRUE)
	{
		chnlCommand.reconnect = RSSL_FALSE;
		printf("Reconnecting in 10 seconds...\n");
		chnlCommand.timeToReconnect = 10;
	}

	if (chnlCommand.timeToReconnect > 0)
	{
		--chnlCommand.timeToReconnect;

		if (chnlCommand.timeToReconnect == 0)
		{
			if (rsslReactorConnect(pReactor, &chnlCommand.cOpts, chnlCommand.pRole, &error) != RSSL_RET_SUCCESS)
			{
				printf("Error rsslReactorConnect(): %s\n", error.rsslError.text);
				chnlCommand.reconnect = RSSL_TRUE;
			}
		}
	}

	if(currentTime > rsslProviderRuntime)
	{
		if( chnlCommand.reactorChannel != NULL && rsslReactorCloseChannel(pReactor, chnlCommand.reactorChannel, &error) != RSSL_RET_SUCCESS)
		{
			printf("Error rsslReactorCloseChannel(): %s\n", error.rsslError.text);
		}

		cleanUpAndExit();
	}

}
Exemplo n.º 4
0
/*
 * Removes a client session for a channel.
 * pReactorChannel - The channel to remove the client session for
 */
void removeClientSessionForChannel(RsslReactor *pReactor, RsslReactorChannel *pReactorChannel)
{
	RsslErrorInfo rsslErrorInfo;
	int i;

	for (i = 0; i < MAX_CLIENT_SESSIONS; i++)
	{
		if (clientSessions[i].clientChannel == pReactorChannel)
		{
			removeClientSession(&clientSessions[i]);
			break;
		}
	}

	FD_CLR(pReactorChannel->socketId, &readFds);
	FD_CLR(pReactorChannel->socketId, &exceptFds);


	if (rsslReactorCloseChannel(pReactor, pReactorChannel, &rsslErrorInfo) != RSSL_RET_SUCCESS)
	{
		printf("rsslReactorCloseChannel() failed: %s\n", rsslErrorInfo.rsslError.text);
		cleanUpAndExit();
	}
}
Exemplo n.º 5
0
RsslReactorCallbackRet channelEventCallback(RsslReactor *pReactor, RsslReactorChannel *pReactorChannel, RsslReactorChannelEvent *pChannelEvent)
{
	ProviderSession *pProvSession = (ProviderSession *)pReactorChannel->userSpecPtr;
	ProviderThread *pProviderThread = pProvSession->pProviderThread;
	RsslErrorInfo rsslErrorInfo;
	RsslReactorChannelInfo reactorChannelInfo;
	RsslUInt32 count;
	RsslRet ret;

	switch(pChannelEvent->channelEventType)
	{
		case RSSL_RC_CET_CHANNEL_UP:
		{
			/* A channel that we have requested via rsslReactorAccept() has come up.  Set our
			 * file descriptor sets so we can be notified to start calling rsslReactorDispatch() for
			 * this channel. */
			FD_SET(pReactorChannel->socketId, &pProviderThread->readfds);
			FD_SET(pReactorChannel->socketId, &pProviderThread->exceptfds);

#ifdef ENABLE_XML_TRACE
			RsslTraceOptions traceOptions;
			rsslClearTraceOptions(&traceOptions);
			traceOptions.traceMsgFileName = "upacProvPerf";
			traceOptions.traceMsgMaxFileSize = 1000000000;
			traceOptions.traceFlags |= RSSL_TRACE_TO_FILE_ENABLE | RSSL_TRACE_WRITE | RSSL_TRACE_READ;
			rsslIoctl(pChannelInfo->pChannel, (RsslIoctlCodes)RSSL_TRACE, (void *)&traceOptions, &error);
#endif

			if (provPerfConfig.highWaterMark > 0)
			{
				if (rsslReactorChannelIoctl(pReactorChannel, RSSL_HIGH_WATER_MARK, &provPerfConfig.highWaterMark, &rsslErrorInfo) != RSSL_RET_SUCCESS)
                {
					printf("rsslReactorChannelIoctl() of RSSL_HIGH_WATER_MARK failed <%s>\n", rsslErrorInfo.rsslError.text);
					exit(-1);
                }
			}

			if ((ret = rsslReactorGetChannelInfo(pReactorChannel, &reactorChannelInfo, &rsslErrorInfo)) != RSSL_RET_SUCCESS)
			{
				printf("rsslReactorGetChannelInfo() failed: %d\n", ret);
				return RSSL_RC_CRET_SUCCESS;
			} 

			printf( "Channel %d active. Channel Info:\n"
					"  maxFragmentSize: %u\n"
					"  maxOutputBuffers: %u\n"
					"  guaranteedOutputBuffers: %u\n"
					"  numInputBuffers: %u\n"
					"  pingTimeout: %u\n"
					"  clientToServerPings: %s\n"
					"  serverToClientPings: %s\n"
					"  sysSendBufSize: %u\n"
					"  sysSendBufSize: %u\n"			
					"  compressionType: %s\n"
					"  compressionThreshold: %u\n"			
					"  ComponentInfo: ", 
					pReactorChannel->socketId,
					reactorChannelInfo.rsslChannelInfo.maxFragmentSize,
					reactorChannelInfo.rsslChannelInfo.maxOutputBuffers, reactorChannelInfo.rsslChannelInfo.guaranteedOutputBuffers,
					reactorChannelInfo.rsslChannelInfo.numInputBuffers,
					reactorChannelInfo.rsslChannelInfo.pingTimeout,
					reactorChannelInfo.rsslChannelInfo.clientToServerPings == RSSL_TRUE ? "true" : "false",
					reactorChannelInfo.rsslChannelInfo.serverToClientPings == RSSL_TRUE ? "true" : "false",
					reactorChannelInfo.rsslChannelInfo.sysSendBufSize, reactorChannelInfo.rsslChannelInfo.sysRecvBufSize,			
					reactorChannelInfo.rsslChannelInfo.compressionType == RSSL_COMP_ZLIB ? "zlib" : "none",
					reactorChannelInfo.rsslChannelInfo.compressionThreshold			
					);

			if (reactorChannelInfo.rsslChannelInfo.componentInfoCount == 0)
				printf("(No component info)");
			else
				for(count = 0; count < reactorChannelInfo.rsslChannelInfo.componentInfoCount; ++count)
				{
					printf("%.*s", 
							reactorChannelInfo.rsslChannelInfo.componentInfo[count]->componentVersion.length,
							reactorChannelInfo.rsslChannelInfo.componentInfo[count]->componentVersion.data);
					if (count < reactorChannelInfo.rsslChannelInfo.componentInfoCount - 1)
						printf(", ");
				}
			printf ("\n\n");

			/* Check that we can successfully pack, if packing messages. */
			if (providerThreadConfig.totalBuffersPerPack > 1
					&& providerThreadConfig.packingBufferLength > reactorChannelInfo.rsslChannelInfo.maxFragmentSize)
			{
				printf("Error(Channel %d): MaxFragmentSize %u is too small for packing buffer size %u\n",
						pReactorChannel->socketId, reactorChannelInfo.rsslChannelInfo.maxFragmentSize, 
						providerThreadConfig.packingBufferLength);
				exit(-1);
			}


			pProvSession->pChannelInfo->pChannel = pReactorChannel->pRsslChannel;
			pProvSession->pChannelInfo->pReactorChannel = pReactorChannel;
			pProvSession->pChannelInfo->pReactor = pReactor;
			rsslQueueAddLinkToBack(&pProviderThread->channelHandler.activeChannelList, &pProvSession->pChannelInfo->queueLink);
			pProvSession->timeActivated = getTimeNano();

			return RSSL_RC_CRET_SUCCESS;
		}
		case RSSL_RC_CET_CHANNEL_READY:
		{
			if (ret = (printEstimatedMsgSizes(pProviderThread, pProvSession)) != RSSL_RET_SUCCESS)
			{
				printf("printEstimatedMsgSizes() failed: %d\n", ret);
				return RSSL_RC_CRET_SUCCESS;
			}

			return RSSL_RC_CRET_SUCCESS;
		}
		case RSSL_RC_CET_FD_CHANGE:
		{
			/* The file descriptor representing the RsslReactorChannel has been changed.
			 * Update our file descriptor sets. */
			printf("Fd change: %d to %d\n", pReactorChannel->oldSocketId, pReactorChannel->socketId);
			FD_CLR(pReactorChannel->oldSocketId, &pProviderThread->readfds);
			FD_CLR(pReactorChannel->oldSocketId, &pProviderThread->exceptfds);
			FD_SET(pReactorChannel->socketId, &pProviderThread->readfds);
			FD_SET(pReactorChannel->socketId, &pProviderThread->exceptfds);

			return RSSL_RC_CRET_SUCCESS;
		}
		case RSSL_RC_CET_WARNING:
		{
			/* We have received a warning event for this channel. Print the information and continue. */
			printf("Received warning for Channel fd=%d.\n", pReactorChannel->socketId);
			printf("	Error text: %s\n", pChannelEvent->pError->rsslError.text);

			return RSSL_RC_CRET_SUCCESS;
		}
		case RSSL_RC_CET_CHANNEL_DOWN:
		{
			pProviderThread->stats.inactiveTime = getTimeNano();

			printf("Channel Closed.\n");

			FD_CLR(pReactorChannel->socketId, &pProviderThread->readfds);
			FD_CLR(pReactorChannel->socketId, &pProviderThread->exceptfds);

			--pProviderThread->clientSessionsCount;
			if (pProvSession->pChannelInfo->pReactorChannel && rsslQueueGetElementCount(&pProviderThread->channelHandler.activeChannelList) > 0)
			{
				rsslQueueRemoveLink(&pProviderThread->channelHandler.activeChannelList, &pProvSession->pChannelInfo->queueLink);
			}
	
			if (pProvSession)
			{
				free(pProvSession->pChannelInfo);
				providerSessionDestroy(pProviderThread, pProvSession);
			}

			if (rsslReactorCloseChannel(pReactor, pReactorChannel, &rsslErrorInfo) != RSSL_RET_SUCCESS)
			{
				printf("rsslReactorCloseChannel() failed: %s\n", rsslErrorInfo.rsslError.text);
				cleanUpAndExit();
			}

			return RSSL_RC_CRET_SUCCESS;
		}
		default:
			printf("Unknown channel event!\n");
			cleanUpAndExit();
	}

	return RSSL_RC_CRET_SUCCESS;
}