| 1 |
|
| /****************************************************************************/
|
| 2 |
|
| /* */
|
| 3 |
|
| /* Program name: MQIsdp protocol C Language implementation */
|
| 4 |
|
| /* */
|
| 5 |
|
| /* Description: This source file contains the send and receive functions to */
|
| 6 |
|
| /* run in the send and receive threads. */
|
| 7 |
|
| /* */
|
| 8 |
|
| /* Statement: Licensed Materials - Property of IBM */
|
| 9 |
|
| /* */
|
| 10 |
|
| /* MQSeries SupportPac IA93 */
|
| 11 |
|
| /* (C) Copyright IBM Corp. 2002 */
|
| 12 |
|
| /* */
|
| 13 |
|
| /****************************************************************************/
|
| 14 |
|
| /* Version @(#) IA93/ship/mspdmn.c, SupportPacs, S000 1.2 03/08/26 16:38:18 */
|
| 15 |
|
| /* */
|
| 16 |
|
| /* Function: */
|
| 17 |
|
| /* */
|
| 18 |
|
| /* The send thread is where the bulk of the processing occurs. The receive */
|
| 19 |
|
| /* thread simply reads messages from the socket and passes them across to */
|
| 20 |
|
| /* the send thread for further processing. */
|
| 21 |
|
| /* */
|
| 22 |
|
| /****************************************************************************/
|
| 23 |
|
| /* */
|
| 24 |
|
| /* Change history: */
|
| 25 |
|
| /* */
|
| 26 |
|
| /* V1.0 19-02-2003 IRH Initial release */
|
| 27 |
|
| /* */
|
| 28 |
|
| /*==========================================================================*/
|
| 29 |
|
| /* Module Name: mspdmn.c */
|
| 30 |
|
| #include <mspdmn.h>
|
| 31 |
|
|
|
| 32 |
|
| /* Global variable controlling the shutdown of all threads behind the API */
|
| 33 |
|
| int mspEnding = 0;
|
| 34 |
|
|
|
| 35 |
|
| int mspWriteDataToSendTask( RCVHCONN rcvHconn, long dataLength, char *pData );
|
| 36 |
|
|
|
| 37 |
|
| /* This is the entry point that the client application must start as a thread / task */
|
| 38 |
|
| /* before calling the API. It starts up mspHandleClientConnection, which contains */
|
| 39 |
|
| /* the main processing logic. */
|
| 40 |
0 |
| DllExport int MQIsdp_SendTask( MQISDPTI *pTaskInfo ) {
|
| 41 |
|
| HCONNCB *pHconn;
|
| 42 |
|
|
|
| 43 |
0 |
| pHconn = mspInitialise( pTaskInfo );
|
| 44 |
|
|
|
| 45 |
0 |
| mspHandleClientConnection( pHconn );
|
| 46 |
|
|
|
| 47 |
0 |
| mspTCPTerm();
|
| 48 |
|
|
|
| 49 |
0 |
| return 0;
|
| 50 |
|
| }
|
| 51 |
|
|
|
| 52 |
|
| /* This is the entry point that the client application must start as a thread / task */
|
| 53 |
|
| /* before calling the API. It reads data from the socket and passes it back to the */
|
| 54 |
|
| /* send task. */
|
| 55 |
|
| /* The receive task can be doing one of two things: */
|
| 56 |
|
| /* Initially it reads its mailbox, waiting to be sent a socket descriptor */
|
| 57 |
|
| /* Once it has a socket descriptor it then waits on that socket for data */
|
| 58 |
|
| /* If the socket becomnes invalid, then it goes back to its mail box to */
|
| 59 |
|
| /* wait for a new socket descriptor */
|
| 60 |
0 |
| DllExport int MQIsdp_ReceiveTask( MQISDPTI *pTaskInfo ) {
|
| 61 |
|
| RCVHCONN rcvHconn;
|
| 62 |
0 |
| long bytesRead = 0;
|
| 63 |
|
| char ec[MSP_EC_LENGTH];
|
| 64 |
|
| int rc;
|
| 65 |
|
|
|
| 66 |
|
| /* Initialise all variables */
|
| 67 |
0 |
| rcvHconn.comParms.memLimit = 0;
|
| 68 |
0 |
| rcvHconn.comParms.mspLogOptions = pTaskInfo->logLevel;
|
| 69 |
|
| #if MSP_DEBUG_MEM > 0
|
| 70 |
|
| rcvHconn.comParms.memMax = 0;
|
| 71 |
|
| rcvHconn.comParms.mc = 0;
|
| 72 |
|
| rcvHconn.comParms.fc = 0;
|
| 73 |
|
| rcvHconn.comParms.memCount = 0;
|
| 74 |
|
| #endif
|
| 75 |
|
|
|
| 76 |
0 |
| rcvHconn.sockfd = MSP_INVALID_SOCKET;
|
| 77 |
|
|
|
| 78 |
0 |
| rcvHconn.ipcCb.sendMailbox = pTaskInfo->sendMailbox;
|
| 79 |
0 |
| rcvHconn.ipcCb.receiveMailbox = pTaskInfo->receiveMailbox;
|
| 80 |
0 |
| rcvHconn.ipcCb.apiMailbox = MSP_NULL_MAILBOX;
|
| 81 |
0 |
| rcvHconn.ipcCb.sendMutex = pTaskInfo->sendMutex;
|
| 82 |
0 |
| rcvHconn.ipcCb.receiveSemaphore = (MSH)MSP_NULL_SEMAPHORE;
|
| 83 |
0 |
| rcvHconn.ipcCb.readTimeout = 5000; /* 5 seconds */
|
| 84 |
0 |
| rcvHconn.ipcCb.options = 0;
|
| 85 |
0 |
| rcvHconn.ipcCb.ipcBufferSz = MSP_DEFAULT_IPC_BUFFER_SZ;
|
| 86 |
0 |
| rcvHconn.ipcCb.pIpcBuffer = mspMalloc( &(rcvHconn.comParms), rcvHconn.ipcCb.ipcBufferSz );
|
| 87 |
0 |
| mspInitialiseIPC( rcvHconn.ipcCb.receiveMailbox, &(rcvHconn.ipcCb) );
|
| 88 |
|
|
|
| 89 |
|
| /* Start the main processing loop */
|
| 90 |
0 |
▶ | while ( mspEnding == 0 ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| while ( mspEnding == 0 ) {
|
0 |
0 |
0 |
|
| 91 |
0 |
▶ | if ( rcvHconn.sockfd != MSP_INVALID_SOCKET ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( rcvHconn.sockfd != MSP_INVALID_SOCKET ) {
|
0 |
0 |
0 |
|
| 92 |
0 |
| mspGetDataFromNetwork( &(rcvHconn.sockfd), &(rcvHconn.comParms),
|
| 93 |
|
| &(rcvHconn.lastError), &bytesRead,
|
| 94 |
|
| &(rcvHconn.ipcCb.ipcBufferSz),
|
| 95 |
|
| &(rcvHconn.ipcCb.pIpcBuffer), 5000 );
|
| 96 |
|
|
|
| 97 |
0 |
▶ | if ( bytesRead > 0 ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( bytesRead > 0 ) {
|
0 |
0 |
0 |
|
| 98 |
0 |
| mspWriteDataToSendTask( rcvHconn, bytesRead, rcvHconn.ipcCb.pIpcBuffer );
|
| 99 |
|
| }
|
| 100 |
|
| } else {
|
| 101 |
|
| /* Block on the mailbox waiting to receive a socket handle */
|
| 102 |
0 |
▶ | if ( mspReadIPC( rcvHconn.ipcCb.receiveMailbox, &(rcvHconn.ipcCb),
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( mspReadIPC( rcvHconn.ipcCb.receiveMailbox, &(rcvHconn.ipcCb),
|
0 |
0 |
0 |
|
| 103 |
|
| &(rcvHconn.comParms), &bytesRead, &(rcvHconn.ipcCb.ipcBufferSz),
|
| 104 |
|
| (void**)&(rcvHconn.ipcCb.pIpcBuffer), ec, &rc, NULL ) == 0 ) {
|
| 105 |
0 |
▶ | if ( memcmp( ec, RCON_S, MSP_EC_LENGTH ) == 0 ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( memcmp( ec, RCON_S, MSP_EC_LENGTH ) == 0 ) {
|
0 |
0 |
0 |
|
| 106 |
|
| /* The socket descriptor was inserted in the rc field */
|
| 107 |
0 |
| rcvHconn.sockfd = rc;
|
| 108 |
|
| }
|
| 109 |
|
| }
|
| 110 |
|
| }
|
| 111 |
|
|
|
| 112 |
|
| }
|
| 113 |
|
|
|
| 114 |
0 |
| mspFree( &(rcvHconn.comParms), rcvHconn.ipcCb.pIpcBuffer, rcvHconn.ipcCb.ipcBufferSz );
|
| 115 |
|
|
|
| 116 |
|
| /* Log the memory allocation. No correction is required because */
|
| 117 |
|
| /* all malloc's were recorded. */
|
| 118 |
0 |
| mspLogMem( &rcvHconn.comParms, "RCV ", 0 );
|
| 119 |
|
|
|
| 120 |
0 |
| return 0;
|
| 121 |
|
| }
|
| 122 |
|
|
|
| 123 |
|
| /* Pass data received by the receive task to the send task for queuing */
|
| 124 |
0 |
| int mspWriteDataToSendTask( RCVHCONN rcvHconn, long dataLength, char *pData ) {
|
| 125 |
0 |
| long bytesRead = 0;
|
| 126 |
|
| char ec[MSP_EC_LENGTH];
|
| 127 |
0 |
| int retCode = 0;
|
| 128 |
0 |
| int rc = 1;
|
| 129 |
|
|
|
| 130 |
|
| /* Obtain the mutex so that we can write to the send task */
|
| 131 |
0 |
▶ | if ( mspLockMutex( rcvHconn.ipcCb.sendMutex ) == 0 ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( mspLockMutex( rcvHconn.ipcCb.sendMutex ) == 0 ) {
|
0 |
0 |
0 |
|
| 132 |
|
|
|
| 133 |
0 |
▶ | if ( mspWriteIPC( rcvHconn.ipcCb.sendMailbox, &(rcvHconn.ipcCb),
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( mspWriteIPC( rcvHconn.ipcCb.sendMailbox, &(rcvHconn.ipcCb),
|
0 |
0 |
0 |
|
| 134 |
|
| RTSK_S, 0, 0, dataLength, pData ) == 0 ) {
|
| 135 |
|
|
|
| 136 |
0 |
| rc = 1;
|
| 137 |
|
| /* If a TCP/IP error occurs then there is a small chance that we may */
|
| 138 |
|
| /* receive a new socket handle instead of the response we expect. */
|
| 139 |
0 |
▶ | while ( rc == 1 ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| while ( rc == 1 ) {
|
0 |
0 |
0 |
|
| 140 |
|
| /* Now wait for a response */
|
| 141 |
0 |
| rc = mspReadIPC( rcvHconn.ipcCb.receiveMailbox, &(rcvHconn.ipcCb),
|
| 142 |
|
| &(rcvHconn.comParms), &bytesRead, &(rcvHconn.ipcCb.ipcBufferSz),
|
| 143 |
|
| (void**)&(rcvHconn.ipcCb.pIpcBuffer), ec, &retCode, NULL );
|
| 144 |
|
|
|
| 145 |
0 |
▶ | if ( memcmp( ec, RTSK_R, MSP_EC_LENGTH ) == 0 ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( memcmp( ec, RTSK_R, MSP_EC_LENGTH ) == 0 ) {
|
0 |
0 |
0 |
|
| 146 |
0 |
| rc = 0;
|
| 147 |
0 |
▶ | } else if ( memcmp( ec, RCON_S, MSP_EC_LENGTH ) == 0 ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| } else if ( memcmp( ec, RCON_S, MSP_EC_LENGTH ) == 0 ) {
|
0 |
0 |
0 |
|
| 148 |
|
| /* The socket descriptor was inserted in the retCode field */
|
| 149 |
0 |
| rcvHconn.sockfd = retCode;
|
| 150 |
|
| }
|
| 151 |
|
| }
|
| 152 |
|
| }
|
| 153 |
|
|
|
| 154 |
0 |
| mspReleaseMutex( rcvHconn.ipcCb.sendMutex );
|
| 155 |
|
| }
|
| 156 |
|
|
|
| 157 |
0 |
| return rc;
|
| 158 |
|
| }
|
| 159 |
|
|
|