/* * Connects to the RSSL server and returns the channel to the caller. * hostname - The hostname of the server to connect to * portno - The port number of the server to connect to * error - The error information in case of failure */ static RsslChannel* connectToRsslServer(RsslConnectionTypes connType, RsslError* error) { RsslChannel* chnl; RsslConnectOptions copts = RSSL_INIT_CONNECT_OPTS; printf("\nAttempting to connect to server %s:%s...\n", srvrHostname, srvrPortNo); copts.connectionInfo.unified.address = srvrHostname; copts.connectionInfo.unified.serviceName = srvrPortNo; copts.connectionInfo.unified.interfaceName = interfaceName; copts.proxyOpts.proxyHostName = proxyHostname; copts.proxyOpts.proxyPort = proxyPort; copts.guaranteedOutputBuffers = 500; copts.connectionType = connType; copts.majorVersion = RSSL_RWF_MAJOR_VERSION; copts.minorVersion = RSSL_RWF_MINOR_VERSION; copts.protocolType = RSSL_RWF_PROTOCOL_TYPE; rsslClearReadOutArgs(&readOutArgs); if ( (chnl = rsslConnect(&copts,error)) != 0) { FD_SET(chnl->socketId,&readfds); FD_SET(chnl->socketId,&exceptfds); if (xmlTrace) { int debugFlags = 0x2C0; RsslTraceOptions traceOptions; rsslClearTraceOptions(&traceOptions); traceOptions.traceMsgFileName = traceOutputFile; traceOptions.traceFlags |= RSSL_TRACE_TO_FILE_ENABLE | RSSL_TRACE_TO_MULTIPLE_FILES | RSSL_TRACE_TO_STDOUT | RSSL_TRACE_READ | RSSL_TRACE_WRITE; traceOptions.traceMsgMaxFileSize = 100000000; rsslIoctl(chnl, (RsslIoctlCodes)RSSL_TRACE, (void *)&traceOptions, error); } printf("\nChannel IPC descriptor = "SOCKET_PRINT_TYPE"\n", chnl->socketId); if (!copts.blocking) { if (!FD_ISSET(chnl->socketId,&wrtfds)) FD_SET(chnl->socketId,&wrtfds); } } return chnl; }
RsslRet snapshotSessionProcessReadReady(SnapshotSession *pSession) { RsslRet readRet; RsslRet ret = RSSL_RET_FAILURE; RsslError rsslError; RsslBuffer *pBuffer; RsslReadInArgs readInArgs; RsslReadOutArgs readOutArgs; switch(pSession->pRsslChannel->state) { case RSSL_CH_STATE_ACTIVE: rsslClearReadInArgs(&readInArgs); rsslClearReadOutArgs(&readOutArgs); pBuffer = rsslReadEx(pSession->pRsslChannel, &readInArgs, &readOutArgs, &readRet, &rsslError); if (pBuffer) { if ((ret = snapshotSessionProcessMessage(pSession, pBuffer)) != RSSL_RET_SUCCESS) return ret; } if (readRet >= RSSL_RET_SUCCESS) return readRet; /* Read values less than RSSL_RET_SUCCESS are codes to handle. */ switch (readRet) { case RSSL_RET_READ_FD_CHANGE: /* Channel's file descriptor was changed. */ printf("<%s> Channel FD changed while reading (from %d to %d).\n\n", pSession->name, pSession->pRsslChannel->oldSocketId, pSession->pRsslChannel->socketId); return RSSL_RET_SUCCESS; case RSSL_RET_READ_PING: /* Received a ping message. */ printf("<%s> Received ping.\n\n", pSession->name); return RSSL_RET_SUCCESS; case RSSL_RET_READ_WOULD_BLOCK: /* Nothing to read. */ return RSSL_RET_SUCCESS; case RSSL_RET_FAILURE: default: /* Channel failed or unhandled code; close the channel. */ printf("<%s> rsslReadEx() failed: %d(%s -- %s).\n\n", pSession->name, readRet, rsslRetCodeToString(readRet), rsslError.text); rsslCloseChannel(pSession->pRsslChannel, &rsslError); pSession->pRsslChannel = NULL; return readRet; } case RSSL_CH_STATE_INITIALIZING: return snapshotSessionInitializeChannel(pSession); default: printf("<%s> Unhandled channel state %u.\n\n", pSession->name, ret, rsslRetCodeToString(ret)); exit(-1); return RSSL_RET_FAILURE; } }