TipcMsgAppendStrPtr use a pointer to append a STR field to a message
T_BOOL TipcMsgAppendStrPtr(msg, str_data
,field_return
) T_IPC_MSGmsg
; T_STRstr_data
; T_IPC_MSG_FIELD *field_return
;
msg
message to append field to
str_data
data for new message field
field_return
optional location to return field (use NULL
if not needed)
TRUE
if the field was successfully appended to the message, FALSE
otherwise.
If TipcMsgAppendStrPtr fails, it returns FALSE
and sets the global SmartSockets error number to one of:
TipcMsgAppendStrPtr appends a null-terminated character STR field containing str_data
to the end of a message’s data. This function does not make a copy of the string. Instead, the supplied pointer to the string is entered directly into the new message field’s internal data structure. The caller is responsible for making sure that the pointer remains valid for the lifetime of the message field, and for freeing it, if necessary, when the message field has been destroyed.
One advantage of TipcMsgAppendStrPtr over TipcMsgAppendStr is that the string can be modified after the field is appended, but before the message is sent. Also, the overhead of one copy operation is avoided, because the character string is still copied into the connection message buffer when the message is sent.
To update the pointer to point to a new memory location, use the TipcMsgFieldUpdateStrPtr function.
None
TipcMsgAppendStr, TipcMsgNextStr, TipcMsgFieldSetSize, TipcMsgFieldUpdateStrPtr
This example creates a message and appends a pointer to a STR field:
T_IPC_MT mt; T_IPC_MSG msg; T_CHAR str[80]; T_IPC_MSG_FIELD field; #define USER_MT_STR_TEST 100 mt = TipcMtCreate("str_test", USER_MT_STR_TEST, "str"); if (mt == NULL) {return
; /* error */
} msg = TipcMsgCreate(mt); if (mt == NULL) {return
; /* error */
}/* An RTclient would typically set the destination of */
/* a message at this point by calling TipcMsgSetDest. */
str[0] = '\0'; if (!TipcMsgAppendStrPtr(msg, str, &field)) {return
; /* error */
} strcpy(str, "This is the field data."); if (!TipcMsgFieldSetSize(field, strlen(str) + 1)) {return
; /* error */
}/* A process would typically send a message at this point by */
/* calling TipcConnMsgSend or TipcSrvMsgSend. */
/* A process would typically destroy a message at this point by */
/* calling TipcMsgDestroy. */
TIBCO SmartSockets™ Application Programming Interface Software Release 6.8, July 2006 Copyright © TIBCO Software Inc. All rights reserved www.tibco.com |