1
USEFUL MACROS AND FUNCTIONS FOR MESSAGE PASSING:
Although we have strongly asserted in our ChanIn/ChanOut matching rule that a ChanIn operation must know in advance how many bytes of information it will receive from a corresponding ChanOut, we can easily design a "blind" ChanIn function. The trick is to have ChanOut first send as an integer the number of bytes it will be sending. Below is an example of two matching functions tailored to sending strings of characters.
void BChanOut(Channel *c, char *s)
{
int n = strlen(s)+1; /* +1 to include \0 */
ChanOut(c, &n, (int) sizeof(int));
ChanOut(c,s,n);
}
int BChanIn(Channel *c, char *s)
{
int n;
ChanIn(c, &n, (int) sizeof(int));
ChanIn(c, s, n);
return n;
}
.