示例#1
0
void	prepare_client(t_data *data)
{
  prepare_players(data);
  prepare_window(data);
  prepare_network(data);
  prepare_pseudo(data);
}
示例#2
0
void client_handler()
{
	printf("mc_loop_test: [CLIENT] Start sending on: ");
	prepare_network(0);

	sleep(2);

    //printf("Sending to: FD = %d; IP = %s; PORT = %d\n",fd, inet_ntoa(user_params.addr.sin_addr), ntohs(user_params.addr.sin_port));
    if (sendto(fd, pattern/*msgbuf*/, user_params.msg_size, 0,
         (struct sockaddr *)&(user_params.addr), sizeof(user_params.addr)) < 0) {
        perror("mc_loop_test: sendto()");
        exit(1);
    }
    printf("mc_loop_test: Client done sending.\n") ;
}
示例#3
0
void server_handler()
{
 	int nbytes;
	socklen_t size = sizeof(struct sockaddr);
	struct sockaddr_in client_addr;
	printf("mc_loop_test: [SERVER] Listen on: ");
	prepare_network(1);

    printf("Waiting to receive from FD %d\n", fd);
    if ((nbytes = recvfrom(fd, msgbuf, user_params.msg_size, 0, (struct sockaddr *)&client_addr, &size)) < 0) {
        perror("mc_loop_test: recvfrom()");
        exit(1);
    }
    printf("server:Message received...\n");

	printf("mc_loop_test: %s: exit\n", __func__);
}
示例#4
0
int
main(int argc, char **argv)
{
  clock_init();

#if NETSTACK_CONF_WITH_IPV6
#if UIP_CONF_IPV6_RPL
  printf(CONTIKI_VERSION_STRING " started with IPV6, RPL\n");
#else
  printf(CONTIKI_VERSION_STRING " started with IPV6\n");
#endif
#else
  printf(CONTIKI_VERSION_STRING " started\n");
#endif

  /* crappy way of remembering and accessing argc/v */
  contiki_argc = argc;
  contiki_argv = argv;

  /* native under windows is hardcoded to use the first one or two args */
  /* for wpcap configuration so this needs to be "removed" from         */
  /* contiki_args (used by the native-border-router) */
#ifdef __CYGWIN__
  contiki_argc--;
  contiki_argv++;
#ifdef UIP_FALLBACK_INTERFACE
  contiki_argc--;
  contiki_argv++;
#endif
#endif

  process_init();
  process_start(&etimer_process, NULL);
  ctimer_init();
  rtimer_init();

  prepare_network();

  serial_line_init();

  /* Make standard output unbuffered. */
  setvbuf(stdout, (char *)NULL, _IONBF, 0);

  select_set_callback(STDIN_FILENO, &stdin_fd);
  while(1) {
    fd_set fdr;
    fd_set fdw;
    int maxfd;
    int i;
    int retval;
    struct timeval tv;

    retval = process_run();

    tv.tv_sec = 0;
    tv.tv_usec = 0;
    if(!retval) {

      if(etimer_pending()) {
        clock_time_t t = etimer_next_expiration_time() - clock_time() - 1;
        if(t < MAX_TICKS) {
          tv.tv_sec = t / CLOCK_SECOND;
          tv.tv_usec = (t % CLOCK_SECOND) * 1000;
          if(tv.tv_usec == 0 && tv.tv_sec == 0) {
            /* Clock time resolution is milliseconds. Avoid millisecond
               busy loops. */
            tv.tv_usec = 250;
          }
        }
      } else {
        tv.tv_sec = 60;
      }

      /* TODO Replace the busy polling used to read data from the slip pthread */
      if(tv.tv_sec)  {
	tv.tv_sec = 0;
	tv.tv_usec = 10000;
      } else if(tv.tv_usec > 10000) {
	tv.tv_usec = 10000;
      }
    }

    FD_ZERO(&fdr);
    FD_ZERO(&fdw);
    maxfd = 0;
    for(i = 0; i <= select_max; i++) {
      if(select_callback[i] != NULL && select_callback[i]->set_fd(&fdr, &fdw)) {
        maxfd = i;
      }
    }

    retval = select(maxfd + 1, &fdr, &fdw, NULL, &tv);
    if(retval < 0) {
      if(errno != EINTR) {
        perror("select");
      }
    } else if(retval > 0) {
      /* timeout => retval == 0 */
      for(i = 0; i <= maxfd; i++) {
        if(select_callback[i] != NULL) {
          select_callback[i]->handle_fd(&fdr, &fdw);
        }
      }
    }

    if(etimer_pending() &&
       (etimer_next_expiration_time() - clock_time() - 1) > MAX_TICKS) {
      etimer_request_poll();
    }
  }

  return 0;
}