Esempio n. 1
0
/*
 * zamykanie sesji
 */
void close_session()
{
  enum clnt_stat clnt_stat;

  clnt_stat = clnt_broadcast(PRIME_PROG, PRIME_VERS,
			     KONIEC_SESJI, (xdrproc_t) xdr_str, my_name, (xdrproc_t) xdr_void,
			     0, (resultproc_t)server_closing);

}
Esempio n. 2
0
/*
 * znajdowanie oczekujacych serwerow
 */
int find_servers()
{
  static int ans = 0;
  enum clnt_stat clnt_stat;

  count = 0;
  clnt_stat = clnt_broadcast(PRIME_PROG, PRIME_VERS,
			     ZGLOS_SIE, (xdrproc_t) xdr_str, my_name, (xdrproc_t) xdr_int,
			     (char *)&ans, (resultproc_t)server_active);

  return count;
}
Esempio n. 3
0
static void
allhosts(void)
{
    statstime host_stat;
    enum clnt_stat clnt_stat;

    clnt_stat = clnt_broadcast(RSTATPROG, RSTATVERS_TIME, RSTATPROC_STATS,
                               (xdrproc_t)xdr_void, NULL,
                               (xdrproc_t)xdr_statstime, &host_stat,
                               (resultproc_t)rstat_reply);
    if (clnt_stat != RPC_SUCCESS && clnt_stat != RPC_TIMEDOUT)
        errx(1, "%s", clnt_sperrno(clnt_stat));
}
Esempio n. 4
0
void
mountd_svc_run(void)
{
	fd_set *fds = NULL;
	int fds_size = 0;
	extern fd_set *__svc_fdset;
	extern int __svc_fdsetsize;

	for (;;) {
		if (gothup) {
			get_exportlist();
			gothup = 0;
		}
		if (gotterm) {
			(void) clnt_broadcast(RPCPROG_MNT, RPCMNT_VER1,
			    RPCMNT_UMNTALL, xdr_void, (caddr_t)0, xdr_void,
			    (caddr_t)0, umntall_each);
			exit(0);
		}
		if (__svc_fdset) {
			int bytes = howmany(__svc_fdsetsize, NFDBITS) *
			    sizeof(fd_mask);
			if (fds_size != __svc_fdsetsize) {
				if (fds)
					free(fds);
				fds = (fd_set *)malloc(bytes);  /* XXX */
				fds_size = __svc_fdsetsize;
			}
			memcpy(fds, __svc_fdset, bytes);
		} else {
			if (fds)
				free(fds);
			fds = NULL;
		}
		switch (select(svc_maxfd+1, fds, 0, 0, (struct timeval *)0)) {
		case -1:
			if (errno == EINTR)
				break;
			perror("mountd_svc_run: - select failed");
			if (fds)
				free(fds);
			return;
		case 0:
			break;
		default:
			svc_getreqset2(fds, svc_maxfd+1);
			break;
		}
	}
}
Esempio n. 5
0
static void
allhosts(void)
{
	utmpidlearr up;
	enum clnt_stat clnt_stat;

	bzero((char *)&up, sizeof(up));
	clnt_stat = clnt_broadcast(RUSERSPROG, RUSERSVERS_IDLE,
	    RUSERSPROC_NAMES, (xdrproc_t)xdr_void, NULL,
	    (xdrproc_t)xdr_utmpidlearr, (char *)&up,
	    (resultproc_t)rusers_reply);
	if (clnt_stat != RPC_SUCCESS && clnt_stat != RPC_TIMEDOUT)
		errx(1, "%s", clnt_sperrno(clnt_stat));
}
Esempio n. 6
0
/*
 * sprawdzanie pierwszosci
 */
