RsslRet snapshotSessionProcessWriteReady(SnapshotSession *pSession) { RsslRet ret = RSSL_RET_FAILURE; RsslError rsslError; switch(pSession->pRsslChannel->state) { case RSSL_CH_STATE_ACTIVE: ret = rsslFlush(pSession->pRsslChannel, &rsslError); /* Read values less than RSSL_RET_SUCCESS are codes to handle. */ if (ret < RSSL_RET_SUCCESS) { /* Flush failed; close the channel. */ printf("<%s> rsslFlush() failed: %d(%s).\n\n", pSession->name, ret, rsslRetCodeToString(ret)); rsslCloseChannel(pSession->pRsslChannel, &rsslError); pSession->pRsslChannel = NULL; return ret; } else if (ret == 0) pSession->setWriteFd = RSSL_FALSE; /* Done flushing. */ return RSSL_RET_SUCCESS; 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; } }
static RsslRet snapshotSessionWrite(SnapshotSession *pSession, RsslBuffer *pBuffer) { RsslError rsslError; RsslRet ret; RsslWriteInArgs writeInArgs; RsslWriteOutArgs writeOutArgs; /* Write the message. */ rsslClearWriteInArgs(&writeInArgs); rsslClearWriteOutArgs(&writeOutArgs); if ((ret = rsslWriteEx(pSession->pRsslChannel, pBuffer, &writeInArgs, &writeOutArgs, &rsslError)) < RSSL_RET_SUCCESS) { printf("<%s> rsslWriteEx() failed: %d(%s -- %s).\n\n", pSession->pRsslChannel, ret, rsslRetCodeToString(ret), rsslError.text); rsslReleaseBuffer(pBuffer, &rsslError); rsslCloseChannel(pSession->pRsslChannel, &rsslError); pSession->pRsslChannel = NULL; return ret; } /* Positive values indicate that data is in the outbound queue and should be flushed. */ if (ret > RSSL_RET_SUCCESS) pSession->setWriteFd = RSSL_TRUE; return RSSL_RET_SUCCESS; }
/* * Removes a channel. * chnl - The channel to be removed */ void removeChannel(RsslChannel* chnl) { RsslError error; RsslRet ret; FD_CLR(chnl->socketId, &readfds); FD_CLR(chnl->socketId, &exceptfds); if (FD_ISSET(chnl->socketId, &wrtfds)) FD_CLR(chnl->socketId, &wrtfds); if ((ret = rsslCloseChannel(chnl, &error)) < RSSL_RET_SUCCESS) { printf("rsslCloseChannel() failed with return code: %d\n", ret); } }
void UPAProvider::ShutdownChannel(RsslChannel * chnl) { RsslError error; RsslRet ret; // clean up the socket fds FD_CLR(chnl->socketId, &readfds_); FD_CLR(chnl->socketId, &exceptfds_); if (FD_ISSET(chnl->socketId, &wrtfds_)) FD_CLR(chnl->socketId, &wrtfds_); // and close the connection if ((ret = rsslCloseChannel(chnl, &error)) < RSSL_RET_SUCCESS) { t42log_warn("rsslCloseChannel() failed with return code: %d ('%s')\n", ret, error.text); } }
/* * Closes channel, cleans up and exits the application. * upaChannel - The channel to be closed * code - if exit due to errors/exceptions */ void closeChannelCleanUpAndExit(RsslChannel* upaChannel, int code) { RsslRet retval = 0; RsslError error; RsslBuffer* msgBuf = 0; /********************************************************* * Client/NIProv Application Liefcycle Major Step 5: * Close connection using rsslCloseChannel (OS connection release handshake) * rsslCloseChannel closes the client based RsslChannel. This will release any pool based resources * back to their respective pools, close the connection, and perform any additional necessary cleanup. * When shutting down the RSSL Transport, the application should release all unwritten pool buffers. * Calling rsslCloseChannel terminates the connection to the ADH. *********************************************************/ if ((retval = rsslCloseChannel(upaChannel, &error)) < RSSL_RET_SUCCESS) { printf("Error %s (%d) (errno: %d) encountered with rsslCloseChannel. Error Text: %s\n", rsslRetCodeToString(error.rsslErrorId), error.rsslErrorId, error.sysError, error.text); } /********************************************************* * Client/NIProv Application Liefcycle Major Step 6: * Uninitialize UPA Transport using rsslUninitialize * The last UPA Transport function that an application should call. This uninitializes internal data * structures and deletes any allocated memory. *********************************************************/ /* All UPA Transport use is complete, must uninitialize. * The uninitialization process allows for any heap allocated memory to be cleaned up properly. */ rsslUninitialize(); /* For applications that do not exit due to errors/exceptions such as: * Exits the application if the run-time has expired. */ if (code == RSSL_RET_SUCCESS) printf("\nUPA NI Provider Training application successfully ended.\n"); /* End application */ exit(code); }
void UPAConsumer::RemoveChannel(RsslChannel* chnl) { // its already been shutdown if(0 == chnl) { return; } RsslError error = { 0, 0, 0, { '\0' } }; RsslRet ret; // tidy up the fds and close the channel FD_CLR(chnl->socketId, &readfds_); FD_CLR(chnl->socketId, &exceptfds_); if (FD_ISSET(chnl->socketId, &wrtfds_)) { FD_CLR(chnl->socketId, &wrtfds_); } if ((ret = rsslCloseChannel(chnl, &error)) < RSSL_RET_SUCCESS) { t42log_error("rsslCloseChannel() failed with return code: %d\n", ret); } }
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; } }
/* * Closes channel, closes server, cleans up and exits the application. * upaChannel - The channel to be closed * upaSrvr - The RsslServer that represents the listening socket connection to the user to be closed * code - if exit due to errors/exceptions */ void closeChannelServerCleanUpAndExit(RsslChannel* upaChannel, RsslServer* upaSrvr, int code) { RsslRet retval = 0; RsslError error; RsslBuffer* msgBuf = 0; /********************************************************* * Server/Provider Application Liefcycle Major Step 6: * Close connection using rsslCloseChannel (OS connection release handshake) * rsslCloseChannel closes the server based RsslChannel. This will release any pool based resources * back to their respective pools, close the connection, and perform any additional necessary cleanup. * When shutting down the UPA Transport, the application should release all unwritten pool buffers. * Calling rsslCloseChannel terminates the connection for each connection client. *********************************************************/ if ((upaChannel) && (retval = rsslCloseChannel(upaChannel, &error) < RSSL_RET_SUCCESS)) { printf("Error %s (%d) (errno: %d) encountered with rsslCloseChannel. Error Text: %s\n", rsslRetCodeToString(error.rsslErrorId), error.rsslErrorId, error.sysError, error.text); } /********************************************************* * Server/Provider Application Liefcycle Major Step 7: * Closes a listening socket associated with an RsslServer. This will release any pool based resources * back to their respective pools, close the listening socket, and perform any additional necessary cleanup. * Any established connections will remain open, allowing for continued information exchange. If desired, * the server can use rsslCloseChannel to shutdown any remaining connections. *********************************************************/ /* clean up server using rsslCloseServer call. * If a server is being shut down, the rsslCloseServer function should be used to close the listening socket and perform * any necessary cleanup. All currently connected RsslChannels will remain open. This allows applications to continue * to send and receive data, while preventing new applications from connecting. The server has the option of calling * rsslCloseChannel to shut down any currently connected applications. * When shutting down the UPA Transport, the application should release any unwritten pool buffers. * The listening socket can be closed by calling rsslCloseServer. This prevents any new connection attempts. * If shutting down connections for all connected clients, the provider should call rsslCloseChannel for each connection client. */ if ((upaSrvr) && (retval = rsslCloseServer(upaSrvr, &error) < RSSL_RET_SUCCESS)) { printf("Error %s (%d) (errno: %d) encountered with rsslCloseServer. Error Text: %s\n", rsslRetCodeToString(error.rsslErrorId), error.rsslErrorId, error.sysError, error.text); } /********************************************************* * Server/Provider Application Liefcycle Major Step 8: * Uninitialize UPA Transport using rsslUninitialize * The last UPA Transport function that an application should call. This uninitializes internal data * structures and deletes any allocated memory. *********************************************************/ /* All UPA Transport use is complete, must uninitialize. * The uninitialization process allows for any heap allocated memory to be cleaned up properly. */ rsslUninitialize(); /* For applications that do not exit due to errors/exceptions such as: * Exits the application if the run-time has expired. */ if (code == RSSL_RET_SUCCESS) printf("\nUPA Interactive Provider Training application successfully ended.\n"); /* End application */ exit(code); }