src/mspclnt.c

filter: Statementstmt 49.1% 88 / 179 Branchbran 29.7% 22 / 74 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 43.4% 110 / 253 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« src/mspstart.c ↑ Summary lib/WebSphere/MQTT/Client.xs »
1 /****************************************************************************/
2 /* */
3 /* Program name: MQIsdp protocol C Language implementation */
4 /* */
5 /* Description: This source file contains the API to the MQIsdp protocol. */
6 /* All functions in this file pass the received data across to the send */
7 /* thread for processing. */
8 /* */
9 /* Statement: Licensed Materials - Property of IBM */
10 /* */
11 /* MQSeries SupportPac IA93 */
12 /* (C) Copyright IBM Corp. 2002, 2003 */
13 /* */
14 /****************************************************************************/
15 /* Version @(#) IA93/ship/mspclnt.c, SupportPacs, S000 1.3 03/08/26 16:38:15 */
16 /* */
17 /* Function: */
18 /* */
19 /* Contains the API that is exposed to client applications. */
20 /* */
21 /****************************************************************************/
22 /* */
23 /* Change history: */
24 /* */
25 /* V1.0 19-02-2003 IRH Initial release */
26 /* */
27 /*==========================================================================*/
28 /* Module Name: mspclnt.c */
29 #ifdef MSP_SINGLE_THREAD
30 #include <mspdmn.h>
31 #endif
32 #include <mspclnt.h>
33
34 static int mspCopyDataToBuffer( MSPCCB *pConnHandle, char **ppCpToBuffer, long *cpToSz,
35 char *pCpFromBuffer, int cpFromSz );
36 static int mspIPCExchange( MSPCCB *pConnHandle, char *pEc, MQISDPMH hMsgWrite, char *pData,
37 long dataLength, long *pBytesRead, char* pEcRead, MQISDPMH *pHmsgRead );
38
39 /* Global variable controlling the shutdown of all threads behind the API, defined in mspdmn.c */
40 extern int mspEnding;
41
42 /* MQIsdp_connect */
43 /* Initialise the connection handle and connect to the send thread */
44 /* phConn must be MQISDP_INV_CONN_HANDLE prior to issuing the connect */
45 /* return MQISDP_OK on success, or an error code */
46 7 DllExport int MQIsdp_connect( MQISDPCH *phConn, CONN_PARMS *pMspCp, MQISDPTI *pTaskInfo ) {
47 7 int rc = MQISDP_FAILED;
48 7 long bytesRead = 0;
49 char eyeCatcher[MSP_EC_LENGTH];
50 MSPCCB *pConnHandle;
51
52 7 ▶ if ( *phConn != MQISDP_INV_CONN_HANDLE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( *phConn != MQISDP_INV_CONN_HANDLE ) { 0 7 7
53 0 return MQISDP_ALREADY_CONNECTED;
54 }
55
56 7 *phConn = MQISDP_INV_CONN_HANDLE;
57
58 7 pConnHandle = (MSPCCB*)mspMalloc( NULL, sizeof(MSPCCB) );
59
60 7 ▶ if ( pConnHandle == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( pConnHandle == NULL ) { 0 7 7
61 0 return MQISDP_OUT_OF_MEMORY;
62 }
63
64 7 pConnHandle->comParms.memLimit = 0;
65 7 pConnHandle->comParms.mspLogOptions = pTaskInfo->logLevel;
66 #if MSP_DEBUG_MEM > 0
67 pConnHandle->comParms.memMax = 0;
68 pConnHandle->comParms.memCount = 0;
69 pConnHandle->comParms.mc = 0;
70 pConnHandle->comParms.fc = 0;
71 #endif
72
73 /* Validate the client identifier */
74 7 ▶ if ( strlen(pMspCp->clientId) > MQISDP_CLIENT_ID_LENGTH ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( strlen(pMspCp->clientId) > MQISDP_CLIENT_ID_LENGTH ) { 0 7 7
75 0 mspFree( NULL, pConnHandle, sizeof(MSPCCB) );
76 0 return MQISDP_CLIENT_ID_ERROR;
77 }
78
79 7 pConnHandle->ipcCb.apiMailbox = pTaskInfo->apiMailbox;
80 7 pConnHandle->ipcCb.sendMailbox = pTaskInfo->sendMailbox;
81 7 pConnHandle->ipcCb.receiveMailbox = MSP_NULL_MAILBOX; /* Don't need to know the receive threads mail box */
82 7 pConnHandle->ipcCb.sendMutex = pTaskInfo->sendMutex;
83 7 pConnHandle->ipcCb.receiveSemaphore = pTaskInfo->receiveSemaphore;
84
85 /* Set the IPC buffer size to the maximum of the CONN_PARMS length or */
86 /* the default IPC buffer size */
87 7 ▶ if ( pMspCp->strucLength > MSP_DEFAULT_IPC_BUFFER_SZ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( pMspCp->strucLength > MSP_DEFAULT_IPC_BUFFER_SZ ) { 0 7 7
88 0 pConnHandle->ipcCb.ipcBufferSz = pMspCp->strucLength;
89 } else {
90 7 pConnHandle->ipcCb.ipcBufferSz = MSP_DEFAULT_IPC_BUFFER_SZ;
91 }
92 14 pConnHandle->ipcCb.pIpcBuffer = (char*)mspMalloc( &(pConnHandle->comParms),
93 7 pConnHandle->ipcCb.ipcBufferSz );
94 7 pConnHandle->ipcCb.options = 0x00 | MSP_IPC_BLOCK;
95 7 pConnHandle->ipcCb.readTimeout = MSP_IPC_WAIT_FOREVER;
96
97 /* Initialise the IPC for this task - the API */
98 7 mspInitialiseIPC( pConnHandle->ipcCb.apiMailbox, &(pConnHandle->ipcCb) );
99
100 #ifdef MSP_SINGLE_THREAD
101 7 pConnHandle->pSendHconn = mspInitialise( NULL );
102 /* When running single threaded we set up a pseudo mailbox for */
103 /* communication, with the buffer being part of the client */
104 /* connection handle. */
105 7 pConnHandle->ipcCb.pPseudoMailbox = pConnHandle->mspIpcBuffer;
106 7 pConnHandle->pSendHconn->ipcCb.pPseudoMailbox = pConnHandle->mspIpcBuffer;
107 #endif
108
109 7 rc = mspIPCExchange( pConnHandle, CONN_S, 0, (char*)pMspCp, pMspCp->strucLength,
110 &bytesRead, eyeCatcher, NULL );
111
112 7 ▶ if ( rc == MQISDP_OK ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( rc == MQISDP_OK ) { 5 2 7
113 5 *phConn = (MQISDPCH)pConnHandle;
114 } else {
115 2 *phConn = MQISDP_INV_CONN_HANDLE;
116 2 mspFree( NULL, pConnHandle, sizeof(MSPCCB) );
117 }
118
119 7 return rc;
120 }
121
122 /* MQIsdp_disconnect */
123 /* Disconnect from the send thread and free up the connection handle */
124 4 DllExport int MQIsdp_disconnect( MQISDPCH *phConn ) {
125 4 int rc = MQISDP_FAILED;
126 4 long bytesRead = 0;
127 char eyeCatcher[MSP_EC_LENGTH];
128 MSPCCB *pConnHandle;
129
130 4 ▶ if ( *phConn == MQISDP_INV_CONN_HANDLE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( *phConn == MQISDP_INV_CONN_HANDLE ) { 0 4 4
131 0 return MQISDP_CONN_HANDLE_ERROR;
132 }
133
134 4 pConnHandle = (MSPCCB*)*phConn;
135
136 4 rc = mspIPCExchange( (MSPCCB*)*phConn, DISC_S, 0, NULL, 0, &bytesRead, eyeCatcher, NULL );
137
138 4 ▶ if (rc != MQISDP_FAILED ) {
Branch: 1 branch
BranchTrueFalseTotal
if (rc != MQISDP_FAILED ) { 4 0 4
139 4 mspFree( &pConnHandle->comParms, pConnHandle->ipcCb.pIpcBuffer,
140 4 pConnHandle->ipcCb.ipcBufferSz );
141
142 /* Log the memory allocation. Add a correction of the size of the connection */
143 /* handle because that was on the heap, but not counted because the */
144 /* structure was malloc'ed before stats were recorded. */
145 4 mspLogMem( &pConnHandle->comParms, "API ", sizeof(MSPCCB) );
146
147 4 mspFree( NULL, pConnHandle, sizeof(MSPCCB) );
148 4 *phConn = MQISDP_INV_CONN_HANDLE;
149 }
150
151 4 return rc;
152 }
153
154 /* MQIsdp_subscribe */
155 /* Pass the subscribe message to the send thread */
156 0 DllExport int MQIsdp_subscribe( MQISDPCH hConn,
157 MQISDPMH *pHmsg,
158 SUB_PARMS *pMspSp ) {
159 0 int rc = MQISDP_FAILED;
160 0 long bytesRead = 0;
161 char eyeCatcher[MSP_EC_LENGTH];
162
163 0 *pHmsg = MQISDP_INV_MSG_HANDLE;
164
165 0 ▶ if ( hConn == MQISDP_INV_CONN_HANDLE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( hConn == MQISDP_INV_CONN_HANDLE ) { 0 0 0
166 0 return MQISDP_CONN_HANDLE_ERROR;
167 }
168
169 0 rc = mspIPCExchange( (MSPCCB*)hConn, SUB_S, 0, (char*)pMspSp, pMspSp->strucLength,
170 &bytesRead, eyeCatcher, pHmsg );
171 0 return rc;
172 }
173
174 /* MQIsdp_unsubscribe */
175 /* Pass the unsubscribe message to the send thread */
176 0 DllExport int MQIsdp_unsubscribe( MQISDPCH hConn,
177 MQISDPMH *pHmsg,
178 UNSUB_PARMS *pMspUp ) {
179
180 0 int rc = MQISDP_FAILED;
181 0 long bytesRead = 0;
182 char eyeCatcher[MSP_EC_LENGTH];
183
184 0 *pHmsg = MQISDP_INV_MSG_HANDLE;
185
186 0 ▶ if ( hConn == MQISDP_INV_CONN_HANDLE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( hConn == MQISDP_INV_CONN_HANDLE ) { 0 0 0
187 0 return MQISDP_CONN_HANDLE_ERROR;
188 }
189
190 0 rc = mspIPCExchange( (MSPCCB*)hConn, UNS_S, 0, (char*)pMspUp, pMspUp->strucLength,
191 &bytesRead, eyeCatcher, pHmsg );
192 0 return rc;
193 }
194
195 /* MQIsdp_publish */
196 /* Pass the publish message to the send thread */
197 4 DllExport int MQIsdp_publish( MQISDPCH hConn,
198 MQISDPMH *pHmsg,
199 PUB_PARMS *pMspPp ){
200 4 int rc = MQISDP_FAILED;
201 4 long bytesRead = 0;
202 char eyeCatcher[MSP_EC_LENGTH];
203
204 4 *pHmsg = MQISDP_INV_MSG_HANDLE;
205
206 4 ▶ if ( hConn == MQISDP_INV_CONN_HANDLE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( hConn == MQISDP_INV_CONN_HANDLE ) { 1 3 4
207 1 return MQISDP_CONN_HANDLE_ERROR;
208 }
209 3 ▶ if ( pMspPp->dataLength <= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( pMspPp->dataLength <= 0 ) { 0 3 3
210 0 return MQISDP_DATA_LENGTH_ERROR;
211 }
212
213 3 rc = mspIPCExchange( (MSPCCB*)hConn, PUB_S, 0, (char*)pMspPp, pMspPp->strucLength,
214 &bytesRead, eyeCatcher, pHmsg );
215 3 return rc;
216 }
217
218 /* MQIsdp_getMsgStatus */
219 /* Find out if a particular message has been delivered successfully or not */
220 0 DllExport int MQIsdp_getMsgStatus( MQISDPCH hConn, MQISDPMH hMsg ) {
221 0 int rc = MQISDP_FAILED;
222 0 long bytesRead = 0;
223 char eyeCatcher[MSP_EC_LENGTH];
224
225 0 ▶ if ( hConn == MQISDP_INV_CONN_HANDLE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( hConn == MQISDP_INV_CONN_HANDLE ) { 0 0 0
226 0 return MQISDP_CONN_HANDLE_ERROR;
227 }
228
229 0 rc = mspIPCExchange( (MSPCCB*)hConn, MSG_S, hMsg, NULL, 0, &bytesRead, eyeCatcher, NULL );
230
231 0 return rc;
232 }
233
234 /* MQIsdp_status */
235 /* Find out the current state of the MQIsdp connection */
236 /* Valid states are: */
237 /* MQISDP_CONNECTING */
238 /* MQISDP_CONNECTED */
239 /* MQISDP_CONNECTION_BROKEN */
240 /* MQISDP_CONNECTION_BROKEN indicates that all retry attempts by the client have failed. */
241 /* The application should disconnect after checking the state of all messages and take some */
242 /* other action. */
243 43 DllExport int MQIsdp_status( MQISDPCH hConn, long errStrLen, long *errCode, char *errStr ) {
244 43 int rc = MQISDP_FAILED;
245 43 long bytesRead = 0;
246 char *pData;
247 char eyeCatcher[MSP_EC_LENGTH];
248 MSPCCB *pConnHandle;
249
250 43 ▶ if ( errStr != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( errStr != NULL ) { 43 0 43
251 43 errStr[0] = '\0';
252 }
253 43 ▶ if ( errCode != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( errCode != NULL ) { 0 43 43
254 0 *errCode = 0;
255 }
256
257 43 ▶ if ( hConn == MQISDP_INV_CONN_HANDLE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( hConn == MQISDP_INV_CONN_HANDLE ) { 0 43 43
258 0 return MQISDP_CONN_HANDLE_ERROR;
259 }
260
261 43 rc = mspIPCExchange( (MSPCCB*)hConn, STAT_S, 0, NULL, 0, &bytesRead, eyeCatcher, NULL );
262
263 43 ▶ if ( (rc != MQISDP_FAILED) && (bytesRead > 0 ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( (rc != MQISDP_FAILED) && (bytesRead > 0 ) ) { 43 0 43
if ( (rc != MQISDP_FAILED) && (bytesRead > 0 ) ) { 43 0 43
264 43 pConnHandle = (MSPCCB*)hConn;
265 /* First retrieve the error code */
266 43 pData = (char*)pConnHandle->ipcCb.pIpcBuffer;
267 43 ▶ if ( errCode != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( errCode != NULL ) { 0 43 43
268 0 memcpy( errCode, pData, sizeof(long) );
269 }
270 43 pData += sizeof(long);
271
272 /* Next see if there is an error string */
273 43 ▶ if ( bytesRead > sizeof(long) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( bytesRead > sizeof(long) ) { 43 0 43
274 43 strncpy( errStr, pData, errStrLen );
275 43 errStr[errStrLen-1] = '\0';
276 } else {
277 0 errStr[0] = '\0';
278 }
279 }
280
281 43 return rc;
282 }
283
284 /* MQIsdp_receivePub */
285 /* The code needs to send a confirmation message to the daemon to indicate that the client */
286 /* application successfully received the publication. This is so that if the receiving */
287 /* application specifies a buffer that is too small then the message is not deleted from */
288 /* the daemon queue. */
289 0 DllExport int MQIsdp_receivePub( MQISDPCH hConn, long msTimeout, long *options, long *topicLength,
290 long *dataLength, long msgBufferLength, char *msgBuffer ) {
291 char *pData;
292 0 int rc = MQISDP_FAILED;
293 0 long bytesRead = 0;
294 u_long msgId;
295 char *pDataBuffer;
296 char eyeCatcher[MSP_EC_LENGTH];
297 int returnCode;
298 MSPCCB *pConnHandle;
299 #ifdef MSP_SINGLE_THREAD
300 long waitedTime;
301 #endif
302
303 0 ▶ if ( hConn == MQISDP_INV_CONN_HANDLE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( hConn == MQISDP_INV_CONN_HANDLE ) { 0 0 0
304 0 return MQISDP_CONN_HANDLE_ERROR;
305 }
306
307 0 pConnHandle = (MSPCCB*)hConn;
308
309 0 *options = 0;
310 0 *topicLength = 0;
311 0 *dataLength = 0;
312
313 /* mspWaitForSemaphore waits for the receive semaphore to become signalled */
314 /* indicating that publications are available. This function only has any */
315 /* effect if the code is built without MSP_SINGLE_THREAD defined */
316 0 mspWaitForSemaphore( pConnHandle->ipcCb.receiveSemaphore, msTimeout );
317
318 /* Regardless of the result of wait for semaphore we want to ask the send thread */
319 /* for publications, even if there are none, because it may send as back a return*/
320 /* code indicating that there is a problem e.g. CONNECTION_BROKEN */
321 0 ▶ if ( mspLockMutex( pConnHandle->ipcCb.sendMutex ) == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( mspLockMutex( pConnHandle->ipcCb.sendMutex ) == 0 ) { 0 0 0
322 #ifdef MSP_SINGLE_THREAD
323 /* If we are single threaded, then we cannot do a simple blocking wait */
324 /* on the TCP/IP socket, as there are other things we have to do such as */
325 /* retry messages, send and receive ACKS. The mspHandleClientConnection */
326 /* function will wait as long as it can before retries are required. */
327 /* Consequently multiple calls to mspHandleClientConnection are required */
328 /* for the wait time to be fully satisfied. */
329 do {
330 0 memcpy( pConnHandle->ipcCb.pIpcBuffer, &msTimeout, sizeof(long) );
331 #endif
332 0 rc = mspWriteIPC( pConnHandle->ipcCb.sendMailbox, &(pConnHandle->ipcCb),
333 RCV_S, 0, 0, sizeof(long), pConnHandle->ipcCb.pIpcBuffer );
334
335 #ifdef MSP_SINGLE_THREAD
336 0 mspHandleClientConnection( pConnHandle->pSendHconn );
337 #endif
338
339 /* This is a blocking read */
340 0 rc = mspReadIPC( pConnHandle->ipcCb.apiMailbox, &(pConnHandle->ipcCb),
341 &(pConnHandle->comParms), &bytesRead,
342 0 &(pConnHandle->ipcCb.ipcBufferSz), (void**)&(pConnHandle->ipcCb.pIpcBuffer),
343 eyeCatcher, &returnCode, NULL );
344
345 #ifdef MSP_SINGLE_THREAD
346 0 ▶ if ( returnCode == MQISDP_NO_PUBS_AVAILABLE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( returnCode == MQISDP_NO_PUBS_AVAILABLE ) { 0 0 0
347 0 memcpy( &waitedTime, pConnHandle->ipcCb.pIpcBuffer, sizeof(long) );
348 0 msTimeout -= waitedTime;
349 }
350 0 ▶ } while ( (returnCode == MQISDP_NO_PUBS_AVAILABLE) && (msTimeout > 0) );
Branch: 2 branches
BranchTrueFalseTotal
} while ( (returnCode == MQISDP_NO_PUBS_AVAILABLE) && (msTimeout > 0) ); 0 0 0
} while ( (returnCode == MQISDP_NO_PUBS_AVAILABLE) && (msTimeout > 0) ); 0 0 0
351 #endif
352
353 /* Return the required info to the API */
354 0 rc = returnCode;
355 0 ▶ if ( (rc == MQISDP_PUBS_AVAILABLE) || (rc == MQISDP_OK) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( (rc == MQISDP_PUBS_AVAILABLE) || (rc == MQISDP_OK) ) { 0 0 0
if ( (rc == MQISDP_PUBS_AVAILABLE) || (rc == MQISDP_OK) ) { 0 0 0
356 0 pData = pConnHandle->ipcCb.pIpcBuffer;
357
358 /* Get the message id */
359 0 memcpy( &msgId, pData, sizeof(u_long) );
360 0 pData += sizeof(u_long);
361
362 /* Next the options */
363 0 ▶ if ( options != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( options != NULL ) { 0 0 0
364 0 memcpy( options, pData, sizeof(long) );
365 }
366 0 pData += sizeof(long);
367
368 /* Next the topic length */
369 0 ▶ if ( topicLength != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( topicLength != NULL ) { 0 0 0
370 0 memcpy( topicLength, pData, sizeof(long) );
371 }
372 0 pData += sizeof(long);
373
374 /* Next the buffer length */
375 0 ▶ if ( dataLength != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( dataLength != NULL ) { 0 0 0
376 0 memcpy( dataLength, pData, sizeof(long) );
377 }
378 0 pData += sizeof(long);
379
380 /* Now copy the data into the application buffer */
381 0 ▶ if ( (msgBufferLength != 0) && (msgBuffer != NULL) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( (msgBufferLength != 0) && (msgBuffer != NULL) ) { 0 0 0
if ( (msgBufferLength != 0) && (msgBuffer != NULL) ) { 0 0 0
382 0 memcpy( &pDataBuffer, pData, sizeof(char*) );
383 0 memcpy( msgBuffer, pDataBuffer, *dataLength );
384 }
385
386 /* Check if the application supplied receive buffer is big enough */
387 0 ▶ if ( (*dataLength > msgBufferLength) || (msgBuffer == NULL) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( (*dataLength > msgBufferLength) || (msgBuffer == NULL) ) { 0 0 0
if ( (*dataLength > msgBufferLength) || (msgBuffer == NULL) ) { 0 0 0
388 /* App buffer is too small */
389 0 rc = MQISDP_DATA_TRUNCATED;
390 /* Decline to receive the message */
391 0 mspWriteIPC( pConnHandle->ipcCb.sendMailbox, &(pConnHandle->ipcCb),
392 RCV_D, 0, 0, 0, NULL );
393 } else {
394 /* Everything OK */
395 /* Now build the response to the send thread to */
396 /* indicate that the data should be deleted. */
397 0 mspWriteIPC( pConnHandle->ipcCb.sendMailbox, &(pConnHandle->ipcCb),
398 RCV_A, 0, msgId, 0, NULL );
399 }
400
401 #ifdef MSP_SINGLE_THREAD
402 0 mspHandleClientConnection( pConnHandle->pSendHconn );
403 #endif
404
405 /* We have to wait for an acknowledgement to this write */
406 /* otherwise we very easily get into the situation where this */
407 /* API writes and returns, then the next API call writes */
408 /* resulting in 2 messages on the IPC input queue. */
409 /* This is a blocking read */
410 0 mspReadIPC( pConnHandle->ipcCb.apiMailbox, &(pConnHandle->ipcCb),
411 &(pConnHandle->comParms), &bytesRead,
412 0 &(pConnHandle->ipcCb.ipcBufferSz), (void**)&(pConnHandle->ipcCb.pIpcBuffer),
413 eyeCatcher, &returnCode, NULL );
414
415 }
416
417 0 mspReleaseMutex( pConnHandle->ipcCb.sendMutex );
418 }
419
420 0 return rc;
421 }
422
423 /* MQIsdp_terminate */
424 /* Shutdown the threads running behind the API */
425 /* Be aware that all tasks that read this global variable will be shutdown */
426 7 DllExport int MQIsdp_terminate( void ) {
427 7 mspEnding = 1;
428 7 return 0;
429 }
430
431 /* MQIsdp_version */
432 /* This function displays the version of the client and the version of the */
433 /* WMQTT protocol supported by this client. */
434 /* The versioning information is printed to stdout. */
435 0 DllExport void MQIsdp_version( void ) {
436 0 printf( "WMQTT client version : 1.2\n" );
437 0 printf( "WMQTT protocol version: 3.0\n\n" );
438 0 printf( "Licensed Materials - Property of IBM\n" );
439 0 printf( "(C) Copyright IBM Corp. 2002, 2003\n" );
440 0 }
441
442 /* This function copies data into a new buffer, enlarging the buffer if required */
443 /* Returns 0 on success, 1 on failure */
444 10 static int mspCopyDataToBuffer( MSPCCB *pConnHandle, char **ppCpToBuffer, long *cpToSz,
445 char *pCpFromBuffer, int cpFromSz ) {
446
447 10 ▶ if ( cpFromSz > *cpToSz ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( cpFromSz > *cpToSz ) { 0 10 10
448 0 *ppCpToBuffer = mspRealloc( &pConnHandle->comParms, *ppCpToBuffer, cpFromSz, *cpToSz );
449 0 ▶ if ( ppCpToBuffer != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ppCpToBuffer != NULL ) { 0 0 0
450 0 *cpToSz = cpFromSz;
451 } else {
452 0 *cpToSz = 0;
453 0 return 1;
454 }
455 }
456
457 10 memcpy( *ppCpToBuffer, pCpFromBuffer, cpFromSz );
458
459 10 return 0;
460 }
461
462 /* All communications from the client application to the send thread need to send some data */
463 /* to the IPC and then wait for a response. mspIPCExchange is a function used by most */
464 /* of the API to do the send and receive. The only exception is MQIsdp_receivePub which */
465 /* has to do some extra work under the mutex lock. */
466 57 static int mspIPCExchange( MSPCCB *pConnHandle, char *pEc, MQISDPMH hMsgWrite, char *pData,
467 long dataLength, long *pBytesRead, char* pEcRead, MQISDPMH *pHmsgRead ) {
468 57 int returnCode = MQISDP_FAILED;
469
470 57 ▶ if ( mspLockMutex( pConnHandle->ipcCb.sendMutex ) == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( mspLockMutex( pConnHandle->ipcCb.sendMutex ) == 0 ) { 57 0 57
471
472 57 ▶ if ( pData != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( pData != NULL ) { 10 47 57
473 /* Copy the data to write into the IPC buffer */
474 10 mspCopyDataToBuffer( pConnHandle, &pConnHandle->ipcCb.pIpcBuffer,
475 &pConnHandle->ipcCb.ipcBufferSz, pData, dataLength );
476 }
477
478 57 mspWriteIPC( pConnHandle->ipcCb.sendMailbox, &(pConnHandle->ipcCb),
479 pEc, 0, hMsgWrite, dataLength, (void*)pConnHandle->ipcCb.pIpcBuffer );
480
481 #ifdef MSP_SINGLE_THREAD
482 57 mspHandleClientConnection( pConnHandle->pSendHconn );
483 #endif
484
485 /* This is a blocking read */
486 57 mspReadIPC( pConnHandle->ipcCb.apiMailbox, &(pConnHandle->ipcCb),
487 &(pConnHandle->comParms), pBytesRead,
488 57 &(pConnHandle->ipcCb.ipcBufferSz), (void**)&(pConnHandle->ipcCb.pIpcBuffer),
489 pEcRead, &returnCode, pHmsgRead );
490
491 57 mspReleaseMutex( pConnHandle->ipcCb.sendMutex );
492 }
493
494 57 return returnCode;
495 }
« src/mspstart.c ↑ Summary lib/WebSphere/MQTT/Client.xs »