Usenet comp.unix.osf.misc (1992-2004)
 help / color / mirror / Atom feed
* RPC HELP
@ 1994-10-05 21:10 Subbarao Chalavadi
  0 siblings, 0 replies; only message in thread
From: Subbarao Chalavadi @ 1994-10-05 21:10 UTC (permalink / raw)


Hi


   I am using RPC and
running into some problem (I don't think it is a major one). But i would really
appreciate if you can give me any help or comments about my problem.
  Thanks a lot in advance for your time. 



 Here is what the problem,


I have two Sun Machines running Sun OS4.1.3 and on one of them i am running
the server and on ther other client process.

The client makes a request for a binary file to the server process. THe server
process then open the binary file name provided by the client and reads into
a linked list (where each node is holding 255 bytes).  After the entire file
is read, the server sends back the linked list to the client.  THe client then
traverses the list and then stores it in another file.

This is working fine for the first time. That is first time when the client
is making a request, the server is responding well and giving the linked list
back and the client is also doing well and it is storing it in a file.

Now here the problem comes. Immediately after the first request is over, if i
make my client to make similar request for the same file or any other
 binary file again, then a msg is coming on the Client machine


RPC: Can't decode the result


But the server is intact.  The server process is still running. And also i put
a print statement at the end of the server to see whether it is reading the
file or not.  And to my surprise, it is printing that statement also everytime
. It looks like the client machine is getting the info but it is not able to
inpret the data may be.

Other interesting thing, after i make 3 or 5 requests again and again, the
server gives back file without problem and the client stores it properly.

So is something am i missing to take care.  Why does i have make 3 or 5 requests
after any request that was served properly.


I have been trying to solve this issue for last one week.  I already posted to
different newsgroups and no proper response except for one. I 
request the people on the net, if possible give your comments or point me to
 a right direction.  


Thanks for any kind of help.


Note: The binary files i am talking about may be as big as 50k to 200k or so.


Here i am enclosing the code and how to run it.  I am using SUN OS 4.1.3

steps for compiling:


rpcgen  dir.x
cc -c dir_xdr.c
cc rls.c dir_clnt.c dir_xdr.o -o rls
cc dir_svc.c dir_proc.c dir_xdr.o -o dir_svc




Now at one machine do the following


dir_svc &

that is running the server at background

then go to another machine and do the following


rls pluto /usr/bin/test.o

here pluto is the machine name where we are running the server process and other
argument is the filename you want the server to give it to the client.


Source code.


--------------------Begin of dir.x---------------------------------------


const MAXNAMELEN = 255;

typedef string nametype<MAXNAMELEN>;

typedef struct namenode *namelist;


struct namenode {


   nametype name;
 
   namelist next;
 
};
 
union readdir_res switch (int errno)
 {
   case 0:
     namelist list;
 
   default:
     void;
};
program DIRPROG {
  version DIRVERS {
   readdir_res
   READDIR(nametype) =1 ;
  }=1;
}=200051
 
----------End of dir.x----------------------------------------
 
 
 
 
 
 
----------------Begin of dir_proc.c------------------------------------
 
 
 
 
 
 
#include <rpc/rpc.h>
#include <sys/dir.h>
#include "dir.h"
#include <stdio.h>
extern char *malloc();
extern char *strdup();
#include <string.h>
#include <fcntl.h>
extern int errno;
readdir_res *
 
 readdir_1(dirname)
  nametype *dirname;
  {
  int count ;
  char  line[255];
  namelist nl;
  namelist *nlp;
  FILE *inputfile;
  static readdir_res res;
 
 inputfile = fopen(*dirname, "r");
  if (inputfile== NULL )
   {
    res.errno = errno;
    return (&res);
 }
 
xdr_free(xdr_readdir_res, &res);
 
 
  nlp = &res.readdir_res_u.list;
  count =0;
 
 
while (  !feof(inputfile) )
 {
  count = fread(line,1,255,inputfile);
 
 
/* The if condition is for last residue of the binary*/
/* file which is not 255 bytes long.  So at that time, reset */
/* your file pointer back to the begining of the left over */
/* residue and read it again and store it in the node of
*/
/* the linked list and leave the while loop */
 
 
 
 if (count != 255)
 {
   fseek(inputfile,-count,2);
   ftell(inputfile);
   count = fread(line,1,count,inputfile);
  *nlp =   (namenode* ) malloc ( sizeof(namenode));
   nl = *nlp;
 
   nl->name = (char *) malloc (255) ;
   memcpy(nl->name,line,255);
   nlp = &nl->next;
   break;  /* Break and leave the while loop */
 
 }
/* This piece gets executed for blocks of 255.  Create a
node*/
/* and store it the data in the name field of the linked
*/
 
  *nlp = (namenode* ) malloc ( sizeof(namenode));
  nl = *nlp;
  nl->name = (char *) malloc (255) ;
  memcpy(nl->name,line,255);
  nlp = &nl->next;
 
 }  /* End of while not end of file */
 
 
 
 
 *nlp= NULL;
 res.errno = 0;
 fclose(inputfile);
 printf("Returning safely ");
 fflush(stdout);
return (&res);
 
 
}



-----------------------------End of dir_proc.c-------------------------
 
 
----------Begin of rls.c --------------------------------------
 
 
 
 
 
#include <stdio.h>
#include <rpc/rpc.h>
#include "dir.h"
extern int errno;
int count=0;
main(argc, argv)
 int argc;
 char* argv[];
 
{
 
 struct timeval tv;
 
 CLIENT *cl;
 char *server;
 char *dir;
 readdir_res *result;
 namelist nl;
 
 FILE *fileout;
 printf(" ENTERED first");
  fflush(stdout);
 
 if (argc != 3)
 
  {
 
   fprintf(stderr, "usage: %s host directory\n", argv[0]);
   exit(1);
 
  }
 
 
server = argv[1];
 
dir   = argv[2];
 
 cl = clnt_create(server,DIRPROG, DIRVERS, "tcp");
 
 
/* I initially put the timer and now i removed it */
 
 

 
/*  tv.tv_sec = 90;
 tv.tv_usec = 0;
 clnt_control(cl,CLSET_TIMEOUT,&tv); */
 
if (cl == NULL)
 
  {
   clnt_pcreateerror(server);
   exit(1);
  }
 
 
 result = readdir_1(&dir, cl);
 
 if (result == NULL)
 {
  clnt_perror(cl, server);
  exit(1);
 }
 
 if (result->errno != 0)
 {
 errno = result->errno;
 perror(dir);
 exit(1);
 }
 
 
/* I am purposefully not writing the last record */
 
 
 fileout = fopen("junk.out","w");
 
 for (nl = result->readdir_res_u.list ; nl->next != NULL; nl=nl->next) {
        count =fwrite((char *)nl->name, 1,255, fileout);
 }
fclose(fileout);

clnt_destroy(cl);
 exit(0);
}
 

---------------End of rls.c----------------------------------------------






Subbarao.

p.s: My opinions don't reflect those of my employer's



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1994-10-05 21:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1994-10-05 21:10 RPC HELP Subbarao Chalavadi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox