RPC -WR5441 Spezifikationen Seite 28

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 34
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 27
Page 28 Remote Procedure Call Programming Guide
5.2. TCP
Here is an example that is essentially rcp. The initiator of the RPC snd call takes its standard input and
sends it to the server rcv which prints it on standard output. The RPC call uses TCP. This also illustrates
an XDR procedure that behaves differently on serialization than on deserialization.
/*
* The xdr routine:
* on decode, read from wire, write onto fp
* on encode, read from fp, write onto wire
*/
#include <stdio.h>
#include <rpc/rpc.h>
xdr_rcp(xdrs, fp)
XDR *xdrs;
FILE *fp;
{
unsigned long size;
char buf[BUFSIZ], *p;
if (xdrs->x_op == XDR_FREE)/* nothing to free */
return 1;
while (1) {
if (xdrs->x_op == XDR_ENCODE) {
if ((size = fread(buf, sizeof(char), BUFSIZ,
fp)) == 0 && ferror(fp)) {
fprintf(stderr, "can’t fread\n");
return (1);
}
}
p = buf;
if (!xdr_bytes(xdrs, &p, &size, BUFSIZ))
return 0;
if (size == 0)
return 1;
if (xdrs->x_op == XDR_DECODE) {
if (fwrite(buf, sizeof(char), size,
fp) != size) {
fprintf(stderr, "can’t fwrite\n");
return (1);
}
}
}
}
Seitenansicht 27
1 2 ... 23 24 25 26 27 28 29 30 31 32 33 34

Kommentare zu diesen Handbüchern

Keine Kommentare