6.2.1 Example: Using the Same Buffer for Request and Reply Messages
The following listing shows how the client program,
audit.c
, makes a synchronous call using the same
buffer for both the request and reply messages. In this case, using
the same buffer is appropriate because the *audv
message buffer has been set up to accommodate both request and
reply information. The following actions are taken in this
code:
- The service queries the
b_id
field, but does not overwrite it. - The application initializes the
bal
andermsg
fields to zero and the NULL string, respectively, in preparation for the values to be returned by the service. - The
svc_name
andhdr_type
variables represent the service name and the balance type requested, respectively. In this example, these variables representaccount
andteller
, respectively.
Listing 6‑1 Using the Same Buffer for Request and Reply Messages
. . .
/* Create buffer and set data pointer */
audv = (struct aud *)tpalloc("VIEW", "aud", sizeof(struct aud));
/* Prepare aud structure */
audv->b_id = q_branchid;
audv->balance = 0.0;
(void)strcpy(audv->ermsg, "");
/* Do tpcall */
if (tpcall(svc_name,(char *)audv,sizeof(struct aud),
(char **)&audv,(long *)&audrl,0)== -1){
(void)fprintf (stderr, "%s service failed\n %s: %s\n",
svc_name, svc_name, audv->ermsg);
retc = -1;
}
else
(void)printf ("Branch %ld %s balance is $%.2f\n",
audv->b_id, hdr_type, audv->balance);
. . .
Parent topic: Sending Synchronous Messages