char is_prime(int i)
{
  static int ans = -1;
  char chrq[sizeof(int) + MAX_STR_LEN];

  received = 0;
  res = 1;

  memcpy(chrq, &i, sizeof(int));
  memcpy(chrq + sizeof(int), my_name, MAX_STR_LEN);

  clnt_broadcast(PRIME_PROG, PRIME_VERS,
		 SPRAWDZ_LICZBE, (xdrproc_t) xdr_check_req, chrq, (xdrproc_t) xdr_int,
		 (char *)&ans, (resultproc_t)server_sprawdzil);

  return res;
}
Esempio n. 7
0
int main(int argn, char *argc[])
{
	//Program parameters : argc[1] : HostName or Host IP
	//					   argc[2] : Server Program Number
	//					   argc[3] : Number of host ready to answer to broadcast
	//					   other arguments depend on test case

	//run_mode can switch into stand alone program or program launch by shell script
	//1 : stand alone, debug mode, more screen information
	//0 : launch by shell script as test case, only one printf -> result status
	int run_mode = 0;
	int test_status = 1; //Default test result set to FAILED
	int progNum = atoi(argc[2]);
	enum clnt_stat cs;
	int varSnd = 0;
	int varRec;

	bool_t eachResult (char *out, struct sockaddr_in *addr);
	maxAnswer = atoi(argc[3]);
	currentAnswer = 0;

	//Show information in debug mode...
	if (run_mode == 1)
	{
		printf("progNum : %d\n", progNum);
		printf("Max SVC : %d\n", maxAnswer);
	}

	//Call broadcast routine
	cs = clnt_broadcast(progNum, VERSNUM, PROCNUM,
				   		(xdrproc_t)xdr_int, (char *)&varSnd,
				   		(xdrproc_t)xdr_int, (char *)&varRec,
				   		eachResult);

	if (currentAnswer == maxAnswer)
		test_status = 0;

	if (cs != RPC_SUCCESS)
		clnt_perrno(cs);

	//This last printf gives the result status to the tests suite
	//normally should be 0: test has passed or 1: test has failed
	printf("%d\n", test_status);

	return test_status;
}
void
deletetask_broadcast (struct slave *slave)
{
  int err;

#ifdef DEBUG
  printf ("**** [call] deletetask\n");
#endif
  err = clnt_broadcast (LOSH, SLAVE, DELETETASK,
			(xdrproc_t) xdr_slave, (char *) slave,
                        (xdrproc_t) xdr_void,  (char *) NULL,
			deleted);
  if (err)
    {
      fprintf (stderr, "deletetask_broadcast: No reply.\n");
      return;
    }

#ifdef DEBUG
  printf ("**** [resp] deletetask\n");
#endif
}
void
whoismaster_broadcast (void)
{
  int err;
  struct master master;

#ifdef DEBUG
  printf ("SLAV [call] whoismaster\n");
#endif
  err = clnt_broadcast (LOSH, MASTER, WHOISMASTER,
			(xdrproc_t) xdr_void,   (char *) NULL,
                        (xdrproc_t) xdr_master, (char *) &master,
			iammaster);
  if (err)
    {
      fprintf (stderr, "clnt_broadcast: Not replied.\n");
      exit (EXIT_FAILURE);
    }

#ifdef DEBUG
  printf ("SLAV [resp] whoismaster\n");
  master_print (&master);
#endif
}
int main(int argn, char *argc[])
{
	//Program parameters : argc[1] : HostName or Host IP
	//                                         argc[2] : Server Program Number
	//                                         argc[3] : Number of test call
	//                                         other arguments depend on test case

	//run_mode can switch into stand alone program or program launch by shell script
	//1 : stand alone, debug mode, more screen information
	//0 : launch by shell script as test case, only one printf -> result status
	int run_mode = 0;
	int test_status = 0;	//Default test result set to FAILED
	int i;
	double *resultTbl;
	struct timeval tv1, tv2;
	struct timezone tz;
	long long diff;
	double rslt;
	int progNum = atoi(argc[2]);
	enum clnt_stat cs;
	int varSnd = 10;
	int varRec = -1;

	//Test initialisation
	maxIter = atoi(argc[3]);
	resultTbl = (double *)malloc(maxIter * sizeof(double));

	//Call tested function several times
	for (i = 0; i < maxIter; i++) {
		//Tic
		gettimeofday(&tv1, &tz);

		//Call function
		cs = clnt_broadcast(progNum, VERSNUM, PROCNUM,
				    (xdrproc_t) xdr_int, (char *)&varSnd,
				    (xdrproc_t) xdr_int, (char *)&varRec,
				    eachResult);

		if (cs != RPC_SUCCESS)
			clnt_perrno(cs);

		//Toc
		gettimeofday(&tv2, &tz);

		//Add function execution time (toc-tic)
		diff =
		    (tv2.tv_sec - tv1.tv_sec) * 1000000L + (tv2.tv_usec -
							    tv1.tv_usec);
		rslt = (double)diff / 1000;

		if (cs == RPC_SUCCESS) {
			resultTbl[i] = rslt;
		} else {
			test_status = 1;
			break;
		}

		if (run_mode) {
			fprintf(stderr, "lf time  = %lf usecn\n", resultTbl[i]);
		}
	}

	//This last printf gives the result status to the tests suite
	//normally should be 0: test has passed or 1: test has failed
	printf("%d\n", test_status);
	printf("%lf %d\n", average(resultTbl), maxIter);
	printf("%lf\n", mini(resultTbl));
	printf("%lf\n", maxi(resultTbl));

	return test_status;
}
void
whoisslave_broadcast ()
{
  int err;
  struct slave *temp;
  struct slave slave;

#ifdef DEBUG
  printf ("MAST [call] whoisslave\n");
#endif
  _slave_count = 0;

  /* Unset all known loads: */
  temp = NULL;
  while (TRUE)
    {
      temp = (struct slave *) list_next (&master -> slaves,
					 (temp == NULL));
      if (temp == NULL)
	break;

      temp -> load = -1;
    }

  err = clnt_broadcast (LOSH, SLAVE, WHOISSLAVE,
                        (xdrproc_t) xdr_void,  (char *) NULL,
			(xdrproc_t) xdr_slave, (char *) &slave,
                        iamslave);
  if (err)
    {
      temp = NULL;
      while (TRUE)
	{
	  temp = (struct slave *) list_next (&master -> slaves,
					     (temp == NULL));
	  if (temp == NULL)
	    break;
	  
	  if (temp -> load == -1)
	    {
#ifdef DEBUG
	      printf ("Breakdown %s\n", temp -> addr);
#endif
	      deletetask_broadcast (temp);
	      list_del (&master -> slaves, (void *) temp,
			(cmpfct_t) task_compare);
	      master -> slave_number--;
	    }
	}

#ifdef DEBUG
      master_print (master);
#endif
    }

#ifdef DEBUG
  printf ("MAST [resp] whoisslave\n");
  temp = NULL;
  while (TRUE)
    {
      temp = (struct slave *) list_next (&master -> slaves,
					 (temp == NULL));
      if (temp == NULL)
	break;

      slave_print (temp);
    }
#endif
}
Esempio n. 12
0
int main(int argn, char *argc[])
{
	//Program parameters : argc[1] : HostName or Host IP
	//					   argc[2] : Server Program Number
	//					   other arguments depend on test case
	
	//run_mode can switch into stand alone program or program launch by shell script
	//1 : stand alone, debug mode, more screen information
	//0 : launch by shell script as test case, only one printf -> result status
	int run_mode = 1;
	int test_status = 0; //Default test result set to PASSED
	int progNum = atoi(argc[2]);
	enum clnt_stat cs;
	//Sent variables
	int intSnd;
	double dblSnd;
	long lngSnd;
	char *strSnd;
	//Received variables
	int intRec;
	double dblRec;
	long lngRec;
	char *strRec;
	
	//Test initialization
	
	
	//Call tested procedure several times
	//Int test : call INTPROCNUM RPC
	intSnd = -65536;
	
	clnt_broadcast(progNum, VERSNUM, INTPROCNUM, 
				   (xdrproc_t)xdr_int, (char *)&intSnd,
				   (xdrproc_t)xdr_int, (char *)&intRec,
				   eachResult);
	
	if (intSnd != intRec)
		test_status = 1;
	if (run_mode == 1)
		printf("Send (int) : %d, Received : %d\n", intSnd, intRec);

	//Test positive number
	intSnd = 16777216;
	
	clnt_broadcast(progNum, VERSNUM, INTPROCNUM, 
				   (xdrproc_t)xdr_int, (char *)&intSnd,
				   (xdrproc_t)xdr_int, (char *)&intRec,
				   eachResult);
	
	if (intSnd != intRec)
		test_status = 1;
	if (run_mode == 1)
		printf("Send (int) : %d, Received : %d\n", intSnd, intRec);
		
	//Long test : call LNGPROCNUM RPC
	lngSnd = -430000;
	
	clnt_broadcast(progNum, VERSNUM, LNGPROCNUM, 
				   (xdrproc_t)xdr_long, (char *)&lngSnd,
				   (xdrproc_t)xdr_long, (char *)&lngRec,
				   eachResult);
	
	if (lngSnd != lngRec)
		test_status = 1;
	if (run_mode == 1)
		printf("Send (long) : %ld, Received : %ld\n", lngSnd, lngRec);
	
	//Double test : call DBLPROCNUM RPC
	dblSnd = -1735.63000f;
	
	clnt_broadcast(progNum, VERSNUM, LNGPROCNUM, 
				   (xdrproc_t)xdr_double, (char *)&dblSnd,
				   (xdrproc_t)xdr_double, (char *)&dblRec,
				   eachResult);
	
	if (dblSnd != dblRec)
		test_status = 1;
	if (run_mode == 1)
		printf("Send (double) : %lf, Received : %lf\n", dblSnd, dblRec);
	
	//String test : call STRPROCNUM RPC
	strSnd = "text to send.";
	strRec = (char *)malloc(64 * sizeof(char));
	
	clnt_broadcast(progNum, VERSNUM, LNGPROCNUM, 
				   (xdrproc_t)xdr_wrapstring, (char *)&strSnd,
				   (xdrproc_t)xdr_wrapstring, (char *)&strRec,
				   eachResult);
	
	if (strcmp(strSnd, strRec))
		test_status = 1;
	if (run_mode == 1)
		printf("Send (string) : %s, Received : %s\n", strSnd, strRec);
	
	//This last printf gives the result status to the tests suite
	//normally should be 0: test has passed or 1: test has failed
	printf("%d\n", test_status);
	
	return test_status;
}