Пример #1
0
/*===========================================================================*
 *				main                                         *
 *===========================================================================*/
PUBLIC int main(int argc, char **argv)
{
/* This is the main routine of this service. The main loop consists of 
 * three major activities: getting new work, processing the work, and
 * sending the reply. The loop never terminates, unless a panic occurs.
 */
  message m;
  int result;                 
  sigset_t sigset;

  /* Initialize the server, then go to work. */
  init_server(argc, argv);

  /* Main loop - get work and do it, forever. */         
  while (TRUE) {              

      /* Wait for incoming message, sets 'callnr' and 'who'. */
      get_work(&m);

      switch (callnr) {
      case PROC_EVENT:
	  sig_handler();
          continue;
      case DS_PUBLISH:
          result = do_publish(&m);
          break;
      case DS_RETRIEVE:
	  result = do_retrieve(&m);
	  break;
      case DS_SUBSCRIBE:
	  result = do_subscribe(&m);
	  break;
      case GETSYSINFO:
	  result = do_getsysinfo(&m);
	  break;
      default: 
          report("DS","warning, got illegal request from:", m.m_source);
          result = EINVAL;
      }

      /* Finally send reply message, unless disabled. */
      if (result != EDONTREPLY) {
          m.m_type = result;  		/* build reply message */
	  reply(who_e, &m);		/* send it away */
      }
  }
  return(OK);				/* shouldn't come here */
}
Пример #2
0
/*===========================================================================*
 *				main                                         *
 *===========================================================================*/
PUBLIC int main(int argc, char **argv)
{
/* This is the main routine of this service. The main loop consists of 
 * three major activities: getting new work, processing the work, and
 * sending the reply. The loop never terminates, unless a panic occurs.
 */
  message m;
  int result;                 

  /* SEF local startup. */
  env_setargs(argc, argv);
  sef_local_startup();

  /* Main loop - get work and do it, forever. */         
  while (TRUE) {              

      /* Wait for incoming message, sets 'callnr' and 'who'. */
      get_work(&m);

      if (is_notify(callnr)) {
          printf("DS: warning, got illegal notify from: %d\n", m.m_source);
          result = EINVAL;
          goto send_reply;
      }

      switch (callnr) {
      case DS_PUBLISH:
          result = do_publish(&m);
          break;
      case DS_RETRIEVE:
	  result = do_retrieve(&m);
	  break;
      case DS_RETRIEVE_LABEL:
	  result = do_retrieve_label(&m);
	  break;
      case DS_DELETE:
	  result = do_delete(&m);
	  break;
      case DS_SUBSCRIBE:
	  result = do_subscribe(&m);
	  break;
      case DS_CHECK:
	  result = do_check(&m);
	  break;
      case DS_SNAPSHOT:
	  result = do_snapshot(&m);
	  break;
      case GETSYSINFO:
	  result = do_getsysinfo(&m);
	  break;
      default: 
          printf("DS: warning, got illegal request from %d\n", m.m_source);
          result = EINVAL;
      }

send_reply:
      /* Finally send reply message, unless disabled. */
      if (result != EDONTREPLY) {
          m.m_type = result;  		/* build reply message */
	  reply(who_e, &m);		/* send it away */
      }
  }
  return(OK);				/* shouldn't come here */
}
Пример #3
0
int main(int argc, char **argv) {
	void		*tabpoll;
	dia_context_t	*dia;
	int result;
	char addr_str[200] = "::1";
	char port_str[10] = "5683";
	int opt;
	int log_level = 0;
	int count = 1, i;
	int group = 1;
	char loss = 0;

	while ((opt = getopt(argc, argv, "A:p:v:m:f:n:g:R:l")) != -1) {
		switch (opt) {
		case 'A' :
			strncpy(addr_str, optarg, 200-1);
			addr_str[200 - 1] = '\0';
			break;
		case 'p' :
			strncpy(port_str, optarg, 10-1);
			port_str[10 - 1] = '\0';
			break;
		case 'm' :
			strcpy (method, optarg);
			break;
		case 'R' :
			strcpy (reqEntity, optarg);
			break;
		case 'l' :
			loss = 1;
			break;
		case 'f' :
			strcpy (file, optarg);
			break;
		case 'n' :
			count = atoi(optarg);
			break;
		case 'g' :
			group = atoi(optarg);
			break;
		case 'v' :
			log_level = strtol(optarg, NULL, 10);
			break;
		default:
			usage();
			exit( 1 );
		}
	}

	if (optind == argc) {
		fprintf (stderr, "You must specify a targetID\n");
		usage();
		exit (1);
	}

	char *targetID	= argv[optind];

	dia = dia_createContext(&callbacks);
	if (!dia) {
		fprintf (stderr, "dia_createContext failed\n");
		usage();
		exit (1);
	}

	dia_withLoss (dia, loss);

	tabpoll = rtl_pollInit ();

	sock	= resolve_address(addr_str, &addr);
	addr.addr.sin.sin_port = htons(atoi(port_str));

	rtl_pollAdd (tabpoll, sock, network_input, network_request, dia, NULL);

	signal(SIGINT, handle_sigint);

	for	(i=0; i<count; i++) {
		if	(!strcmp(method, "create"))
			do_create (dia, targetID, group);
		else if	(!strcmp(method, "retrieve"))
			do_retrieve (dia, targetID, group);
		else if	(!strcmp(method, "update"))
			do_update (dia, targetID, group);
		else if	(!strcmp(method, "delete"))
			do_delete (dia, targetID, group);
		else {
			usage ();
			exit (1);
		}

		dIa_status (dia);

		while ( more ) {
			struct dia_timeval tv;
			dIa_nextTimer (dia, &tv);
			result = rtl_poll(tabpoll, (tv.tv_sec*1000) + (tv.tv_usec/1000));
		}

		dIa_status (dia);

		if	(quit)
			break;
	}

	return 0;
}