2.3 Putting Data in a Buffer
Once you have allocated a buffer, you can put data in it.
In the following listing, a VIEW typed buffer
called aud is created with three members (fields). The
three members are b_id, the branch identifier taken
from the command line (if provided); balance, used to
return the requested balance; and ermsg, used to
return a message to the status line for the user. When
audit is used to request a specific branch balance,
the value of the b_id member is set to the branch
identifier to which the request is being sent, and the
balance and ermsg members are set to zero
and the NULL string, respectively.
Listing Putting Data in a Message Buffer - Example 1
...
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, "");
...When audit is used to query the total bank balance,
the total balance at each site is obtained by a call to the
BAL server. To run a query on each site, a
representative branch identifier is specified. Representative
branch identifiers are stored in an array named
sitelist[]. Hence, the aud structure is
set up as shown in the following listing.
Listing Placing Data in a Message Buffer - Example 2
...
/* Prepare aud structure */
audv->b_id = sitelist[i];/* routing done on this field */
audv->balance = 0.0;
(void)strcpy(audv->ermsg, "");
...The process of putting data into a STRING buffer is
illustrated in the listing titled “Resizing a Buffer”
.
See Also
- “Allocating a Typed Buffer”
- “Resizing a Typed Buffer”
-
tpalloc(3c)in Oracle Tuxedo ATMI C Function Reference
Parent topic: Managing Typed Buffers