| 1 |
|
| /****************************************************************************/
|
| 2 |
|
| /* */
|
| 3 |
|
| /* Program name: MQIsdp protocol C Language implementation */
|
| 4 |
|
| /* */
|
| 5 |
|
| /* Description: This source file contains the functions that are used by the*/
|
| 6 |
|
| /* send thread to process data to be sent and as well as data */
|
| 7 |
|
| /* received. */
|
| 8 |
|
| /* */
|
| 9 |
|
| /* Statement: Licensed Materials - Property of IBM */
|
| 10 |
|
| /* */
|
| 11 |
|
| /* MQSeries SupportPac IA93 */
|
| 12 |
|
| /* (C) Copyright IBM Corp. 2002 */
|
| 13 |
|
| /* */
|
| 14 |
|
| /****************************************************************************/
|
| 15 |
|
| /* Version @(#) IA93/ship/msputils.c, SupportPacs, S000 1.4 03/08/26 16:38:36 */
|
| 16 |
|
| /* */
|
| 17 |
|
| /* Function: */
|
| 18 |
|
| /* */
|
| 19 |
|
| /* mspHandleClientConnection is the main function which controls both */
|
| 20 |
|
| /* sending and receiving of data, keeping the MQIsdp connection alive and */
|
| 21 |
|
| /* retrying any failed transmissions. */
|
| 22 |
|
| /* */
|
| 23 |
|
| /****************************************************************************/
|
| 24 |
|
| /* */
|
| 25 |
|
| /* Change history: */
|
| 26 |
|
| /* */
|
| 27 |
|
| /* V1.0 19-02-2003 IRH Initial release */
|
| 28 |
|
| /* 06-06-2003 IRH mspSendRcvPubResponse did not report any errors */
|
| 29 |
|
| /* if the connectin to the broker was broken. */
|
| 30 |
|
| /* */
|
| 31 |
|
| /*==========================================================================*/
|
| 32 |
|
| /* Module Name: msputils.c */
|
| 33 |
|
| #include <mspdmn.h>
|
| 34 |
|
|
|
| 35 |
|
| /* Global flag that controls the shutting down of the send and receive threads */
|
| 36 |
|
| /* Defined in mspdmn.c */
|
| 37 |
|
| extern int mspEnding;
|
| 38 |
|
|
|
| 39 |
|
| int mspInitialiseHconn( HCONNCB *pHconn, long ipcBytesRead, void *ipcrBuffer );
|
| 40 |
|
| int mspSendGetStatusResponse( HCONNCB *pHconn, MQISDPMH hMsg );
|
| 41 |
|
| int mspSendConnStatusResponse( HCONNCB *pHconn, long bytesRead, char *pReadBuffer );
|
| 42 |
|
| int mspSendRcvPubResponse( HCONNCB *pHconn, long bytesRead, char *pReadBuffer );
|
| 43 |
|
| int mspDeletePublication( HCONNCB *pHconn, char *ec, MQISDPMH hMsg );
|
| 44 |
|
| int mspReceiveIPCMessage( HCONNCB *pHconn, char *ec, MQISDPMH hMsg, long bytesRead );
|
| 45 |
|
| int mspResetHconn( HCONNCB * pHconn );
|
| 46 |
|
|
|
| 47 |
|
| /*******************************************************/
|
| 48 |
|
| /* Initialise any resources after the daemon starts up */
|
| 49 |
|
| /*******************************************************/
|
| 50 |
7 |
| HCONNCB *mspInitialise( MQISDPTI *pTaskInfo ) {
|
| 51 |
7 |
| HCONNCB *pHconn = NULL;
|
| 52 |
|
|
|
| 53 |
|
| /* Malloc a connection handle ready to give to the next client connection */
|
| 54 |
7 |
| pHconn = (HCONNCB*)mspMalloc( NULL, sizeof(HCONNCB) );
|
| 55 |
7 |
▶ | if ( pHconn == NULL ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( pHconn == NULL ) {
|
0 |
7 |
7 |
|
| 56 |
0 |
| return NULL;
|
| 57 |
|
| }
|
| 58 |
|
|
|
| 59 |
|
| /* Initialise the TCP/IP stack */
|
| 60 |
7 |
| mspTCPInit();
|
| 61 |
|
|
|
| 62 |
|
| /* Initialise common parms */
|
| 63 |
7 |
| pHconn->comParms.memLimit = 0;
|
| 64 |
7 |
▶ | if ( pTaskInfo ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( pTaskInfo ) {
|
0 |
7 |
7 |
|
| 65 |
0 |
| pHconn->comParms.mspLogOptions = pTaskInfo->logLevel;
|
| 66 |
|
| } else {
|
| 67 |
7 |
| pHconn->comParms.mspLogOptions = LOGNONE; /* -1 to enable all debugging */
|
| 68 |
|
| }
|
| 69 |
|
| #if MSP_DEBUG_MEM > 0
|
| 70 |
|
| pHconn->comParms.memMax = 0;
|
| 71 |
|
| pHconn->comParms.memCount = 0;
|
| 72 |
|
| pHconn->comParms.mc = 0;
|
| 73 |
|
| pHconn->comParms.fc = 0;
|
| 74 |
|
| #endif
|
| 75 |
|
|
|
| 76 |
|
| /* Initialise IPC parameters */
|
| 77 |
7 |
▶ | if ( pTaskInfo != NULL ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( pTaskInfo != NULL ) {
|
0 |
7 |
7 |
|
| 78 |
0 |
| pHconn->ipcCb.apiMailbox = pTaskInfo->apiMailbox;
|
| 79 |
0 |
| pHconn->ipcCb.sendMailbox = pTaskInfo->sendMailbox;
|
| 80 |
0 |
| pHconn->ipcCb.receiveMailbox = pTaskInfo->receiveMailbox;
|
| 81 |
0 |
| pHconn->ipcCb.sendMutex = MSP_NULL_MUTEX;
|
| 82 |
0 |
| pHconn->ipcCb.receiveSemaphore = pTaskInfo->receiveSemaphore;
|
| 83 |
|
| }
|
| 84 |
7 |
| pHconn->ipcCb.readTimeout = 2000;
|
| 85 |
7 |
| pHconn->ipcCb.options = 0;
|
| 86 |
7 |
| pHconn->ipcCb.ipcBufferSz = MSP_DEFAULT_IPC_BUFFER_SZ;
|
| 87 |
7 |
| pHconn->ipcCb.pIpcBuffer = mspMalloc( &(pHconn->comParms), MSP_DEFAULT_IPC_BUFFER_SZ );
|
| 88 |
7 |
| mspInitialiseIPC( pHconn->ipcCb.sendMailbox, &(pHconn->ipcCb) );
|
| 89 |
|
|
|
| 90 |
|
| /* Initialise the input queue */
|
| 91 |
7 |
| pHconn->inQ.rcvdPubsQ = NULL;
|
| 92 |
7 |
| pHconn->inQ.rpHash = mspInitHash( pHconn, MSP_DEFAULT_NUM_HASH_KEYS );
|
| 93 |
7 |
| pHconn->inQ.numBytesQueued = 0;
|
| 94 |
|
|
|
| 95 |
|
| /* Initialise the output queue */
|
| 96 |
7 |
| pHconn->outQ.inProgressQ = NULL;
|
| 97 |
7 |
| pHconn->outQ.ipHash = mspInitHash( pHconn, MSP_DEFAULT_NUM_HASH_KEYS );
|
| 98 |
7 |
| pHconn->outQ.numBytesQueued = 0;
|
| 99 |
|
|
|
| 100 |
|
| /* Initialise the reconnect information */
|
| 101 |
7 |
| pHconn->reconnect.connectMsg = NULL;
|
| 102 |
|
|
|
| 103 |
7 |
| pHconn->apiReturnCode = MQISDP_OK;
|
| 104 |
7 |
| pHconn->connState = MQISDP_DISCONNECTED;
|
| 105 |
7 |
| pHconn->retryCount = 0;
|
| 106 |
7 |
| pHconn->timeForNextPoll = 0;
|
| 107 |
7 |
| pHconn->timeForNextRetry = 0;
|
| 108 |
7 |
| pHconn->ctrlFlags = 0;
|
| 109 |
|
|
|
| 110 |
|
| /* Initialise the persistence interface */
|
| 111 |
7 |
| pHconn->persistFuncs = NULL;
|
| 112 |
|
|
|
| 113 |
|
| /* Initialise the TCP/IP parms */
|
| 114 |
7 |
| pHconn->tcpParms.lastError = 0;
|
| 115 |
7 |
| pHconn->tcpParms.msperrno = 0;
|
| 116 |
7 |
| pHconn->tcpParms.sockfd = MSP_INVALID_SOCKET;
|
| 117 |
|
|
|
| 118 |
|
| /* Call mspResetHconn to initialise the rest of the Hconn */
|
| 119 |
7 |
| mspResetHconn( pHconn );
|
| 120 |
|
|
|
| 121 |
|
| #ifdef MSP_SINGLE_THREAD
|
| 122 |
7 |
| pHconn->tcpParms.sockWaitTime = 0;
|
| 123 |
|
| #endif
|
| 124 |
|
|
|
| 125 |
7 |
| return pHconn;
|
| 126 |
|
| }
|
| 127 |
|
|
|
| 128 |
|
| /* This function contains the main loop for the send thread */
|
| 129 |
|
| /* The function spends most of its time waiting for IPC input, which may come from */
|
| 130 |
|
| /* the API, or from the receive thread. */
|
| 131 |
|
| /* The function manages retrying failed sends, handles TCP/IP connection breakages */
|
| 132 |
|
| /* and queues received data ready for the application to collect */
|
| 133 |
57 |
| int mspHandleClientConnection( HCONNCB *pHconn) {
|
| 134 |
57 |
| long bytesRead = 0;
|
| 135 |
|
| #ifdef MSP_SINGLE_THREAD
|
| 136 |
57 |
| long netBytesRead = 0;
|
| 137 |
|
| #endif
|
| 138 |
|
| char ec[MSP_EC_LENGTH];
|
| 139 |
|
| int retCode;
|
| 140 |
|
| MQISDPMH hMsg;
|
| 141 |
|
| IPQ *curIpqEntry, *nextIpqEntry;
|
| 142 |
|
|
|
| 143 |
|
| #ifndef MSP_SINGLE_THREAD
|
| 144 |
|
| do {
|
| 145 |
|
| #else
|
| 146 |
57 |
| pHconn->tcpParms.sockWaitTime = 0;
|
| 147 |
|
| #endif
|
| 148 |
|
| /* Handle IPC input from client or receive task */
|
| 149 |
|
| /* #########################################################################*/
|
| 150 |
57 |
▶ | if ( mspReadIPC( pHconn->ipcCb.sendMailbox, &(pHconn->ipcCb), &(pHconn->comParms),
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( mspReadIPC( pHconn->ipcCb.sendMailbox, &(pHconn->ipcCb), &(pHconn->comParms),
|
57 |
0 |
57 |
|
| 151 |
|
| &bytesRead, &(pHconn->ipcCb.ipcBufferSz),
|
| 152 |
57 |
| (void**)&(pHconn->ipcCb.pIpcBuffer), ec, &retCode, &hMsg ) == 0 ) {
|
| 153 |
|
|
|
| 154 |
|
| /* Have a look at what type of request the client has sent in */
|
| 155 |
57 |
| mspReceiveIPCMessage( pHconn, ec, hMsg, bytesRead );
|
| 156 |
|
|
|
| 157 |
|
| /* Indicate that data was received */
|
| 158 |
57 |
| bytesRead = 1;
|
| 159 |
|
| }
|
| 160 |
|
| /* #########################################################################*/
|
| 161 |
|
| /* End of handling IPC input from client application */
|
| 162 |
|
|
|
| 163 |
|
| /* If an application is connected then execute the code to service */
|
| 164 |
|
| /* TCP/IP and retry messages, otherwise just service the IPC mailbox */
|
| 165 |
57 |
▶ | if ( pHconn->ctrlFlags & MSP_CLIENT_APP_CONNECTED ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( pHconn->ctrlFlags & MSP_CLIENT_APP_CONNECTED ) {
|
53 |
4 |
57 |
|
| 166 |
|
| /* Handle TCP/IP input from the SCADA broker */
|
| 167 |
|
| /* #########################################################################*/
|
| 168 |
|
| /* Loop getting all available messages from the network */
|
| 169 |
|
| #ifdef MSP_SINGLE_THREAD
|
| 170 |
53 |
| netBytesRead = 1;
|
| 171 |
106 |
▶ | while ( netBytesRead > 0 ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| while ( netBytesRead > 0 ) {
|
53 |
53 |
106 |
|
| 172 |
|
|
|
| 173 |
53 |
▶ | if ( mspGetDataFromNetwork( &(pHconn->tcpParms.sockfd), &(pHconn->comParms),
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( mspGetDataFromNetwork( &(pHconn->tcpParms.sockfd), &(pHconn->comParms),
|
0 |
53 |
53 |
|
| 174 |
|
| &(pHconn->tcpParms.lastError), &netBytesRead,
|
| 175 |
|
| &(pHconn->ipcCb.ipcBufferSz),
|
| 176 |
|
| &(pHconn->ipcCb.pIpcBuffer),
|
| 177 |
53 |
| pHconn->tcpParms.sockWaitTime ) == 2 ) {
|
| 178 |
|
| /* A recv error occurred */
|
| 179 |
0 |
| pHconn->connState = MQISDP_DISCONNECTED;
|
| 180 |
0 |
| netBytesRead = 0;
|
| 181 |
|
| }
|
| 182 |
|
|
|
| 183 |
53 |
▶ | if ( netBytesRead > 0 ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( netBytesRead > 0 ) {
|
0 |
53 |
53 |
|
| 184 |
0 |
| mspReceiveScadaMessage( pHconn, netBytesRead, pHconn->ipcCb.pIpcBuffer );
|
| 185 |
|
| /* If we are single threaded then we can stop waiting */
|
| 186 |
|
| /* only when a publication has been successfully received */
|
| 187 |
0 |
▶ | if ( pHconn->inQ.rtpEntries > 0 ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( pHconn->inQ.rtpEntries > 0 ) {
|
0 |
0 |
0 |
|
| 188 |
0 |
| pHconn->tcpParms.sockWaitTime = 0;
|
| 189 |
|
| }
|
| 190 |
|
| } else
|
| 191 |
|
| #endif
|
| 192 |
|
| /* Do we need to poll the MQIsdp server? */
|
| 193 |
53 |
▶ | if ( (pHconn->connState == MQISDP_CONNECTED) &&
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( (pHconn->connState == MQISDP_CONNECTED) &&
|
0 |
53 |
53 |
|
| 194 |
0 |
▶ | (time( NULL ) >= pHconn->timeForNextPoll) ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| (time( NULL ) >= pHconn->timeForNextPoll) ) {
|
0 |
0 |
0 |
|
| 195 |
|
|
|
| 196 |
|
| /* Poll the server */
|
| 197 |
0 |
▶ | if ( mspSendPingRequest( pHconn ) == 1 ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( mspSendPingRequest( pHconn ) == 1 ) {
|
0 |
0 |
0 |
|
| 198 |
|
| /* Set the time for the next poll if the TCP/IP send failed */
|
| 199 |
|
| /* to stop the broker becoming swamped with ping messages */
|
| 200 |
0 |
| pHconn->timeForNextPoll = time(NULL) + pHconn->keepAliveTime;
|
| 201 |
|
| }
|
| 202 |
|
| }
|
| 203 |
|
| #ifdef MSP_SINGLE_THREAD
|
| 204 |
|
| } /* while (netBytesRead > 0) */
|
| 205 |
|
| #endif
|
| 206 |
|
| /* #########################################################################*/
|
| 207 |
|
| /* End of handling TCP/IP input from the SCADA server */
|
| 208 |
|
|
|
| 209 |
|
| /* If the TCP/IP connection has broken then try to reconnect it. */
|
| 210 |
|
| /* #########################################################################*/
|
| 211 |
|
| /* If we are in a state of not connected and */
|
| 212 |
|
| /* pHconn->timeForNextConnect is zero then we are on our first */
|
| 213 |
|
| /* retry. Otherwise if current time > pHconn->timeForNextConnect */
|
| 214 |
|
| /* then we need to try another connect. */
|
| 215 |
53 |
▶ | if ( (pHconn->connState != MQISDP_CONNECTED) &&
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( (pHconn->connState != MQISDP_CONNECTED) &&
|
53 |
0 |
53 |
|
| 216 |
53 |
▶ | ( (pHconn->reconnect.timeForNextConnect == 0) ||
|
Branch: 1 branch
| Branch | True | False | Total |
| ( (pHconn->reconnect.timeForNextConnect == 0) ||
|
53 |
0 |
53 |
|
| 217 |
53 |
▶ | (time(NULL) >= pHconn->reconnect.timeForNextConnect) ) ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| (time(NULL) >= pHconn->reconnect.timeForNextConnect) ) ) {
|
12 |
41 |
53 |
|
| 218 |
|
|
|
| 219 |
|
| /* If connRetries < 0 then we are running under clean start */
|
| 220 |
|
| /* so the application needs to explicitly reconnect and */
|
| 221 |
|
| /* resubscribe */
|
| 222 |
|
| /* Check we can do the next retry: connRetries + 1 < retryCount */
|
| 223 |
12 |
▶ | if ( ((pHconn->reconnect.connRetries + 1) <= pHconn->retryCount) &&
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( ((pHconn->reconnect.connRetries + 1) <= pHconn->retryCount) &&
|
8 |
4 |
12 |
|
| 224 |
8 |
▶ | (pHconn->reconnect.connRetries >= 0) ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| (pHconn->reconnect.connRetries >= 0) ) {
|
3 |
5 |
8 |
|
| 225 |
|
|
|
| 226 |
3 |
| pHconn->reconnect.connRetries++;
|
| 227 |
3 |
| mspMQIsdpReconnect( pHconn );
|
| 228 |
|
|
|
| 229 |
|
| } else {
|
| 230 |
|
| /* The end of the road.... */
|
| 231 |
|
| /* Attempts to establish a connection have expired. Tell the */
|
| 232 |
|
| /* client application that it needs to reconnect. */
|
| 233 |
9 |
| pHconn->connState = MQISDP_CONNECTION_BROKEN;
|
| 234 |
|
| }
|
| 235 |
12 |
| pHconn->reconnect.timeForNextConnect = time(NULL) + pHconn->retryInterval;
|
| 236 |
|
| }
|
| 237 |
|
| /* #########################################################################*/
|
| 238 |
|
| /* End of TCP/IP reconnect processing. */
|
| 239 |
|
|
|
| 240 |
|
| /* Check to see what data needs retrying */
|
| 241 |
|
| /* #########################################################################*/
|
| 242 |
53 |
▶ | if ( time(NULL) > pHconn->timeForNextRetry ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( time(NULL) > pHconn->timeForNextRetry ) {
|
3 |
50 |
53 |
|
| 243 |
3 |
| curIpqEntry = pHconn->outQ.inProgressQ;
|
| 244 |
3 |
▶ | while ( curIpqEntry != NULL ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| while ( curIpqEntry != NULL ) {
|
0 |
3 |
3 |
|
| 245 |
0 |
| nextIpqEntry = curIpqEntry->Next;
|
| 246 |
0 |
▶ | if ( curIpqEntry->msgStatus == MQISDP_RETRYING ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( curIpqEntry->msgStatus == MQISDP_RETRYING ) {
|
0 |
0 |
0 |
|
| 247 |
0 |
| mspSendScadaMessage( pHconn, curIpqEntry->msgLength, curIpqEntry->msgData,
|
| 248 |
0 |
| curIpqEntry->msgId, 1, 0 );
|
| 249 |
|
| } else {
|
| 250 |
|
| /* If the msgStatus is not retrying then the entry is marked as being */
|
| 251 |
|
| /* available for retry if it is still on the InProgressQ next time around. */
|
| 252 |
|
| /* It is not retried now because it might have only just been sent. */
|
| 253 |
0 |
| curIpqEntry->msgStatus = MQISDP_RETRYING;
|
| 254 |
|
| }
|
| 255 |
|
|
|
| 256 |
0 |
| curIpqEntry = nextIpqEntry;
|
| 257 |
|
| }
|
| 258 |
|
|
|
| 259 |
3 |
| pHconn->timeForNextRetry = time(NULL) + pHconn->retryInterval;
|
| 260 |
|
| }
|
| 261 |
|
| /* #########################################################################*/
|
| 262 |
|
| /* End of checking to see what data needs retrying */
|
| 263 |
|
|
|
| 264 |
|
| } /* if (pHconn->ctrlFlags & MSP_CLIENT_APP_CONNECTED) */
|
| 265 |
|
|
|
| 266 |
|
| #ifndef MSP_SINGLE_THREAD
|
| 267 |
|
| } while ( mspEnding == 0 );
|
| 268 |
|
| #else
|
| 269 |
|
| /* If there is an application waiting to receive data then send a response */
|
| 270 |
57 |
▶ | if ( strncmp( ec, RCV_S, MSP_EC_LENGTH ) == 0 ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( strncmp( ec, RCV_S, MSP_EC_LENGTH ) == 0 ) {
|
0 |
57 |
57 |
|
| 271 |
0 |
| mspSendRcvPubResponse( pHconn, bytesRead, pHconn->ipcCb.pIpcBuffer );
|
| 272 |
|
| }
|
| 273 |
|
|
|
| 274 |
|
| /* If a client has disconnected then clean up */
|
| 275 |
57 |
▶ | if ( !(pHconn->ctrlFlags & MSP_CLIENT_APP_CONNECTED) ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( !(pHconn->ctrlFlags & MSP_CLIENT_APP_CONNECTED) ) {
|
4 |
53 |
57 |
|
| 276 |
|
| #endif
|
| 277 |
|
|
|
| 278 |
|
| /* Remove the received publications hash table */
|
| 279 |
4 |
| mspTermHash( pHconn, pHconn->inQ.rpHash );
|
| 280 |
|
|
|
| 281 |
|
| /* Remove the In Progress Messages hash table */
|
| 282 |
4 |
| mspTermHash( pHconn, pHconn->outQ.ipHash );
|
| 283 |
|
|
|
| 284 |
4 |
| mspFree( &pHconn->comParms, pHconn->ipcCb.pIpcBuffer, pHconn->ipcCb.ipcBufferSz );
|
| 285 |
|
|
|
| 286 |
|
| /* Log the memory allocation. Add a correction of the size of the connection */
|
| 287 |
|
| /* handle because that was on the heap, but not counted because the */
|
| 288 |
|
| /* structure was malloc'ed before stats were recorded. */
|
| 289 |
4 |
| mspLogMem( &(pHconn->comParms), "SEND", sizeof(HCONNCB) );
|
| 290 |
|
|
|
| 291 |
4 |
| mspFree( NULL, pHconn, sizeof(HCONNCB) );
|
| 292 |
|
|
|
| 293 |
|
| #ifdef MSP_SINGLE_THREAD
|
| 294 |
|
| } /* if ( !(ctrlFlags & MSP_CLIENT_APP_CONNECTED) ) { */
|
| 295 |
|
| #endif
|
| 296 |
|
|
|
| 297 |
57 |
| return 0;
|
| 298 |
|
| }
|
| 299 |
|
|
|
| 300 |
|
| /* The send thread uses this function to process the IPC data received. */
|
| 301 |
|
| /* Data may come from the API (in mspclnt.c), or from the receive task */
|
| 302 |
|
| /* (in mspdmn.c). */
|
| 303 |
57 |
| int mspReceiveIPCMessage( HCONNCB *pHconn, char *ec, MQISDPMH hMsg,
|
| 304 |
|
| long bytesRead ) {
|
| 305 |
|
| long mspsBufSize;
|
| 306 |
57 |
| void *mspsMsg = NULL;
|
| 307 |
57 |
| int rc = 0;
|
| 308 |
|
|
|
| 309 |
57 |
| switch ( ec[0] ) {
|
| 310 |
0 |
| case 'A': /* Receive publication acknowledgement from the API */
|
| 311 |
0 |
| mspDeletePublication( pHconn, ec, hMsg );
|
| 312 |
0 |
▶ | if ( pHconn->inQ.rtpEntries > 0 ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( pHconn->inQ.rtpEntries > 0 ) {
|
0 |
0 |
0 |
|
| 313 |
|
| /* If there are publications available to receive */
|
| 314 |
|
| /* then signal the receive semaphore. */
|
| 315 |
0 |
| mspSignalSemaphore( pHconn->ipcCb.receiveSemaphore );
|
| 316 |
|
| }
|
| 317 |
0 |
| break;
|
| 318 |
7 |
| case 'C': /* Connect message from the API */
|
| 319 |
7 |
▶ | if ( pHconn->ctrlFlags & MSP_CLIENT_APP_CONNECTED ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( pHconn->ctrlFlags & MSP_CLIENT_APP_CONNECTED ) {
|
0 |
7 |
7 |
|
| 320 |
0 |
| pHconn->apiReturnCode = MQISDP_ALREADY_CONNECTED;
|
| 321 |
|
| } else {
|
| 322 |
7 |
| pHconn->ctrlFlags |= MSP_CLIENT_APP_CONNECTED;
|
| 323 |
7 |
| pHconn->apiReturnCode = MQISDP_OK;
|
| 324 |
|
|
|
| 325 |
7 |
| mspsMsg = mspBuildScadaConnectMsg( pHconn, bytesRead,
|
| 326 |
7 |
| pHconn->ipcCb.pIpcBuffer, &mspsBufSize );
|
| 327 |
|
|
|
| 328 |
7 |
▶ | if ( mspsMsg != NULL ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( mspsMsg != NULL ) {
|
7 |
0 |
7 |
|
| 329 |
7 |
▶ | if ( mspInitialiseHconn( pHconn, bytesRead, pHconn->ipcCb.pIpcBuffer ) == 0 ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( mspInitialiseHconn( pHconn, bytesRead, pHconn->ipcCb.pIpcBuffer ) == 0 ) {
|
5 |
2 |
7 |
|
| 330 |
5 |
| mspTCPInitialise( pHconn );
|
| 331 |
5 |
| mspSendScadaMessage( pHconn, mspsBufSize, mspsMsg, 0, 0, 0 );
|
| 332 |
5 |
▶ | MSP_SET_NEXT_MSGID( pHconn->nextMsgId );
|
Branch: 1 branch
| Branch | True | False | Total |
| MSP_SET_NEXT_MSGID( pHconn->nextMsgId );
|
5 |
0 |
5 |
|
| 333 |
|
| }
|
| 334 |
|
| } else {
|
| 335 |
|
| /* The connect has failed */
|
| 336 |
0 |
| pHconn->ctrlFlags &= MSP_CLIENT_APP_DISCONNECTED;
|
| 337 |
|
| }
|
| 338 |
|
|
|
| 339 |
7 |
| mspWriteIPC( pHconn->ipcCb.apiMailbox, &(pHconn->ipcCb), ec,
|
| 340 |
7 |
| pHconn->apiReturnCode, 0, 0, NULL );
|
| 341 |
|
| }
|
| 342 |
7 |
| break;
|
| 343 |
4 |
| case 'D': /* Disconnect message from the API */
|
| 344 |
4 |
| mspsMsg = mspBuildScadaDisconnectMsg( pHconn, bytesRead,
|
| 345 |
4 |
| pHconn->ipcCb.pIpcBuffer, &mspsBufSize );
|
| 346 |
4 |
▶ | if ( mspsMsg != NULL ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( mspsMsg != NULL ) {
|
4 |
0 |
4 |
|
| 347 |
4 |
| mspSendScadaMessage( pHconn, mspsBufSize, mspsMsg, 0, 0, 0 );
|
| 348 |
|
| }
|
| 349 |
4 |
| pHconn->ctrlFlags &= MSP_CLIENT_APP_DISCONNECTED;
|
| 350 |
4 |
| mspResetHconn( pHconn );
|
| 351 |
4 |
| mspWriteIPC( pHconn->ipcCb.apiMailbox, &(pHconn->ipcCb), ec, MQISDP_OK, 0, 0, NULL );
|
| 352 |
4 |
| break;
|
| 353 |
0 |
| case 'E': /* Receive publication decline from the API - The application buffer was not large */
|
| 354 |
|
| /* enough to receive the data. Signal the next waiter that a message is still available */
|
| 355 |
0 |
▶ | if ( pHconn->inQ.rtpEntries > 0 ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( pHconn->inQ.rtpEntries > 0 ) {
|
0 |
0 |
0 |
|
| 356 |
|
| /* If there are publications available to receive */
|
| 357 |
|
| /* then signal the receive semaphore. */
|
| 358 |
0 |
| mspSignalSemaphore( pHconn->ipcCb.receiveSemaphore );
|
| 359 |
|
| }
|
| 360 |
0 |
| mspWriteIPC( pHconn->ipcCb.apiMailbox, &(pHconn->ipcCb), RCV_B, MQISDP_OK, 0, 0, NULL );
|
| 361 |
0 |
| break;
|
| 362 |
3 |
| case 'P': /* Publish message from the API */
|
| 363 |
|
| case 'S': /* Subscribe message from the API */
|
| 364 |
|
| case 'U': /* Unsubscribe message from the API */
|
| 365 |
3 |
▶ | if ( pHconn->connState == MQISDP_CONNECTION_BROKEN ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( pHconn->connState == MQISDP_CONNECTION_BROKEN ) {
|
0 |
3 |
3 |
|
| 366 |
0 |
| mspWriteIPC( pHconn->ipcCb.apiMailbox, &(pHconn->ipcCb), ec,
|
| 367 |
|
| MQISDP_CONNECTION_BROKEN, 0, 0, NULL );
|
| 368 |
|
| } else {
|
| 369 |
3 |
| pHconn->apiReturnCode = MQISDP_OK;
|
| 370 |
3 |
| switch( ec[0] ) {
|
| 371 |
3 |
| case 'P':
|
| 372 |
3 |
| mspsMsg = mspBuildScadaPublishMsg( pHconn, bytesRead,
|
| 373 |
3 |
| pHconn->ipcCb.pIpcBuffer, &mspsBufSize );
|
| 374 |
3 |
| break;
|
| 375 |
0 |
| case 'S':
|
| 376 |
0 |
| mspsMsg = mspBuildScadaSubscribeMsg( pHconn, bytesRead,
|
| 377 |
0 |
| pHconn->ipcCb.pIpcBuffer, &mspsBufSize );
|
| 378 |
0 |
| break;
|
| 379 |
0 |
| case 'U':
|
| 380 |
0 |
| mspsMsg = mspBuildScadaUnsubscribeMsg( pHconn, bytesRead,
|
| 381 |
0 |
| pHconn->ipcCb.pIpcBuffer, &mspsBufSize );
|
| 382 |
|
| }
|
| 383 |
|
|
|
| 384 |
3 |
▶ | if ( mspsMsg != NULL ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( mspsMsg != NULL ) {
|
2 |
1 |
3 |
|
| 385 |
2 |
| rc = mspSendScadaMessage( pHconn, mspsBufSize, mspsMsg, pHconn->nextMsgId, 0, 0 );
|
| 386 |
|
| /* 0 or 1 are ok as return codes, anything higher is an error */
|
| 387 |
2 |
▶ | if ( rc > 1 ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( rc > 1 ) {
|
0 |
2 |
2 |
|
| 388 |
0 |
| pHconn->apiReturnCode = rc;
|
| 389 |
|
| }
|
| 390 |
|
| }
|
| 391 |
|
|
|
| 392 |
3 |
| mspWriteIPC( pHconn->ipcCb.apiMailbox, &(pHconn->ipcCb), ec,
|
| 393 |
3 |
| pHconn->apiReturnCode, pHconn->nextMsgId, 0, NULL );
|
| 394 |
|
|
|
| 395 |
3 |
▶ | MSP_SET_NEXT_MSGID( pHconn->nextMsgId );
|
Branch: 1 branch
| Branch | True | False | Total |
| MSP_SET_NEXT_MSGID( pHconn->nextMsgId );
|
3 |
0 |
3 |
|
| 396 |
|
| }
|
| 397 |
3 |
| break;
|
| 398 |
0 |
| case 'M': /* Get message status from the API */
|
| 399 |
0 |
| mspSendGetStatusResponse( pHconn, hMsg );
|
| 400 |
0 |
| break;
|
| 401 |
0 |
| case 'R': /* Receive a publication message from the API */
|
| 402 |
|
| #ifdef MSP_SINGLE_THREAD
|
| 403 |
|
| /* The requested time to wait is in the IPC buffer */
|
| 404 |
|
| /* Wait for at most 50% of the keepalive time. */
|
| 405 |
|
| /* Keepalive time is in seconds - convert to milliseconds */
|
| 406 |
|
| /* (*1000) and divide by 2, or just multiply by 500 */
|
| 407 |
|
| /* If there is already a publication available, then don't wait */
|
| 408 |
0 |
▶ | if ( pHconn->inQ.rtpEntries > 0 ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( pHconn->inQ.rtpEntries > 0 ) {
|
0 |
0 |
0 |
|
| 409 |
0 |
| pHconn->tcpParms.sockWaitTime = 0;
|
| 410 |
|
| } else {
|
| 411 |
|
| int waitTime;
|
| 412 |
0 |
| memcpy( &waitTime, pHconn->ipcCb.pIpcBuffer, sizeof(int) );
|
| 413 |
0 |
| pHconn->tcpParms.sockWaitTime = MIN( (int)(pHconn->keepAliveTime*500), waitTime );
|
| 414 |
|
| }
|
| 415 |
|
| #else
|
| 416 |
|
| mspSendRcvPubResponse( pHconn, bytesRead, pHconn->ipcCb.pIpcBuffer );
|
| 417 |
|
| #endif
|
| 418 |
0 |
| break;
|
| 419 |
43 |
| case 'T': /* Get the connection status message from the API */
|
| 420 |
43 |
| mspSendConnStatusResponse( pHconn, bytesRead, pHconn->ipcCb.pIpcBuffer );
|
| 421 |
43 |
| break;
|
| 422 |
|
| #ifndef MSP_SINGLE_THREAD
|
| 423 |
|
| case 'K': /* Receive data from the receive task and send an IPC response */
|
| 424 |
|
| /* For a single task solution the TCP/IP socket is polled for input */
|
| 425 |
|
| /* further down this function */
|
| 426 |
|
| mspReceiveScadaMessage( pHconn, bytesRead, pHconn->ipcCb.pIpcBuffer );
|
| 427 |
|
| mspWriteIPC( pHconn->ipcCb.receiveMailbox, &(pHconn->ipcCb), RTSK_R, MQISDP_OK, 0, 0, NULL );
|
| 428 |
|
| break;
|
| 429 |
|
| #endif
|
| 430 |
0 |
| default:
|
| 431 |
0 |
| mspLog( LOGERROR, &(pHconn->comParms), "Unrecognised IPC eye catcher:%.2s\n", ec );
|
| 432 |
0 |
| break;
|
| 433 |
|
| }
|
| 434 |
|
|
|
| 435 |
57 |
| return 0;
|
| 436 |
|
| }
|
| 437 |
|
| /* mspGetDataFromNetwork: Returns 0 if data was received */
|
| 438 |
|
| /* Returns 2 on error, 1 if no data available, otherwise 0 */
|
| 439 |
53 |
| int mspGetDataFromNetwork( int *pSockfd, MSPCMN *pComParms, int *pLastError,
|
| 440 |
|
| long *pBytesRead, long *rBufSize, char **rBuffer,
|
| 441 |
|
| long msTimeout ) {
|
| 442 |
53 |
| int rc = 1;
|
| 443 |
|
|
|
| 444 |
53 |
| *pBytesRead = 0;
|
| 445 |
|
|
|
| 446 |
|
| /* Poll the socket to check for input data */
|
| 447 |
53 |
▶ | if ( msp_select( *pSockfd, msTimeout ) > 0 ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( msp_select( *pSockfd, msTimeout ) > 0 ) {
|
0 |
53 |
53 |
|
| 448 |
0 |
▶ | if ( mspTCPReadMsg( *pSockfd, pComParms, pLastError, pBytesRead,
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( mspTCPReadMsg( *pSockfd, pComParms, pLastError, pBytesRead,
|
0 |
0 |
0 |
|
| 449 |
|
| rBufSize, rBuffer) < 0 ) {
|
| 450 |
0 |
| mspTCPDisconnect( pSockfd );
|
| 451 |
0 |
| rc = 2;
|
| 452 |
|
| } else {
|
| 453 |
0 |
| rc = 0;
|
| 454 |
|
| }
|
| 455 |
|
| }
|
| 456 |
|
|
|
| 457 |
53 |
| return rc;
|
| 458 |
|
| }
|
| 459 |
|
|
|
| 460 |
|
| /* Initialise the connection handle when a new connection is created */
|
| 461 |
7 |
| int mspInitialiseHconn( HCONNCB *pHconn, long ipcBytesRead, void *ipcrBuffer ) {
|
| 462 |
|
| CONN_PARMS *pMspCp; /* User input connection parameters */
|
| 463 |
7 |
| int rc = 0; /* The function return code */
|
| 464 |
7 |
| int i = 0; /* Loop counter used when loading messages from the persistence */
|
| 465 |
|
| char *pResAddr; /* DNS resolved IP address */
|
| 466 |
|
| int numMsgs; /* Number of messages retrieved from the persistence */
|
| 467 |
|
| MQISDP_PMSG *pPersistMsgs;/* Pointer to messages returned from the persistence */
|
| 468 |
|
| u_short wmqttMsgId; /* WMQTT message identifier */
|
| 469 |
|
| RPQ *pRcvdEntry; /* Received queue entry */
|
| 470 |
|
|
|
| 471 |
7 |
| pMspCp = (CONN_PARMS*)ipcrBuffer;
|
| 472 |
|
|
|
| 473 |
|
| /* Set up parameters for keeping the connection alive */
|
| 474 |
7 |
| pHconn->keepAliveTime = pMspCp->keepAliveTime;
|
| 475 |
7 |
| pHconn->timeForNextPoll = time(NULL) + pHconn->keepAliveTime;
|
| 476 |
7 |
| pHconn->retryCount = pMspCp->retryCount;
|
| 477 |
7 |
| pHconn->retryInterval = pMspCp->retryInterval;
|
| 478 |
7 |
| pHconn->timeForNextRetry = time(NULL) + pHconn->retryInterval;
|
| 479 |
|
|
|
| 480 |
|
| /* Set a time limit for the connect to complete */
|
| 481 |
7 |
| pHconn->reconnect.timeForNextConnect = time(NULL) + pHconn->retryInterval;
|
| 482 |
|
|
|
| 483 |
|
| /* Set the persistence interface as requested by the connecting application */
|
| 484 |
7 |
| pHconn->persistFuncs = pMspCp->pPersistFuncs;
|
| 485 |
|
|
|
| 486 |
|
| /* We haven't completed the MQIsdp connect yet */
|
| 487 |
7 |
| pHconn->connState = MQISDP_CONNECTING;
|
| 488 |
|
|
|
| 489 |
7 |
| pResAddr = mspTCPGetHostByName( pHconn, pMspCp->brokerHostname );
|
| 490 |
7 |
▶ | if ( pResAddr != NULL ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( pResAddr != NULL ) {
|
6 |
1 |
7 |
|
| 491 |
6 |
| mspLog( LOGTCPIP, &(pHconn->comParms), "DNS resolved %s -> %s\n", pMspCp->brokerHostname, pResAddr );
|
| 492 |
6 |
| memcpy( pHconn->tcpParms.brokerAddress, pResAddr, MQISDP_INET_ADDR_LENGTH );
|
| 493 |
6 |
| pHconn->tcpParms.brokerPort = (u_short)pMspCp->brokerPort;
|
| 494 |
|
|
|
| 495 |
|
| /* Now initialise the persistence */
|
| 496 |
6 |
▶ | if ( pHconn->persistFuncs != NULL ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( pHconn->persistFuncs != NULL ) {
|
4 |
2 |
6 |
|
| 497 |
4 |
| rc = pHconn->persistFuncs->open( pHconn->persistFuncs->pUserData, pMspCp->clientId,
|
| 498 |
4 |
| pHconn->tcpParms.brokerAddress,
|
| 499 |
4 |
| pHconn->tcpParms.brokerPort );
|
| 500 |
4 |
▶ | if ( rc == 0 ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( rc == 0 ) {
|
4 |
0 |
4 |
|
| 501 |
4 |
▶ | if ( pHconn->ctrlFlags & MSP_CLEAN_SESSION ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( pHconn->ctrlFlags & MSP_CLEAN_SESSION ) {
|
1 |
3 |
4 |
|
| 502 |
|
| /* Using clean session, so reset the state of the persistence */
|
| 503 |
1 |
| rc = pHconn->persistFuncs->reset( pHconn->persistFuncs->pUserData );
|
| 504 |
|
| } else {
|
| 505 |
|
| /* Not using clean session, so load in the previous state from the persistence */
|
| 506 |
3 |
▶ | if ( rc == 0 ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( rc == 0 ) {
|
3 |
0 |
3 |
|
| 507 |
3 |
| rc = pHconn->persistFuncs->getAllSentMessages( pHconn->persistFuncs->pUserData,
|
| 508 |
|
| &numMsgs, &pPersistMsgs );
|
| 509 |
3 |
▶ | if ( (rc == 0) && (numMsgs > 0) ) {
|
Branch: 2 branches
| Branch | True | False | Total |
| if ( (rc == 0) && (numMsgs > 0) ) {
|
3 |
0 |
3 |
| if ( (rc == 0) && (numMsgs > 0) ) {
|
3 |
0 |
3 |
|
| 510 |
|
| /* There is no TCP/IP connection at this stage, so mspSendScadaMessage */
|
| 511 |
|
| /* will simply queue the data up in memory, initialising the memory */
|
| 512 |
|
| /* state back to what it was prior to the application last disconnecting */
|
| 513 |
|
| /* The initFlag is set to stop the data being written back to the */
|
| 514 |
|
| /* persistence. */
|
| 515 |
12 |
▶ | for ( i=0; i < numMsgs; i++ ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| for ( i=0; i < numMsgs; i++ ) {
|
9 |
3 |
12 |
|
| 516 |
9 |
▶ | if ( pPersistMsgs[i].key > pHconn->nextMsgId ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( pPersistMsgs[i].key > pHconn->nextMsgId ) {
|
9 |
0 |
9 |
|
| 517 |
|
| /* Conversion from u_long to u_short is ok as a key greater */
|
| 518 |
|
| /* than can be accomodated by u_short is never used. */
|
| 519 |
9 |
| pHconn->nextMsgId = (u_short)pPersistMsgs[i].key;
|
| 520 |
|
| }
|
| 521 |
9 |
| mspSendScadaMessage( pHconn,
|
| 522 |
9 |
| pPersistMsgs[i].length,
|
| 523 |
9 |
| pPersistMsgs[i].pWmqttMsg,
|
| 524 |
9 |
| (short)pPersistMsgs[i].key, 0, 1 );
|
| 525 |
|
| }
|
| 526 |
|
| }
|
| 527 |
|
| }
|
| 528 |
3 |
▶ | if ( rc == 0 ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( rc == 0 ) {
|
3 |
0 |
3 |
|
| 529 |
3 |
| rc = pHconn->persistFuncs->getAllReceivedMessages( pHconn->persistFuncs->pUserData,
|
| 530 |
|
| &numMsgs, &pPersistMsgs );
|
| 531 |
3 |
▶ | if ( (rc == 0) && (numMsgs > 0) ) {
|
Branch: 2 branches
| Branch | True | False | Total |
| if ( (rc == 0) && (numMsgs > 0) ) {
|
3 |
0 |
3 |
| if ( (rc == 0) && (numMsgs > 0) ) {
|
1 |
2 |
3 |
|
| 532 |
|
| /* The messages were stored in the MQIsdp wire format, so the */
|
| 533 |
|
| /* mspStorePublication function can be used to reload memory */
|
| 534 |
|
| /* as though the messages had just been received from TCP/IP. */
|
| 535 |
4 |
▶ | for ( i=0; i < numMsgs; i++ ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| for ( i=0; i < numMsgs; i++ ) {
|
3 |
1 |
4 |
|
| 536 |
3 |
▶ | if ( pPersistMsgs[i].key > pHconn->nextRcvId ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( pPersistMsgs[i].key > pHconn->nextRcvId ) {
|
3 |
0 |
3 |
|
| 537 |
3 |
| pHconn->nextRcvId = pPersistMsgs[i].key;
|
| 538 |
|
| }
|
| 539 |
3 |
| pRcvdEntry = mspStorePublication( pHconn,
|
| 540 |
3 |
| pPersistMsgs[i].length,
|
| 541 |
3 |
| pPersistMsgs[i].pWmqttMsg,
|
| 542 |
|
| &wmqttMsgId );
|
| 543 |
3 |
▶ | if ( pRcvdEntry != NULL ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( pRcvdEntry != NULL ) {
|
0 |
3 |
3 |
|
| 544 |
0 |
| pRcvdEntry->rcvId = pPersistMsgs[i].key;
|
| 545 |
|
| } else {
|
| 546 |
3 |
| rc = 1;
|
| 547 |
|
| }
|
| 548 |
|
|
|
| 549 |
|
| }
|
| 550 |
|
| }
|
| 551 |
|
| }
|
| 552 |
|
| }
|
| 553 |
|
| }
|
| 554 |
4 |
▶ | if ( rc != 0 ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( rc != 0 ) {
|
1 |
3 |
4 |
|
| 555 |
1 |
| pHconn->apiReturnCode = MQISDP_PERSISTENCE_FAILED;
|
| 556 |
|
| }
|
| 557 |
|
| }
|
| 558 |
|
|
|
| 559 |
|
| } else {
|
| 560 |
1 |
| pHconn->apiReturnCode = MQISDP_HOSTNAME_NOT_FOUND;
|
| 561 |
1 |
| rc = 1;
|
| 562 |
|
| }
|
| 563 |
|
|
|
| 564 |
7 |
| return rc;
|
| 565 |
|
| }
|
| 566 |
|
|
|
| 567 |
|
| /* A funtion to return the status of a message to the API */
|
| 568 |
0 |
| int mspSendGetStatusResponse( HCONNCB *pHconn, MQISDPMH hMsg ) {
|
| 569 |
0 |
| int rc = MQISDP_IN_PROGRESS;
|
| 570 |
|
| MHASHENTRY *pHashEntry;
|
| 571 |
|
|
|
| 572 |
0 |
▶ | if ( (hMsg > 0) && (hMsg <= MQISDP_MAX_MSGS) ) {
|
Branch: 2 branches
| Branch | True | False | Total |
| if ( (hMsg > 0) && (hMsg <= MQISDP_MAX_MSGS) ) {
|
0 |
0 |
0 |
| if ( (hMsg > 0) && (hMsg <= MQISDP_MAX_MSGS) ) {
|
0 |
0 |
0 |
|
| 573 |
0 |
| pHashEntry = mspGetHashEntry( pHconn->outQ.ipHash, (short)hMsg );
|
| 574 |
|
| /* Get the hash table entry for this message id. */
|
| 575 |
|
| /* If the Hash entry is NULL then the message was delivered. */
|
| 576 |
|
| /* If it is not NULL then the message is any data waiting to be sent */
|
| 577 |
0 |
▶ | if ( pHashEntry == NULL ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( pHashEntry == NULL ) {
|
0 |
0 |
0 |
|
| 578 |
0 |
| rc = MQISDP_DELIVERED;
|
| 579 |
|
| } else {
|
| 580 |
0 |
| rc = ((IPQ*)pHashEntry->dataPtr)->msgStatus;
|
| 581 |
|
| }
|
| 582 |
|
| } else {
|
| 583 |
0 |
| rc = MQISDP_MSG_HANDLE_ERROR;
|
| 584 |
|
| }
|
| 585 |
|
|
|
| 586 |
0 |
| mspWriteIPC( pHconn->ipcCb.apiMailbox, &(pHconn->ipcCb), MSG_R, rc, hMsg, 0, NULL );
|
| 587 |
|
|
|
| 588 |
0 |
| return 0;
|
| 589 |
|
| }
|
| 590 |
|
|
|
| 591 |
|
| /* Send the connection status back to the API */
|
| 592 |
|
| /* Buffer written to IPC holds: */
|
| 593 |
|
| /* errorCode (long) */
|
| 594 |
|
| /* error string length (long) */
|
| 595 |
|
| /* error string MQISDP_ERROR_STRING_LENGTH */
|
| 596 |
43 |
| int mspSendConnStatusResponse( HCONNCB *pHconn, long bytesRead, char *pReadBuffer ) {
|
| 597 |
|
| char *pData;
|
| 598 |
43 |
| char *pErrStr = NULL;
|
| 599 |
|
| long dataLength;
|
| 600 |
|
| long lastError;
|
| 601 |
|
|
|
| 602 |
43 |
| pData = pHconn->ipcCb.pIpcBuffer;
|
| 603 |
43 |
| dataLength = sizeof(long);
|
| 604 |
|
|
|
| 605 |
|
| /* Copy an error code */
|
| 606 |
43 |
▶ | if ( pHconn->tcpParms.sockfd == MSP_INVALID_SOCKET ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( pHconn->tcpParms.sockfd == MSP_INVALID_SOCKET ) {
|
43 |
0 |
43 |
|
| 607 |
43 |
| lastError = pHconn->tcpParms.lastError & MSP_GET_LAST_ERROR;
|
| 608 |
43 |
| memcpy( pData, &lastError, sizeof(long) );
|
| 609 |
|
| } else {
|
| 610 |
0 |
| memset( pData, 0, sizeof(long) );
|
| 611 |
|
| }
|
| 612 |
43 |
| pData += sizeof(long);
|
| 613 |
|
|
|
| 614 |
|
| /* Insert a NULL after the error code field to initialise the error string field */
|
| 615 |
43 |
| pErrStr = pData;
|
| 616 |
43 |
| *pErrStr = '\0';
|
| 617 |
|
|
|
| 618 |
|
| /* Copy any relevant info string data */
|
| 619 |
43 |
| switch ( pHconn->tcpParms.lastError & MSP_GET_ERROR_TYPE ) {
|
| 620 |
0 |
| case 0:
|
| 621 |
0 |
| sprintf( pData, MSP_TCP_CONN_SUC_STR, pHconn->tcpParms.brokerAddress,
|
| 622 |
0 |
| (long)pHconn->tcpParms.brokerPort );
|
| 623 |
0 |
| break;
|
| 624 |
0 |
| case MSP_CONN_ERROR:
|
| 625 |
0 |
| switch ( pHconn->tcpParms.lastError & MSP_GET_LAST_ERROR ) {
|
| 626 |
0 |
| case MQISDP_SOCKET_CLOSED:
|
| 627 |
0 |
| strcpy( pData, MSP_SOCK_CLOSED_ERR_STR );
|
| 628 |
0 |
| break;
|
| 629 |
0 |
| case MQISDP_PROTOCOL_VERSION_ERROR:
|
| 630 |
0 |
| strcpy( pData, MSP_MQISDP_VERS_ERR_STR );
|
| 631 |
0 |
| break;
|
| 632 |
0 |
| case MQISDP_CLIENT_ID_ERROR:
|
| 633 |
0 |
| strcpy( pData, MSP_MQISDP_CLID_ERR_STR );
|
| 634 |
0 |
| break;
|
| 635 |
0 |
| case MQISDP_BROKER_UNAVAILABLE:
|
| 636 |
0 |
| strcpy( pData, MSP_MQISDP_CREF_ERR_STR );
|
| 637 |
0 |
| break;
|
| 638 |
0 |
| case MQISDP_HOSTNAME_NOT_FOUND:
|
| 639 |
0 |
| strcpy( pData, MSP_MQISDP_HOST_ERR_STR );
|
| 640 |
0 |
| break;
|
| 641 |
0 |
| default:
|
| 642 |
0 |
| break;
|
| 643 |
|
| }
|
| 644 |
0 |
| break;
|
| 645 |
0 |
| case MSP_TCP_SEND_ERROR:
|
| 646 |
0 |
| sprintf( pData, MSP_TCP_SEND_ERR_STR, (long)(pHconn->tcpParms.lastError & MSP_GET_LAST_ERROR) );
|
| 647 |
0 |
| break;
|
| 648 |
0 |
| case MSP_TCP_RECV_ERROR:
|
| 649 |
0 |
| sprintf( pData, MSP_TCP_RECV_ERR_STR, (long)(pHconn->tcpParms.lastError & MSP_GET_LAST_ERROR) );
|
| 650 |
0 |
| break;
|
| 651 |
43 |
| case MSP_TCP_CONN_ERROR:
|
| 652 |
43 |
| sprintf( pData, MSP_TCP_CONN_ERR_STR, (long)(pHconn->tcpParms.lastError & MSP_GET_LAST_ERROR) );
|
| 653 |
43 |
| break;
|
| 654 |
0 |
| case MSP_TCP_SOCK_ERROR:
|
| 655 |
0 |
| sprintf( pData, MSP_TCP_SOCK_ERR_STR, (long)(pHconn->tcpParms.lastError & MSP_GET_LAST_ERROR) );
|
| 656 |
0 |
| break;
|
| 657 |
0 |
| case MSP_TCP_HOST_ERROR:
|
| 658 |
0 |
| strcpy( pData, MSP_MQISDP_HOST_ERR_STR );
|
| 659 |
0 |
| break;
|
| 660 |
0 |
| default:
|
| 661 |
0 |
| break;
|
| 662 |
|
| }
|
| 663 |
|
|
|
| 664 |
|
| /* Add the length of the string pErrStr. If no error data was available */
|
| 665 |
|
| /* then pErrStr will be pointing at its initial value of \0 - a 0 length string */
|
| 666 |
43 |
| dataLength += strlen( pErrStr ) + 1;
|
| 667 |
|
|
|
| 668 |
43 |
| mspWriteIPC( pHconn->ipcCb.apiMailbox, &(pHconn->ipcCb), STAT_R,
|
| 669 |
43 |
| pHconn->connState, 0, dataLength, pHconn->ipcCb.pIpcBuffer );
|
| 670 |
|
|
|
| 671 |
43 |
| return 0;
|
| 672 |
|
| }
|
| 673 |
|
|
|
| 674 |
|
| /* Buffer written to IPC holds: */
|
| 675 |
|
| /* msgId (short) */
|
| 676 |
|
| /* options (long) */
|
| 677 |
|
| /* topic length (long) */
|
| 678 |
|
| /* buffer length (long) */
|
| 679 |
|
| /* data buffer */
|
| 680 |
|
| /* This function does not delete a publication when it is sent to the client */
|
| 681 |
|
| /* The publication is only deleted upon receipt of a positive acknowledgement */
|
| 682 |
|
| /* from the client library. */
|
| 683 |
0 |
| int mspSendRcvPubResponse( HCONNCB *pHconn, long bytesRead, char *pReadBuffer ) {
|
| 684 |
0 |
| long respDataLength = 0;
|
| 685 |
0 |
| char *pData = NULL;
|
| 686 |
|
| RPQ *pRcvdPub;
|
| 687 |
|
| int rc;
|
| 688 |
|
|
|
| 689 |
|
|
|
| 690 |
|
| /* Find the next available publication, if any */
|
| 691 |
0 |
| pRcvdPub = pHconn->inQ.rcvdPubsQ;
|
| 692 |
0 |
▶ | while ( (pRcvdPub != NULL) && (pRcvdPub->readyToPublish == 0) ) {
|
Branch: 2 branches
| Branch | True | False | Total |
| while ( (pRcvdPub != NULL) && (pRcvdPub->readyToPublish == 0) ) {
|
0 |
0 |
0 |
| while ( (pRcvdPub != NULL) && (pRcvdPub->readyToPublish == 0) ) {
|
0 |
0 |
0 |
|
| 693 |
0 |
| pRcvdPub = pRcvdPub->Next;
|
| 694 |
|
| }
|
| 695 |
|
|
|
| 696 |
0 |
▶ | if ( pRcvdPub != NULL ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( pRcvdPub != NULL ) {
|
0 |
0 |
0 |
|
| 697 |
0 |
| respDataLength = (4*sizeof(long)) + sizeof(char*);
|
| 698 |
|
| }
|
| 699 |
|
|
|
| 700 |
0 |
▶ | if ( respDataLength > pHconn->ipcCb.ipcBufferSz ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( respDataLength > pHconn->ipcCb.ipcBufferSz ) {
|
0 |
0 |
0 |
|
| 701 |
0 |
| pHconn->ipcCb.pIpcBuffer = mspRealloc( &(pHconn->comParms), pHconn->ipcCb.pIpcBuffer,
|
| 702 |
|
| respDataLength, pHconn->ipcCb.ipcBufferSz );
|
| 703 |
0 |
| pHconn->ipcCb.ipcBufferSz = respDataLength;
|
| 704 |
|
| }
|
| 705 |
|
|
|
| 706 |
0 |
▶ | if ( pHconn->ipcCb.pIpcBuffer == NULL ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( pHconn->ipcCb.pIpcBuffer == NULL ) {
|
0 |
0 |
0 |
|
| 707 |
0 |
| pHconn->ipcCb.ipcBufferSz = 0;
|
| 708 |
0 |
| rc = MQISDP_OUT_OF_MEMORY;
|
| 709 |
0 |
▶ | } else if ( pRcvdPub == NULL ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| } else if ( pRcvdPub == NULL ) {
|
0 |
0 |
0 |
|
| 710 |
|
| /* When there are no more publications to receive then */
|
| 711 |
|
| /* we need to return one of two possible return codes */
|
| 712 |
|
| /* MQISDP_NO_PUBS_AVAILABLE or MQISDP_CONNECTION_BROKEN */
|
| 713 |
0 |
▶ | if ( pHconn->connState == MQISDP_CONNECTION_BROKEN ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( pHconn->connState == MQISDP_CONNECTION_BROKEN ) {
|
0 |
0 |
0 |
|
| 714 |
0 |
| rc = pHconn->connState;
|
| 715 |
|
| } else {
|
| 716 |
0 |
| rc = MQISDP_NO_PUBS_AVAILABLE;
|
| 717 |
|
| }
|
| 718 |
|
| #ifdef MSP_SINGLE_THREAD
|
| 719 |
|
| /* Return how long we actually waited for */
|
| 720 |
0 |
| respDataLength = sizeof(long);
|
| 721 |
0 |
| pData = (char*)(&pHconn->tcpParms.sockWaitTime);
|
| 722 |
|
| #endif
|
| 723 |
|
| } else {
|
| 724 |
0 |
| pData = pHconn->ipcCb.pIpcBuffer;
|
| 725 |
|
|
|
| 726 |
|
| /* Copy in the message id */
|
| 727 |
0 |
| memcpy( pData, &pRcvdPub->rcvId, sizeof(u_long) );
|
| 728 |
0 |
| pData += sizeof(u_long);
|
| 729 |
|
|
|
| 730 |
|
| /* copy the options */
|
| 731 |
0 |
| memcpy( pData, &pRcvdPub->options, sizeof(long) );
|
| 732 |
0 |
| pData += sizeof(long);
|
| 733 |
|
|
|
| 734 |
|
| /* copy the topic length */
|
| 735 |
0 |
| memcpy( pData, &pRcvdPub->topicLength, sizeof(long) );
|
| 736 |
0 |
| pData += sizeof(long);
|
| 737 |
|
|
|
| 738 |
|
| /* copy the buffer length */
|
| 739 |
0 |
| memcpy( pData, &pRcvdPub->bufferLength, sizeof(long) );
|
| 740 |
0 |
| pData += sizeof(long);
|
| 741 |
|
|
|
| 742 |
|
| /* Copy the buffer pointer */
|
| 743 |
0 |
| memcpy( pData, &(pRcvdPub->buffer), sizeof(char*) );
|
| 744 |
|
|
|
| 745 |
|
| /* Indicate if there are more publications or not (pHconn->inQ.rtpEntries) */
|
| 746 |
0 |
▶ | rc = (pHconn->inQ.rtpEntries > 1)?MQISDP_PUBS_AVAILABLE:MQISDP_OK;
|
Branch: 1 branch
| Branch | True | False | Total |
| rc = (pHconn->inQ.rtpEntries > 1)?MQISDP_PUBS_AVAILABLE:MQISDP_OK;
|
0 |
0 |
0 |
|
| 747 |
|
|
|
| 748 |
|
| /* respData Length was set above */
|
| 749 |
0 |
| pData = pHconn->ipcCb.pIpcBuffer;
|
| 750 |
|
| }
|
| 751 |
|
|
|
| 752 |
0 |
| mspWriteIPC( pHconn->ipcCb.apiMailbox, &(pHconn->ipcCb), RCV_R, rc, 0, respDataLength, pData );
|
| 753 |
|
|
|
| 754 |
0 |
| return 0;
|
| 755 |
|
| }
|
| 756 |
|
|
|
| 757 |
|
| /* When the API successfully passes a message back to the client application, this */
|
| 758 |
|
| /* function removes the publication from the queue of data to be received. */
|
| 759 |
0 |
| int mspDeletePublication( HCONNCB *pHconn, char *ec, MQISDPMH hMsg ) {
|
| 760 |
|
| RPQ *pRcvdPub;
|
| 761 |
0 |
| long rc = MQISDP_OK;
|
| 762 |
|
|
|
| 763 |
|
| /* Find the next available publication, if any */
|
| 764 |
0 |
| pRcvdPub = pHconn->inQ.rcvdPubsQ;
|
| 765 |
0 |
▶ | while ( (pRcvdPub != NULL) && (pRcvdPub->rcvId != hMsg) ) {
|
Branch: 2 branches
| Branch | True | False | Total |
| while ( (pRcvdPub != NULL) && (pRcvdPub->rcvId != hMsg) ) {
|
0 |
0 |
0 |
| while ( (pRcvdPub != NULL) && (pRcvdPub->rcvId != hMsg) ) {
|
0 |
0 |
0 |
|
| 766 |
0 |
| pRcvdPub = pRcvdPub->Next;
|
| 767 |
|
| }
|
| 768 |
|
|
|
| 769 |
0 |
▶ | if ( pRcvdPub != NULL ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( pRcvdPub != NULL ) {
|
0 |
0 |
0 |
|
| 770 |
|
| /* If the application received a QoS 1 or 2 publication and persistence is being used */
|
| 771 |
|
| /* then delete the message from the persistence. */
|
| 772 |
0 |
▶ | if ( !(pRcvdPub->options & MQISDP_QOS_0) && (pHconn->persistFuncs != NULL) ) {
|
Branch: 2 branches
| Branch | True | False | Total |
| if ( !(pRcvdPub->options & MQISDP_QOS_0) && (pHconn->persistFuncs != NULL) ) {
|
0 |
0 |
0 |
| if ( !(pRcvdPub->options & MQISDP_QOS_0) && (pHconn->persistFuncs != NULL) ) {
|
0 |
0 |
0 |
|
| 773 |
|
| /* Delete the received publication from the persistence store (QoS > 0 only) */
|
| 774 |
0 |
| pHconn->persistFuncs->delReceivedMessage( pHconn->persistFuncs->pUserData, pRcvdPub->rcvId );
|
| 775 |
|
| }
|
| 776 |
|
|
|
| 777 |
|
| /* And from the in memory queue */
|
| 778 |
0 |
| mspDeleteRPMFromList( pHconn, pRcvdPub );
|
| 779 |
|
| } else {
|
| 780 |
0 |
| mspLog( LOGERROR, &(pHconn->comParms), "mspDeletePublication:Cannot find publication, msgId:%ld\n", (u_short)hMsg );
|
| 781 |
0 |
| rc = MQISDP_FAILED;
|
| 782 |
|
| }
|
| 783 |
|
|
|
| 784 |
0 |
| mspWriteIPC( pHconn->ipcCb.apiMailbox, &(pHconn->ipcCb), RCV_B, rc, hMsg, 0, NULL );
|
| 785 |
|
|
|
| 786 |
0 |
| return 0;
|
| 787 |
|
| }
|
| 788 |
|
|
|
| 789 |
|
| /* Initialise the receive task by sending it the socket to listen on */
|
| 790 |
|
| /* Write the socket to the receive mail box */
|
| 791 |
0 |
| int mspInitReceiveTask( HCONNCB *pHconn ) {
|
| 792 |
|
|
|
| 793 |
|
| #ifndef MSP_SINGLE_THREAD
|
| 794 |
|
| /* The socket descriptor is inserted in the rc field of the IPC header */
|
| 795 |
|
| /* By sending the socket descriptor in the IPC header the send task does */
|
| 796 |
|
| /* have to worry about allocating an additional buffer and waiting for a */
|
| 797 |
|
| /* response indicating that the buffer has been read. */
|
| 798 |
|
| mspWriteIPC( pHconn->ipcCb.receiveMailbox, &(pHconn->ipcCb), RCON_S,
|
| 799 |
|
| pHconn->tcpParms.sockfd, 0, 0, NULL );
|
| 800 |
|
| #endif
|
| 801 |
0 |
| return 0;
|
| 802 |
|
| }
|
| 803 |
|
|
|
| 804 |
|
| /* This function resets the connection handle after a disconnect */
|
| 805 |
|
| /* ready to receive the next connect */
|
| 806 |
|
| /* This entails freeing up connection specific storage and */
|
| 807 |
|
| /* reseting some values */
|
| 808 |
11 |
| int mspResetHconn( HCONNCB *pHconn ) {
|
| 809 |
|
| IPQ *curIpqEntry;
|
| 810 |
|
| RPQ *curRpqEntry;
|
| 811 |
|
|
|
| 812 |
|
| /* Disconnect from TCP/IP */
|
| 813 |
11 |
| mspTCPDisconnect( &(pHconn->tcpParms.sockfd) );
|
| 814 |
|
|
|
| 815 |
|
| /* Scrub the memory state, but don't scrub the state in the persistence store unless */
|
| 816 |
|
| /* clean session is being used with the MQIsdp protocol. */
|
| 817 |
11 |
▶ | if ( pHconn->persistFuncs != NULL ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( pHconn->persistFuncs != NULL ) {
|
2 |
9 |
11 |
|
| 818 |
2 |
▶ | if ( pHconn->ctrlFlags & MSP_CLEAN_SESSION ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( pHconn->ctrlFlags & MSP_CLEAN_SESSION ) {
|
1 |
1 |
2 |
|
| 819 |
1 |
| pHconn->persistFuncs->reset( pHconn->persistFuncs->pUserData );
|
| 820 |
|
| }
|
| 821 |
2 |
| pHconn->persistFuncs->close( pHconn->persistFuncs->pUserData );
|
| 822 |
|
| }
|
| 823 |
|
|
|
| 824 |
|
|
|
| 825 |
|
| /* Delete any messages on the output (in progress) queue */
|
| 826 |
11 |
| mspLog( LOGNORMAL, &(pHconn->comParms), "Number of bytes queued for sending:%ld\n", pHconn->outQ.numBytesQueued );
|
| 827 |
11 |
| curIpqEntry = pHconn->outQ.inProgressQ;
|
| 828 |
11 |
▶ | if ( curIpqEntry != NULL ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( curIpqEntry != NULL ) {
|
1 |
10 |
11 |
|
| 829 |
2 |
▶ | while( curIpqEntry->Next != NULL ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| while( curIpqEntry->Next != NULL ) {
|
1 |
1 |
2 |
|
| 830 |
1 |
| curIpqEntry = curIpqEntry->Next;
|
| 831 |
1 |
| mspDelFromHash( pHconn, pHconn->outQ.ipHash, curIpqEntry->Prev->msgId );
|
| 832 |
1 |
| mspDeleteIPMFromList( pHconn, curIpqEntry->Prev );
|
| 833 |
|
| }
|
| 834 |
1 |
| mspDelFromHash( pHconn, pHconn->outQ.ipHash, curIpqEntry->msgId );
|
| 835 |
1 |
| mspDeleteIPMFromList( pHconn, curIpqEntry );
|
| 836 |
1 |
| mspLog( LOGNORMAL, &(pHconn->comParms), "Number of bytes queued for sending:%ld\n", pHconn->outQ.numBytesQueued );
|
| 837 |
|
| }
|
| 838 |
11 |
| pHconn->outQ.inProgressQ = NULL;
|
| 839 |
11 |
| pHconn->outQ.ipEntries = 0;
|
| 840 |
11 |
| pHconn->outQ.numBytesQueued = 0;
|
| 841 |
11 |
| pHconn->outQ.pLastEntry = NULL;
|
| 842 |
|
|
|
| 843 |
|
| /* Delete any messages on the input (received publications) queue */
|
| 844 |
11 |
| mspLog( LOGNORMAL, &(pHconn->comParms), "Number of bytes queued for receiving:%ld\n", pHconn->inQ.numBytesQueued );
|
| 845 |
11 |
| curRpqEntry = pHconn->inQ.rcvdPubsQ;
|
| 846 |
11 |
▶ | if ( curRpqEntry != NULL ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( curRpqEntry != NULL ) {
|
0 |
11 |
11 |
|
| 847 |
0 |
▶ | while( curRpqEntry->Next != NULL ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| while( curRpqEntry->Next != NULL ) {
|
0 |
0 |
0 |
|
| 848 |
0 |
| curRpqEntry = curRpqEntry->Next;
|
| 849 |
0 |
| mspDeleteRPMFromList( pHconn, curRpqEntry->Prev );
|
| 850 |
|
| }
|
| 851 |
0 |
| mspDeleteRPMFromList( pHconn, curRpqEntry );
|
| 852 |
0 |
| mspLog( LOGNORMAL, &(pHconn->comParms), "Number of bytes queued for receiving:%ld\n", pHconn->inQ.numBytesQueued );
|
| 853 |
|
| }
|
| 854 |
11 |
| pHconn->inQ.rcvdPubsQ = NULL;
|
| 855 |
11 |
| pHconn->inQ.rtpEntries = 0;
|
| 856 |
11 |
| pHconn->inQ.numBytesQueued = 0;
|
| 857 |
11 |
| pHconn->inQ.pLastEntry = NULL;
|
| 858 |
|
|
|
| 859 |
|
| /* Remove the saved connect message for the previous connection */
|
| 860 |
11 |
▶ | if ( pHconn->reconnect.connectMsg != NULL ) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if ( pHconn->reconnect.connectMsg != NULL ) {
|
4 |
7 |
11 |
|
| 861 |
4 |
| mspFree( &(pHconn->comParms), pHconn->reconnect.connectMsg, pHconn->reconnect.connMsgSz );
|
| 862 |
4 |
| pHconn->reconnect.connectMsg = NULL;
|
| 863 |
|
| }
|
| 864 |
11 |
| pHconn->reconnect.connMsgSz = 0;
|
| 865 |
11 |
| pHconn->reconnect.connRetries = 0;
|
| 866 |
11 |
| pHconn->reconnect.timeForNextConnect = 0;
|
| 867 |
|
|
|
| 868 |
|
| /* Delete all TCP/IP connection information */
|
| 869 |
11 |
| pHconn->tcpParms.lastError = 0;
|
| 870 |
11 |
| pHconn->tcpParms.msperrno = 0;
|
| 871 |
11 |
| pHconn->tcpParms.sockfd = MSP_INVALID_SOCKET;
|
| 872 |
|
|
|
| 873 |
11 |
| pHconn->nextMsgId = 0;
|
| 874 |
11 |
| pHconn->nextRcvId = 0;
|
| 875 |
|
|
|
| 876 |
11 |
| return 0;
|
| 877 |
|
| }
|
| 878 |
|
|
|
| 879 |
|
|
|
| 880 |
|
|
|